diff --git a/docs/BokehServer.md b/docs/BokehServer.md index dca7995..376d54e 100644 --- a/docs/BokehServer.md +++ b/docs/BokehServer.md @@ -24,7 +24,7 @@ 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 ``` @@ -32,7 +32,7 @@ Next, define the demo model. Here, we define the input and output variables as k 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 diff --git a/docs/index.md b/docs/index.md index f940789..e627ff8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 @@ -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 @@ -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 diff --git a/examples/read_only/model.py b/examples/read_only/model.py index 94375ed..2028370 100644 --- a/examples/read_only/model.py +++ b/examples/read_only/model.py @@ -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 diff --git a/lume_epics/epics_pva_server.py b/lume_epics/epics_pva_server.py index 4f22dfd..f8537a6 100644 --- a/lume_epics/epics_pva_server.py +++ b/lume_epics/epics_pva_server.py @@ -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. diff --git a/lume_epics/model.py b/lume_epics/model.py index 718ef83..c98361b 100644 --- a/lume_epics/model.py +++ b/lume_epics/model.py @@ -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. """ @@ -23,7 +23,7 @@ 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. @@ -31,7 +31,10 @@ class OnlineModel: """ - def __init__(self, model: BaseModel,) -> None: + def __init__( + self, + model: BaseModel, + ) -> None: """ Initialize OnlineModel with the base model class. diff --git a/lume_epics/tests/launch_server.py b/lume_epics/tests/launch_server.py index 8ef6378..afad154 100644 --- a/lume_epics/tests/launch_server.py +++ b/lume_epics/tests/launch_server.py @@ -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, @@ -18,7 +18,7 @@ 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( @@ -26,7 +26,15 @@ class TestModel(SurrogateModel): ), "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, @@ -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"), } diff --git a/lume_epics/tests/test_server.py b/lume_epics/tests/test_server.py index e5f1ad7..318e617 100644 --- a/lume_epics/tests/test_server.py +++ b/lume_epics/tests/test_server.py @@ -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