Skip to content

Commit 46b74e9

Browse files
committed
Move sundials-related functionality to amici.sim.sundials.*
Related to #3041.
1 parent 20b07e9 commit 46b74e9

File tree

113 files changed

+1267
-992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1267
-992
lines changed

.github/workflows/test_conda_install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Test import
4848
shell: bash -l {0}
4949
run: |
50-
python -c "from amici import _amici; print(_amici)"
50+
python -c "from amici._installation import _amici; print(_amici)"
5151
python -m amici
5252
- name: Run SBML import test
5353
shell: bash -l {0}

.github/workflows/test_python_cplusplus.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
run: scripts/installAmiciSource.sh
5757

5858
- name: Check OpenMP support
59-
run: source venv/bin/activate && python -c "import amici; import sys; sys.exit(not amici.compiled_with_openmp())"
59+
run: source venv/bin/activate && python -c "from amici.sim.sundials import compiled_with_openmp; import sys; sys.exit(not compiled_with_openmp())"
6060

6161
- name: Python tests (part 1)
6262
run: |
@@ -278,7 +278,7 @@ jobs:
278278
run: scripts/installAmiciSource.sh
279279

280280
- name: Check OpenMP support
281-
run: source venv/bin/activate && python -c "import amici; import sys; sys.exit(not amici.compiled_with_openmp())"
281+
run: source venv/bin/activate && python -c "from amici.sim.sundials import compiled_with_openmp; import sys; sys.exit(not compiled_with_openmp())"
282282

283283
- name: cppcheck
284284
run: scripts/run-cppcheck.sh
@@ -340,7 +340,7 @@ jobs:
340340
scripts/installAmiciSource.sh
341341
342342
- name: Check OpenMP support
343-
run: source venv/bin/activate && python -c "import amici; import sys; sys.exit(not amici.compiled_with_openmp())"
343+
run: source venv/bin/activate && python -c "from amici.sim.sundials import compiled_with_openmp; import sys; sys.exit(not compiled_with_openmp())"
344344

345345
- name: Get BioNetGen
346346
run: scripts/buildBNGL.sh

.gitignore

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ python/tests/piecewise_test/*
155155

156156
python/sdist/amici.egg-info/*
157157
python/sdist/amici/version.txt
158-
python/sdist/amici/amici.py
159-
python/sdist/amici/amici_wrap.cxx
160-
python/sdist/amici/amici_without_hdf5.py
161-
python/sdist/amici/amici_wrap_without_hdf5.cxx
162-
python/sdist/amici/include/
163-
python/sdist/amici/lib/
164-
python/sdist/amici/share/
158+
python/sdist/amici/_installation/amici.py
159+
python/sdist/amici/_installation/amici_wrap.cxx
160+
python/sdist/amici/_installation/amici_without_hdf5.py
161+
python/sdist/amici/_installation/amici_wrap_without_hdf5.cxx
162+
python/sdist/amici/_installation/include/
163+
python/sdist/amici/_installation/lib/
164+
python/sdist/amici/_installation/share/
165165
python/sdist/build/*
166166
python/sdist/amici/git_version.txt
167167

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def install_doxygen():
9393
# -- Mock out some problematic modules-------------------------------------
9494

9595
# Note that for sub-modules, all parent modules must be listed explicitly.
96-
autodoc_mock_imports = ["_amici", "amici._amici"]
96+
autodoc_mock_imports = ["_amici", "amici._installation._amici"]
9797
for mod_name in autodoc_mock_imports:
9898
sys.modules[mod_name] = mock.MagicMock()
9999

@@ -363,7 +363,7 @@ def install_doxygen():
363363
"BoolVector": ":class:`bool`",
364364
"DoubleVector": ":class:`float`",
365365
"StringVector": ":class:`str`",
366-
"ExpDataPtrVector": ":class:`amici.amici.ExpData`",
366+
"ExpDataPtrVector": ":class:`amici.sim.sundials.ExpData`",
367367
}
368368

369369
# TODO: alias for forward type definition, remove after release of petab_sciml

doc/examples/example_errors.ipynb

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,40 @@
1111
]
1212
},
1313
{
14-
"metadata": {},
1514
"cell_type": "code",
16-
"outputs": [],
1715
"execution_count": null,
16+
"id": "b9e6cb8843da8bc3",
17+
"metadata": {},
18+
"outputs": [],
1819
"source": [
1920
"%matplotlib inline\n",
2021
"import os\n",
2122
"from contextlib import suppress\n",
2223
"from pathlib import Path\n",
2324
"\n",
24-
"import amici\n",
2525
"import matplotlib.pyplot as plt\n",
2626
"import numpy as np\n",
2727
"from amici import (\n",
2828
" SbmlImporter,\n",
29-
" SensitivityMethod,\n",
30-
" SensitivityOrder,\n",
31-
" SteadyStateSensitivityMode,\n",
3229
" import_model_module,\n",
33-
" run_simulation,\n",
34-
" simulation_status_to_str,\n",
3530
")\n",
3631
"from amici.importers.petab.v1 import (\n",
3732
" EDATAS,\n",
3833
" RDATAS,\n",
3934
" import_petab_problem,\n",
4035
" simulate_petab,\n",
4136
")\n",
42-
"from amici.plotting import plot_jacobian, plot_state_trajectories\n",
37+
"from amici.sim.sundials import (\n",
38+
" AMICI_SUCCESS,\n",
39+
" ExpData,\n",
40+
" SensitivityMethod,\n",
41+
" SensitivityOrder,\n",
42+
" SteadyStateSensitivityMode,\n",
43+
" run_simulation,\n",
44+
" simulation_status_to_str,\n",
45+
" unscale_parameter,\n",
46+
")\n",
47+
"from amici.sim.sundials.plotting import plot_jacobian, plot_state_trajectories\n",
4348
"from petab.v1.sbml import get_sbml_model\n",
4449
"\n",
4550
"try:\n",
@@ -51,8 +56,7 @@
5156
" import benchmark_models_petab\n",
5257
" except ModuleNotFoundError:\n",
5358
" print(\"** Please restart the kernel. **\")"
54-
],
55-
"id": "b9e6cb8843da8bc3"
59+
]
5660
},
5761
{
5862
"cell_type": "markdown",
@@ -131,9 +135,9 @@
131135
"\n",
132136
"The number of steps the solver has to take is closely related to the chosen error tolerance. More accurate results, more steps. Therefore, this problem can be solved in two ways:\n",
133137
"\n",
134-
"1. Increasing the maximum number of steps via [amici.Solver.set_max_steps](https://amici.readthedocs.io/en/latest/generated/amici.amici.Solver.html#amici.amici.Solver.set_max_steps). Note that this will increase the time required for simulation, and that simulation may still fail eventually. Sometimes it may be preferable to not increase this limit but rather fail fast. Also note that increasing the number of allowed steps increase RAM requirements (even if fewer steps are actually taken), so don't set this to ridiculously large values in order to avoid this error.\n",
138+
"1. Increasing the maximum number of steps via [Solver.set_max_steps](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.Solver.html#amici.sim.sundials.Solver.set_max_steps). Note that this will increase the time required for simulation, and that simulation may still fail eventually. Sometimes it may be preferable to not increase this limit but rather fail fast. Also note that increasing the number of allowed steps increase RAM requirements (even if fewer steps are actually taken), so don't set this to ridiculously large values in order to avoid this error.\n",
135139
"\n",
136-
"2. Reducing the number of steps CVODES has to take. This is determined by the required error tolerance. There are various solver error tolerances than can be adjusted. The most relevant ones are those controlled via [amici.Solver.set_relative_tolerance()](https://amici.readthedocs.io/en/latest/generated/amici.amici.Solver.html#amici.amici.Solver.set_relative_tolerance) and [amici.Solver.set_absolute_tolerance()](https://amici.readthedocs.io/en/latest/generated/amici.amici.Solver.html#amici.amici.Solver.set_absolute_tolerance).\n",
140+
"2. Reducing the number of steps CVODES has to take. This is determined by the required error tolerance. There are various solver error tolerances than can be adjusted. The most relevant ones are those controlled via [Solver.set_relative_tolerance()](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.Solver.html#amici.sim.sundials.Solver.set_relative_tolerance) and [Solver.set_absolute_tolerance()](https://amici.readthedocs.io/en/latest/generated/amici.sim.sundials.Solver.html#amici.sim.sundials.Solver.set_absolute_tolerance).\n",
137141
"\n",
138142
"So, let's fix that:"
139143
]
@@ -162,7 +166,7 @@
162166
" \"Status:\",\n",
163167
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
164168
")\n",
165-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
169+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
166170
"print(\"Simulations finished successfully.\")\n",
167171
"print()\n",
168172
"\n",
@@ -183,7 +187,7 @@
183187
" \"Status:\",\n",
184188
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
185189
")\n",
186-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
190+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
187191
"print(\"Simulations finished successfully.\")"
188192
]
189193
},
@@ -253,7 +257,7 @@
253257
"outputs": [],
254258
"source": [
255259
"# Create a copy of this simulation condition\n",
256-
"edata = amici.ExpData(res[EDATAS][0])\n",
260+
"edata = ExpData(res[EDATAS][0])\n",
257261
"edata.set_timepoints(np.linspace(0, 0.33011, 5000))\n",
258262
"amici_solver = amici_model.create_solver()\n",
259263
"rdata = run_simulation(amici_model, amici_solver, edata)\n",
@@ -403,7 +407,7 @@
403407
" \"Status:\",\n",
404408
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
405409
")\n",
406-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
410+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
407411
"print(\"Simulations finished successfully.\")"
408412
]
409413
},
@@ -631,9 +635,7 @@
631635
"unscaled_parameter = dict(\n",
632636
" zip(\n",
633637
" amici_model.get_free_parameter_ids(),\n",
634-
" starmap(\n",
635-
" amici.unscale_parameter, zip(edata.free_parameters, edata.pscale)\n",
636-
" ),\n",
638+
" starmap(unscale_parameter, zip(edata.free_parameters, edata.pscale)),\n",
637639
" )\n",
638640
")\n",
639641
"print(dict((p, unscaled_parameter[p]) for p in (\"Kd\", \"Kp\", \"n_par\")))"
@@ -796,7 +798,7 @@
796798
" \"Status:\",\n",
797799
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
798800
")\n",
799-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
801+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
800802
]
801803
},
802804
{
@@ -835,7 +837,7 @@
835837
" \"Status:\",\n",
836838
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
837839
")\n",
838-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
840+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
839841
]
840842
},
841843
{
@@ -972,7 +974,7 @@
972974
"\n",
973975
"# hard to reproduce on GHA\n",
974976
"if os.getenv(\"GITHUB_ACTIONS\") is None:\n",
975-
" assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
977+
" assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
976978
]
977979
},
978980
{
@@ -998,7 +1000,7 @@
9981000
" scaled_parameters=True,\n",
9991001
" solver=amici_solver,\n",
10001002
" )\n",
1001-
" if all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS]):\n",
1003+
" if all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS]):\n",
10021004
" print(\n",
10031005
" f\"-> Succeeded with relative steady state tolerance {amici_solver.get_relative_tolerance_steady_state()}\\n\"\n",
10041006
" )\n",
@@ -1014,7 +1016,7 @@
10141016
"rdata = res[RDATAS][0]\n",
10151017
"print(f\"preeq_status={rdata.preeq_status}\")\n",
10161018
"print(f\"{rdata.preeq_numsteps=}\")\n",
1017-
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
1019+
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
10181020
]
10191021
},
10201022
{

doc/examples/example_jax/ExampleJax.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@
274274
]
275275
},
276276
{
277-
"metadata": {},
278277
"cell_type": "code",
279-
"outputs": [],
280278
"execution_count": null,
279+
"id": "4c510f3e65879888",
280+
"metadata": {},
281+
"outputs": [],
281282
"source": [
282283
"from amici.importers.petab.v1 import import_petab_problem\n",
283284
"\n",
284285
"amici_model = import_petab_problem(petab_problem, compile_=True, verbose=False)"
285-
],
286-
"id": "4c510f3e65879888"
286+
]
287287
},
288288
{
289289
"cell_type": "markdown",
@@ -304,16 +304,17 @@
304304
]
305305
},
306306
{
307-
"metadata": {},
308307
"cell_type": "code",
309-
"outputs": [],
310308
"execution_count": null,
309+
"id": "beb890bd2f3d0880",
310+
"metadata": {},
311+
"outputs": [],
311312
"source": [
312-
"import amici\n",
313313
"from amici.importers.petab.v1 import simulate_petab\n",
314+
"from amici.sim.sundials import SensitivityOrder\n",
314315
"\n",
315316
"amici_solver = amici_model.create_solver()\n",
316-
"amici_solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
317+
"amici_solver.set_sensitivity_order(SensitivityOrder.first)\n",
317318
"\n",
318319
"\n",
319320
"def amici_callback_base(parameters: jnp.array):\n",
@@ -328,8 +329,7 @@
328329
" tuple(ret[\"sllh\"][par_id] for par_id in petab_problem.x_free_ids)\n",
329330
" )\n",
330331
" return llh, sllh"
331-
],
332-
"id": "beb890bd2f3d0880"
332+
]
333333
},
334334
{
335335
"cell_type": "markdown",

doc/examples/example_jax_petab/ExampleJaxPEtab.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,8 @@
565565
"metadata": {},
566566
"outputs": [],
567567
"source": [
568-
"import amici\n",
569568
"from amici.importers.petab.v1 import simulate_petab\n",
569+
"from amici.sim.sundials import SensitivityMethod, SensitivityOrder\n",
570570
"\n",
571571
"# Import the PEtab problem as a standard AMICI model\n",
572572
"amici_model = import_petab_problem(\n",
@@ -594,7 +594,7 @@
594594
"outputs": [],
595595
"source": [
596596
"# Profile simulation only\n",
597-
"solver.set_sensitivity_order(amici.SensitivityOrder.none)"
597+
"solver.set_sensitivity_order(SensitivityOrder.none)"
598598
]
599599
},
600600
{
@@ -616,16 +616,16 @@
616616
]
617617
},
618618
{
619-
"metadata": {},
620619
"cell_type": "code",
621-
"source": [
622-
"# Profile gradient computation using forward sensitivity analysis\n",
623-
"solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
624-
"solver.set_sensitivity_method(amici.SensitivityMethod.forward)"
625-
],
620+
"execution_count": null,
626621
"id": "81fe95a6e7f613f1",
622+
"metadata": {},
627623
"outputs": [],
628-
"execution_count": null
624+
"source": [
625+
"# Profile gradient computation using forward sensitivity analysis\n",
626+
"solver.set_sensitivity_order(SensitivityOrder.first)\n",
627+
"solver.set_sensitivity_method(SensitivityMethod.forward)"
628+
]
629629
},
630630
{
631631
"cell_type": "code",
@@ -653,8 +653,8 @@
653653
"outputs": [],
654654
"source": [
655655
"# Profile gradient computation using adjoint sensitivity analysis\n",
656-
"solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
657-
"solver.set_sensitivity_method(amici.SensitivityMethod.adjoint)"
656+
"solver.set_sensitivity_order(SensitivityOrder.first)\n",
657+
"solver.set_sensitivity_method(SensitivityMethod.adjoint)"
658658
]
659659
},
660660
{

doc/examples/example_petab/petab.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
]
1313
},
1414
{
15-
"metadata": {},
1615
"cell_type": "code",
17-
"outputs": [],
1816
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
1919
"source": [
2020
"import petab\n",
21-
"from amici import run_simulation\n",
2221
"from amici.importers.petab.v1 import (\n",
2322
" import_petab_problem,\n",
2423
" simulate_petab,\n",
2524
")\n",
2625
"from amici.importers.petab.v1.petab_problem import PetabProblem\n",
27-
"from amici.plotting import plot_state_trajectories"
26+
"from amici.sim.sundials import run_simulation\n",
27+
"from amici.sim.sundials.plotting import plot_state_trajectories"
2828
]
2929
},
3030
{

0 commit comments

Comments
 (0)