Skip to content

Commit 6e12168

Browse files
authored
Use IDs and names from ReturnData (#3112)
Remove the remainder of the old monkey-patching to store model entity names and IDs on `ReturnData` for `RDataReporting::full`.
1 parent 505a137 commit 6e12168

File tree

9 files changed

+180
-765
lines changed

9 files changed

+180
-765
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ See also our [versioning policy](https://amici.readthedocs.io/en/latest/versioni
6767
* Model output directory keyword arguments have been harmonized:
6868
What was previously `model_output_dir`, `output_dir`, `outdir` is now
6969
consistently called `output_dir` across the API.
70+
* Plotting functions have been moved from `amici.plotting` to
71+
`amici.sim.sundials.plotting`. The `model` argument has been removed.
7072

7173
**Features**
7274

doc/examples/example_errors.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,10 @@
252252
]
253253
},
254254
{
255-
"cell_type": "code",
256-
"execution_count": null,
257-
"id": "42b79264344ba95f",
258255
"metadata": {},
256+
"cell_type": "code",
259257
"outputs": [],
258+
"execution_count": null,
260259
"source": [
261260
"# Create a copy of this simulation condition\n",
262261
"edata = ExpData(res[EDATAS][0])\n",
@@ -265,9 +264,10 @@
265264
"rdata = run_simulation(amici_model, amici_solver, edata)\n",
266265
"\n",
267266
"# Visualize state trajectories\n",
268-
"plot_state_trajectories(rdata, model=amici_model)\n",
267+
"plot_state_trajectories(rdata)\n",
269268
"plt.yscale(\"log\")"
270-
]
269+
],
270+
"id": "fcebaf5d7951e1"
271271
},
272272
{
273273
"cell_type": "markdown",

doc/examples/example_petab/petab_v2.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"source": [
114114
"rdata = result.rdatas[0]\n",
115115
"edata = result.edatas[0]\n",
116-
"plot_observable_trajectories(rdata, model=simulator.model, edata=edata)"
116+
"plot_observable_trajectories(rdata, edata=edata)"
117117
],
118118
"id": "d6bbefc2e3d3ccbc"
119119
},
@@ -197,8 +197,8 @@
197197
"metadata": {},
198198
"outputs": [],
199199
"source": [
200-
"plot_observable_trajectories(rdata, model=model, edata=edata)\n",
201-
"plot_state_trajectories(rdata, model=model)"
200+
"plot_observable_trajectories(rdata, edata=edata)\n",
201+
"plot_state_trajectories(rdata)"
202202
]
203203
},
204204
{

doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,10 @@
233233
"\n",
234234
"# plot trajectories\n",
235235
"fig, axes = plt.subplots(2, 2, figsize=(8, 8))\n",
236-
"plot_state_trajectories(rdata, model=model, ax=axes[0, 0])\n",
237-
"plot_observable_trajectories(rdata, model=model, ax=axes[1, 0])\n",
238-
"plot_state_trajectories(rdata_reduced, model=model_reduced, ax=axes[0, 1])\n",
239-
"plot_observable_trajectories(rdata_reduced, model=model_reduced, ax=axes[1, 1])\n",
236+
"plot_state_trajectories(rdata, ax=axes[0, 0])\n",
237+
"plot_observable_trajectories(rdata, ax=axes[1, 0])\n",
238+
"plot_state_trajectories(rdata_reduced, ax=axes[0, 1])\n",
239+
"plot_observable_trajectories(rdata_reduced, ax=axes[1, 1])\n",
240240
"fig.tight_layout()"
241241
]
242242
},
@@ -386,7 +386,7 @@
386386
"timepoints = np.linspace(0, 14, 200)\n",
387387
"model.set_timepoints(timepoints)\n",
388388
"rdata = run_simulation(model, solver)\n",
389-
"plot_state_trajectories(rdata, model=model)\n",
389+
"plot_state_trajectories(rdata)\n",
390390
"\n",
391391
"for stst_value in steady_state:\n",
392392
" plt.axhline(y=stst_value, color=\"gray\", linestyle=\"--\", linewidth=1)"
@@ -501,8 +501,8 @@
501501
"print(\"Initial state used for simulation:\", rdata_reduced[\"x0\"])\n",
502502
"\n",
503503
"\n",
504-
"plot_state_trajectories(rdata_reduced, model=model_reduced)\n",
505-
"plot_observable_trajectories(rdata_reduced, model=model_reduced)"
504+
"plot_state_trajectories(rdata_reduced)\n",
505+
"plot_observable_trajectories(rdata_reduced)"
506506
]
507507
},
508508
{

doc/examples/getting_started/GettingStarted.ipynb

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
},
2222
{
2323
"cell_type": "code",
24+
"execution_count": null,
2425
"metadata": {},
26+
"outputs": [],
2527
"source": [
2628
"import amici\n",
29+
"import numpy as np\n",
2730
"\n",
2831
"sbml_importer = amici.SbmlImporter(\"model_steadystate_scaled.xml\")"
29-
],
30-
"outputs": [],
31-
"execution_count": null
32+
]
3233
},
3334
{
3435
"cell_type": "markdown",
@@ -39,14 +40,14 @@
3940
},
4041
{
4142
"cell_type": "code",
43+
"execution_count": null,
4244
"metadata": {},
45+
"outputs": [],
4346
"source": [
4447
"model_name = \"model_steadystate\"\n",
4548
"model_dir = \"model_dir\"\n",
4649
"sbml_importer.sbml2amici(model_name, model_dir)"
47-
],
48-
"outputs": [],
49-
"execution_count": null
50+
]
5051
},
5152
{
5253
"cell_type": "markdown",
@@ -58,17 +59,17 @@
5859
},
5960
{
6061
"cell_type": "code",
62+
"execution_count": null,
6163
"metadata": {},
64+
"outputs": [],
6265
"source": [
6366
"# load the model module\n",
6467
"model_module = amici.import_model_module(model_name, model_dir)\n",
6568
"# instantiate model\n",
6669
"model = model_module.get_model()\n",
6770
"# instantiate solver\n",
6871
"solver = model.create_solver()"
69-
],
70-
"outputs": [],
71-
"execution_count": null
72+
]
7273
},
7374
{
7475
"cell_type": "markdown",
@@ -77,10 +78,12 @@
7778
},
7879
{
7980
"cell_type": "code",
81+
"execution_count": null,
8082
"metadata": {},
81-
"source": "model.set_free_parameter_by_name(\"p1\", 1e-3)",
8283
"outputs": [],
83-
"execution_count": null
84+
"source": [
85+
"model.set_free_parameter_by_name(\"p1\", 1e-3)"
86+
]
8487
},
8588
{
8689
"cell_type": "markdown",
@@ -89,10 +92,12 @@
8992
},
9093
{
9194
"cell_type": "code",
95+
"execution_count": null,
9296
"metadata": {},
93-
"source": "solver.set_absolute_tolerance(1e-10)",
9497
"outputs": [],
95-
"execution_count": null
98+
"source": [
99+
"solver.set_absolute_tolerance(1e-10)"
100+
]
96101
},
97102
{
98103
"cell_type": "markdown",
@@ -108,14 +113,14 @@
108113
},
109114
{
110115
"cell_type": "code",
116+
"execution_count": null,
111117
"metadata": {},
118+
"outputs": [],
112119
"source": [
113120
"# set timepoints\n",
114-
"model.set_timepoints([0, 1])\n",
121+
"model.set_timepoints(np.linspace(0, 10, 101))\n",
115122
"rdata = model.simulate(solver=solver)"
116-
],
117-
"outputs": [],
118-
"execution_count": null
123+
]
119124
},
120125
{
121126
"cell_type": "markdown",
@@ -124,36 +129,51 @@
124129
},
125130
{
126131
"cell_type": "code",
132+
"execution_count": null,
127133
"metadata": {},
134+
"outputs": [],
128135
"source": [
129136
"rdata.x"
130-
],
131-
"outputs": [],
132-
"execution_count": null
137+
]
133138
},
134139
{
135140
"cell_type": "markdown",
136141
"metadata": {},
137-
"source": "All results attributes are always ordered according to the model. For species, this means that the columns of `rdata.x` match the ordering of species in the model, which can be accessed as [Model.get_state_names](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.html#amici.sim.sundials.Model.get_state_names)"
142+
"source": "All results attributes are always ordered according to the model. For species, this means that the columns of `rdata.x` match the ordering of species in the model, which can be accessed as [Model.get_state_names](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.html#amici.sim.sundials.Model.get_state_names) or as `ReturnData.state_names`:"
138143
},
139144
{
140145
"cell_type": "code",
146+
"execution_count": null,
141147
"metadata": {},
142-
"source": "model.get_state_names()",
143148
"outputs": [],
144-
"execution_count": null
149+
"source": [
150+
"model.get_state_names()"
151+
]
145152
},
146153
{
147-
"metadata": {},
148154
"cell_type": "markdown",
155+
"metadata": {},
149156
"source": "For convenience, most results stored in `ReturnData` can also be retrieved as [xarray.DataArray](https://docs.xarray.dev/en/stable/index.html) objects that already include the respective row and column names. This can be accessed via the `xr` attribute of `ReturnData`. Here, we access the model state `x` as `DataArray` object to convert it to a `pandas.DataFrame`:"
150157
},
151158
{
159+
"cell_type": "code",
160+
"execution_count": null,
152161
"metadata": {},
162+
"outputs": [],
163+
"source": [
164+
"rdata.xr.x.to_pandas()"
165+
]
166+
},
167+
{
153168
"cell_type": "code",
154-
"source": "rdata.xr.x.to_pandas()",
169+
"execution_count": null,
170+
"metadata": {},
155171
"outputs": [],
156-
"execution_count": null
172+
"source": [
173+
"from amici.sim.sundials.plotting import *\n",
174+
"\n",
175+
"plot_state_trajectories(rdata)"
176+
]
157177
},
158178
{
159179
"cell_type": "markdown",

0 commit comments

Comments
 (0)