Skip to content

Commit

Permalink
Merge pull request #97 from jacquelinegarrahan/doc-cleanup
Browse files Browse the repository at this point in the history
Doc cleanup
  • Loading branch information
jacquelinegarrahan authored May 24, 2022
2 parents bd8c16a + 9c2603a commit 626b165
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/BokehServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Create a new file named `model.py`. Set up out model:
```python
import numpy as np
from lume_model.variables import ScalarInputVariable, ImageOutputVariable
from lume_model.models import SurrogateModel
from lume_model.models import BaseModel
from lume_model.utils import save_variables
```

Next, define the demo model. Here, we define the input and output variables as keyword arguments. In order for the evaluate method to execute correctly, these
passed variables must be dictionaries of variables with corresponding types and names. These could also be defined as class attributes.

```python
class DemoModel(SurrogateModel):
class DemoModel(BaseModel):
def __init__(self, input_variables=None, output_variables=None):
self.input_variables = input_variables
self.output_variables = output_variables
Expand Down
14 changes: 7 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ output = ScalarOutputVariable(name="output")

### Defining the model

[LUME-model](https://github.com/slaclab/lume-model) includes a SurrogateModel base class to enforce the defined class's compatability with the lume-epics server. The primary function of this base class is to force the implementation of an evaluate method. This method must accept a list of `lume-model` input variables, execute the model, and return a list of `lume-model` output variables. Input variables and output variables must be defined as class attributes. They may be defined directly as class attributes or assigned in __init__.
[LUME-model](https://github.com/slaclab/lume-model) includes a BaseModel base class to enforce the defined class's compatability with the lume-epics server. The primary function of this base class is to force the implementation of an evaluate method. This method must accept a list of `lume-model` input variables, execute the model, and return a list of `lume-model` output variables. Input variables and output variables must be defined as class attributes. They may be defined directly as class attributes or assigned in __init__.

For our model, we will construct a class that accepts and stores our input and output variables on initialization. Then, we implement an `evaluate` method that accepts an updated list of input variables, executes the model, and updates the output variable value appropriately. Place the following code in a file named `server.py`.
```python
from lume_epics.model import SurrogateModel
from lume_epics.model import BaseModel
import numpy as np

class ExampleModel(SurrogateModel):
class ExampleModel(BaseModel):
def __init__(self, input_variables = [], output_variables = []):
self.input_variables = input_variables
self.output_variables = output_variables
Expand Down Expand Up @@ -112,11 +112,11 @@ These are then loaded during server construction:
from lume_epics.epics_server import Server
from lume_model.utils import variables_from_yaml
from lume_epics.utils import config_from_yaml
from lume_epics.model import SurrogateModel
from lume_epics.model import BaseModel
import numpy as np


class ExampleModel(SurrogateModel):
class ExampleModel(BaseModel):
def __init__(self, input_variables = [], output_variables = []):
self.input_variables = input_variables
self.output_variables = output_variables
Expand Down Expand Up @@ -278,12 +278,12 @@ In `server.py`:
```python
import numpy as np
from lume_model.variables import ScalarInputVariable, ImageOutputVariable
from lume_model.models import SurrogateModel
from lume_model.models import BaseModel
from lume_model.utils import save_variables
from lume_model.utils import variables_from_yaml
from lume_epics.utils import config_from_yaml

class ExampleModel(SurrogateModel):
class ExampleModel(BaseModel):
def __init__(self, input_variables: dict=None, output_variables:dict=None):
self.input_variables = input_variables
self.output_variables = output_variables
Expand Down
4 changes: 2 additions & 2 deletions examples/read_only/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
ImageOutputVariable,
ScalarOutputVariable,
)
from lume_model.models import SurrogateModel
from lume_model.models import BaseModel
from lume_model.utils import save_variables


class DemoModel(SurrogateModel):
class DemoModel(BaseModel):
def __init__(self, input_variables=None, output_variables=None):
self.input_variables = input_variables
self.output_variables = output_variables
Expand Down
2 changes: 1 addition & 1 deletion lume_epics/epics_pva_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def __init__(self, pvname: str, is_constant: bool, server: PVAServer):

def put(self, pv: SharedPV, op: ServOpWrap) -> None:
"""Updates the global input process variable state, posts the input process
variable value change, runs the thread local OnlineSurrogateModel instance
variable value change, runs the thread local BaseModel instance
using the updated global input process variable states, and posts the model
output values to the output process variables.
Expand Down
13 changes: 8 additions & 5 deletions lume_epics/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
This module is used for executing callbacks on the user's SurrogateModel class for use
with the EPICS server defined in lume_epics.epics_server. The SurrogateModel must be
This module is used for executing callbacks on the user's BaseModel subclass for use
with the EPICS server defined in lume_epics.epics_server. The BaseModel must be
defined using the guidelines outlined in the lume_model.models module to be surfaced
using the OnlineSurrogateModel class.
using the BaseModel class.
"""

Expand All @@ -23,15 +23,18 @@ class OnlineModel:
Class for executing surrogate model.
Attributes:
model (SurrogateModel): Model for execution.
model (BaseModel): Model for execution.
input_variables (Dict[str, InputVariable]): List of lume-model variables to use as inputs.
ouput_variables (Dict[str, OutputVariable]): List of lume-model variables to use as outputs.
"""

def __init__(self, model: BaseModel,) -> None:
def __init__(
self,
model: BaseModel,
) -> None:
"""
Initialize OnlineModel with the base model class.
Expand Down
17 changes: 13 additions & 4 deletions lume_epics/tests/launch_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sys
from lume_epics import epics_server
from lume_model.models import SurrogateModel
from lume_model.models import BaseModel
from lume_model.variables import (
ScalarInputVariable,
ImageInputVariable,
Expand All @@ -18,15 +18,23 @@
logger.setLevel("DEBUG")


class TestModel(SurrogateModel):
class TestModel(BaseModel):
input_variables = {
"input1": ScalarInputVariable(name="input1", default=1.0, range=[0.0, 5.0]),
"input2": ScalarInputVariable(
name="input2", default=2.0, range=[0.0, 5.0], is_constant=True
),
"input3": ImageInputVariable(
name="input3",
default=np.array([[1, 6,], [4, 1]]),
default=np.array(
[
[
1,
6,
],
[4, 1],
]
),
value_range=[1, 10],
axis_labels=["count_1", "count_2"],
x_min=0,
Expand All @@ -43,7 +51,8 @@ class TestModel(SurrogateModel):
"output1": ScalarOutputVariable(name="output1"),
"output2": ScalarOutputVariable(name="output2"),
"output3": ImageOutputVariable(
name="output3", axis_labels=["count_1", "count_2"],
name="output3",
axis_labels=["count_1", "count_2"],
),
"output4": ArrayOutputVariable(name="output4"),
}
Expand Down
2 changes: 1 addition & 1 deletion lume_epics/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ImageOutputVariable,
)
from lume_epics import epics_server
from lume_model.models import SurrogateModel
from lume_model.models import BaseModel
from lume_epics.tests.conftest import PVA_CONFIG


Expand Down

0 comments on commit 626b165

Please sign in to comment.