Skip to content

Commit d4d7328

Browse files
BenSchZABenSchZAcadlabsgtgiutri
authored
Experiment notebooks (#54)
Co-authored-by: BenSchZA <[email protected]> Co-authored-by: cadlabsgt <[email protected]> Co-authored-by: giutri <[email protected]> Co-authored-by: cadlabsgt <[email protected]>
1 parent fb89383 commit d4d7328

34 files changed

+4778
-746
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ benchmark-test:
6060

6161
benchmark-default:
6262
python -m pytest benchmarks/benchmark_default_experiment.py --benchmark-only --benchmark-json output.json
63+
64+
profile-memory:
65+
mprof run --include-children --multiprocess $(target)
66+
mprof plot

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,11 @@ make test
233233

234234
A notebook exists to perform simulation time profiling of individual State Update Blocks of the model, see [experiments/notebooks/simulation_profiling/simulation_timestep_substep_profiling.ipynb]. Simulation time profiling of PRs is also performed in the GitHub Action pipeline, and included in each PR by a bot. See the Makefile and GitHub Action file for more details.
235235

236-
Memory profiling can also be performed using `memory-profiler`.
236+
Memory profiling can also be performed using the `memory-profiler` Python package:
237+
238+
```bash
239+
make profile-memory target="tests/test_notebook_memory.py 1_sanity_checks.ipynb"
240+
```
237241

238242
## Change Log
239243

experiments/notebooks/0_README.ipynb

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Experiment Notebook: {Descriptive Experiment Keywords}"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# Table of Contents\n",
15+
"* [Experiment Summary](#Experiment-Summary)\n",
16+
"* [Experiment Assumptions](#Experiment-Assumptions)\n",
17+
"* [Experiment Setup](#Experiment-Setup)\n",
18+
"* [Analysis 1: ...](#Analysis-1:-...)"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"# Experiment Summary \n",
26+
"\n",
27+
"The purpose of this notebook is to...\n",
28+
"\n",
29+
"# Experiment Assumptions\n",
30+
"\n",
31+
"See [assumptions document](../../ASSUMPTIONS.md) for further details."
32+
]
33+
},
34+
{
35+
"cell_type": "markdown",
36+
"metadata": {},
37+
"source": [
38+
"# Experiment Setup\n",
39+
"\n",
40+
"We begin with several experiment-notebook-level preparatory setup operations:\n",
41+
"\n",
42+
"* Import relevant dependencies\n",
43+
"* Import relevant experiment templates\n",
44+
"* Create copies of experiments\n",
45+
"* Configure and customize experiments \n",
46+
"\n",
47+
"Analysis-specific setup operations are handled in their respective notebook sections."
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": null,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"# Import the setup module:\n",
57+
"# * sets up the Python path\n",
58+
"# * runs shared notebook configuration methods, such as loading IPython modules\n",
59+
"import setup\n",
60+
"\n",
61+
"import copy\n",
62+
"import logging\n",
63+
"import numpy as np\n",
64+
"import pandas as pd\n",
65+
"import plotly.express as px\n",
66+
"\n",
67+
"import experiments.notebooks.visualizations as visualizations\n",
68+
"from experiments.run import run\n",
69+
"from experiments.utils import display_code"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"# Enable/disable logging\n",
79+
"logger = logging.getLogger()\n",
80+
"logger.disabled = False"
81+
]
82+
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"metadata": {},
87+
"outputs": [],
88+
"source": [
89+
"# Import experiment templates\n",
90+
"import experiments.default_experiment as default_experiment"
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"# Inspect experiment template\n",
100+
"display_code(default_experiment)"
101+
]
102+
},
103+
{
104+
"cell_type": "code",
105+
"execution_count": null,
106+
"metadata": {},
107+
"outputs": [],
108+
"source": [
109+
"# Create a simulation for each analysis\n",
110+
"simulation_1 = copy.deepcopy(default_experiment.experiment.simulations[0])"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"metadata": {},
117+
"outputs": [],
118+
"source": [
119+
"# Experiment configuration\n",
120+
"simulation_1.model.initial_state.update({})\n",
121+
"\n",
122+
"simulation_1.model.params.update({})"
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {},
128+
"source": [
129+
"# Analysis 1: ..."
130+
]
131+
},
132+
{
133+
"cell_type": "markdown",
134+
"metadata": {},
135+
"source": [
136+
"{Analysis Description}"
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"execution_count": null,
142+
"metadata": {},
143+
"outputs": [],
144+
"source": [
145+
"# Analysis-specific setup"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": [
154+
"# Experiment execution\n",
155+
"df, exceptions = run(simulation_1)"
156+
]
157+
},
158+
{
159+
"cell_type": "code",
160+
"execution_count": null,
161+
"metadata": {},
162+
"outputs": [],
163+
"source": [
164+
"# Post-processing and visualizations"
165+
]
166+
},
167+
{
168+
"cell_type": "code",
169+
"execution_count": null,
170+
"metadata": {},
171+
"outputs": [],
172+
"source": []
173+
}
174+
],
175+
"metadata": {
176+
"kernelspec": {
177+
"display_name": "Python 3",
178+
"language": "python",
179+
"name": "python3"
180+
},
181+
"language_info": {
182+
"codemirror_mode": {
183+
"name": "ipython",
184+
"version": 3
185+
},
186+
"file_extension": ".py",
187+
"mimetype": "text/x-python",
188+
"name": "python",
189+
"nbconvert_exporter": "python",
190+
"pygments_lexer": "ipython3",
191+
"version": "3.8.11"
192+
}
193+
},
194+
"nbformat": 4,
195+
"nbformat_minor": 4
196+
}

0 commit comments

Comments
 (0)