Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow relative paths in YAML files and update docs #89

Merged
merged 4 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
390 changes: 68 additions & 322 deletions docs/index.md

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions docs/models.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
# Models

::: lume_model.models
selection:
::: lume_model.base
options:
members:
- BaseModel
rendering:
show_root_heading: false
- LUMEBaseModel

::: lume_model.models.torch_model
options:
members:
- TorchModel

::: lume_model.models.torch_module
options:
members:
- TorchModule

::: lume_model.models.keras_model
options:
members:
- KerasModel
7 changes: 5 additions & 2 deletions docs/utils.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Utilities

::: lume_model.utils
rendering:
show_root_heading: false
options:
members:
- variables_as_yaml
- variables_from_dict
- variables_from_yaml
13 changes: 5 additions & 8 deletions docs/variables.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# Variables

::: lume_model.variables
selection:
options:
members:
- Variable
- ScalarVariable
- InputVariable
- OutputVariable
- ScalarInputVariable
- ScalarOutputVariable
- ImageInputVariable
- ImageOutputVariable
- ArrayInputVariable
- ArrayOutputVariable
- TableVariable
rendering:
show_source: true
198 changes: 0 additions & 198 deletions examples/IrisTraining.ipynb

This file was deleted.

Empty file removed examples/__init__.py
Empty file.
131 changes: 131 additions & 0 deletions examples/custom_model.ipynb
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 removed examples/files/example_input_image.npy
Binary file not shown.
Loading
Loading