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

Krathedits #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 9 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@
"sphinx.ext.intersphinx",
"sphinx_copybutton",
"sphinx_design",
"myst_nb",
"nbsphinx",
"jupyter_sphinx",
'sphinx.ext.todo',
'sphinx.ext.mathjax',
'sphinx.ext.ifconfig',
'sphinx.ext.napoleon',
# 'myst_nb',
]

nbsphinx_custom_formats = {
".md": ["jupytext.reads", {"fmt": "mystnb"}],
}
# nbsphinx_custom_formats = {
# ".md": ["jupytext.reads", {"fmt": "mystnb"}],
# }

# Adjusting size of embedded HTMLs
html_static_path = ['_static']
Expand Down
133 changes: 85 additions & 48 deletions docs/source/notebooks/basic_model.ipynb

Large diffs are not rendered by default.

202 changes: 134 additions & 68 deletions docs/source/notebooks/basic_sampling.ipynb

Large diffs are not rendered by default.

189 changes: 143 additions & 46 deletions docs/source/notebooks/composite_vector_space.ipynb

Large diffs are not rendered by default.

163 changes: 122 additions & 41 deletions docs/source/notebooks/dictionary_vector_space.ipynb

Large diffs are not rendered by default.

293 changes: 210 additions & 83 deletions docs/source/notebooks/external_model.ipynb

Large diffs are not rendered by default.

184 changes: 137 additions & 47 deletions docs/source/notebooks/external_qoi_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,69 @@
"source": [
"# External QoiModel tutorial\n",
"\n",
"In this tutorial you will learn the basics of the QoiModel interface. The QoIModel interface is almost identical to the model interface,\n",
"but has an additional method called compute_qoi() where it returns a (usually scalar) quantity of interest. This type of model is useful for various workflows, such as training a ROM to a desired tolerance on a specified QoI. The API for the model interface is provided here:\n",
"\n",
"https://pressio.github.io/rom-tools-and-workflows/romtools/workflows/models.html\n"
"In this tutorial you will learn the basics of the `QoiModel` interface. The `QoIModel` interface is almost identical to the `Model` interface,\n",
"but has an additional method called `compute_qoi()` where it returns a (usually scalar) quantity of interest. This type of model is useful for various workflows, such as training a ROM to a desired tolerance on a specified QoI. The API for the model interface is provided [here](https://pressio.github.io/rom-tools-and-workflows/romtools/workflows/models.html).\n"
]
},
{
"cell_type": "markdown",
"id": "81661d69",
"metadata": {},
"source": [
"## Modules\n",
"Here are the relevant modules for this example."
]
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "358fb709-9c81-45a3-a871-2549de121580",
"metadata": {},
"outputs": [],
"source": [
"#First, let's import the relavant modules:\n",
"%%capture\n",
"import romtools\n",
"import os\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from romtools.workflows import models"
]
},
{
"cell_type": "markdown",
"id": "a1c0d073",
"metadata": {},
"source": [
"## Model Definition\n",
"As a starting point, we will use the model created in the `external_model` tutorial."
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "b1ffa4be-246c-44a9-b486-f517b9f7acb9",
"metadata": {},
"outputs": [],
"source": [
"# As a starting point, we will use the model created in the external_model tutorial\n",
"from ipynb.fs.full.external_model import adrExternalRomToolsModel"
]
},
{
"cell_type": "markdown",
"id": "f8d5c05e",
"metadata": {},
"source": [
"## Model Class Definition\n",
"Now, we will create a QoI model. As a QoI, we will take the gradient of the state at the right of the domain."
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "217759fb-6ec9-4488-897b-e5b4db9f4b2c",
"metadata": {},
"outputs": [],
"source": [
"#Now, we will create a QoI model. As a QoI, we will take the gradient of the state at the right of the domain\n",
"class adrExternalRomToolsQoiModel(adrExternalRomToolsModel):\n",
" # Our class will inherit all the methods from adrExternalRomToolsModel\n",
" \n",
Expand All @@ -57,52 +80,119 @@
" x = solution['x']\n",
" dx = x[1] - x[0] #we use a uniform grid\n",
" ux_at_right_edge = (0. - u[-1])/dx\n",
" return ux_at_right_edge\n",
"\n",
"# We can now instatiate our QoI\n",
"myModel = adrExternalRomToolsQoiModel()\n",
" return ux_at_right_edge"
]
},
{
"cell_type": "markdown",
"id": "1f21b795",
"metadata": {},
"source": [
"We can now instatiate our QoI."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "411588c9",
"metadata": {},
"outputs": [],
"source": [
"myModel = adrExternalRomToolsQoiModel()"
]
},
{
"cell_type": "markdown",
"id": "665ddbfe",
"metadata": {},
"source": [
"That's it!"
]
},
{
"cell_type": "markdown",
"id": "dfbb0c29",
"metadata": {},
"source": [
"## Example\n",
"Let's do an example run of the model similar to how it will be used in a workflow.\n",
"\n",
"#That's it!"
"First, let's make a dictionary that is a stand in for the parameter space."
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": null,
"id": "dbf42fd4-340f-4074-9682-69a9df424b26",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The QoI is -6.429918802201725\n"
]
}
],
"source": [
"#Let's do an example run of the model similar to how it will be used in a workflow.\n",
"\n",
"if __name__==\"__main__\":\n",
" #First, let's make a dictionary that is a stand in for the parameter space\n",
" parameter_sample = {}\n",
" parameter_sample['c'] = 0.5\n",
" parameter_sample['nu'] = 1e-1\n",
"\n",
" #Now, let's populate our run directory. In this example, we will just use the current run directory.\n",
" #In a full workflow, romtools will manage creating directories\n",
" myModel.populate_run_directory(os.getcwd(),parameter_sample)\n",
"\n",
" #Now, let's run the model\n",
" run_dir = os.getcwd()\n",
"outputs": [],
"source": [
"parameter_sample = {}\n",
"parameter_sample['c'] = 0.5\n",
"parameter_sample['nu'] = 1e-1"
]
},
{
"cell_type": "markdown",
"id": "66d99534",
"metadata": {},
"source": [
"Now, let's populate our run directory. In this example, we will just use the current run directory.\n",
"In a full workflow, romtools will manage creating directories."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32b442c6",
"metadata": {},
"outputs": [],
"source": [
"myModel.populate_run_directory(os.getcwd(),parameter_sample)"
]
},
{
"cell_type": "markdown",
"id": "7d29ca27",
"metadata": {},
"source": [
"Now, let's run the model and compute the QoI."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b7ce69d",
"metadata": {},
"outputs": [],
"source": [
"run_dir = os.getcwd()\n",
"\n",
" myModel.run_model(run_dir,parameter_sample)\n",
"myModel.run_model(run_dir,parameter_sample)\n",
"\n",
" qoi = myModel.compute_qoi(run_dir,parameter_sample)\n",
"qoi = myModel.compute_qoi(run_dir,parameter_sample)\n",
"\n",
" print('The QoI is ' + str(qoi))\n",
" #We will finish by cleaning up the files we created\n",
" os.system('rm params.dat')\n",
" os.system('rm solution.npz')"
"print('The QoI is ' + str(qoi))"
]
},
{
"cell_type": "markdown",
"id": "746f061a",
"metadata": {},
"source": [
"We will finish by cleaning up the files we created."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "99887167",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"os.system('rm params.dat')\n",
"os.system('rm solution.npz')"
]
}
],
Expand All @@ -122,7 +212,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Loading