-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
617 additions
and
246 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "235c92cd-cc05-42b8-a516-1185eeac5f0c", | ||
"metadata": {}, | ||
"source": [ | ||
"# Creating a Custom LUME-model\n", | ||
"Custom models that are compatible with LUME tools can be created by inhereting from the `LUMEBaseModel`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "56725817-2b21-4bea-98b0-151dea959f77", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from lume_model.base import LUMEBaseModel\n", | ||
"from lume_model.variables import ScalarInputVariable, ScalarOutputVariable" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "79c62b18-7dc1-44ca-b578-4dea5cc4a4b4", | ||
"metadata": {}, | ||
"source": [ | ||
"## Model Definition\n", | ||
"The minimum requirement for creating a custom LUME-model is to implement the abstract `evaluate` method inherited from `LUMEBaseModel`. Here, we simply return the squared input." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "f96d9863-269c-49d8-9671-cc73a783bcbc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class ExampleModel(LUMEBaseModel):\n", | ||
" def evaluate(self, input_dict):\n", | ||
" output_dict = {\n", | ||
" \"output1\": input_dict[self.input_variables[0].name] ** 2,\n", | ||
" \"output2\": input_dict[self.input_variables[1].name] ** 2,\n", | ||
" }\n", | ||
" return output_dict" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "868fff4d-1f46-48e2-8bd0-c9d831df79e6", | ||
"metadata": {}, | ||
"source": [ | ||
"## Model Instantiation and Execution\n", | ||
"Instantiation requires specification of the input and output variables of the model." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "97946e64-062d-47d4-8d0c-d7e02a335a56", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"input_variables = [\n", | ||
" ScalarInputVariable(name=\"input1\", default=0.1, value_range=[0.0, 1.0]),\n", | ||
" ScalarInputVariable(name=\"input2\", default=0.2, value_range=[0.0, 1.0]),\n", | ||
"]\n", | ||
"output_variables = [\n", | ||
" ScalarOutputVariable(name=\"output1\"),\n", | ||
" ScalarOutputVariable(name=\"output2\"),\n", | ||
"]\n", | ||
"\n", | ||
"m = ExampleModel(input_variables=input_variables, output_variables=output_variables)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "50aae4be-0d6e-456f-83e8-3a84d6d78f84", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"{'output1': 0.09, 'output2': 0.36}" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"input_dict = {\n", | ||
" \"input1\": 0.3,\n", | ||
" \"input2\": 0.6,\n", | ||
"}\n", | ||
"m.evaluate(input_dict)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "6a547f3c-1706-4b32-bab6-9687627f6a78", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python [conda env:lume-model-dev]", | ||
"language": "python", | ||
"name": "conda-env-lume-model-dev-py" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.18" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.