Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test_conda_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Test import
shell: bash -l {0}
run: |
python -c "from amici import _amici; print(_amici)"
python -c "from amici._installation import _amici; print(_amici)"
python -m amici
- name: Run SBML import test
shell: bash -l {0}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test_python_cplusplus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: scripts/installAmiciSource.sh

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

- name: Python tests (part 1)
run: |
Expand Down Expand Up @@ -278,7 +278,7 @@ jobs:
run: scripts/installAmiciSource.sh

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

- name: cppcheck
run: scripts/run-cppcheck.sh
Expand Down Expand Up @@ -340,7 +340,7 @@ jobs:
scripts/installAmiciSource.sh

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

- name: Get BioNetGen
run: scripts/buildBNGL.sh
Expand Down
14 changes: 7 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ python/tests/piecewise_test/*

python/sdist/amici.egg-info/*
python/sdist/amici/version.txt
python/sdist/amici/amici.py
python/sdist/amici/amici_wrap.cxx
python/sdist/amici/amici_without_hdf5.py
python/sdist/amici/amici_wrap_without_hdf5.cxx
python/sdist/amici/include/
python/sdist/amici/lib/
python/sdist/amici/share/
python/sdist/amici/_installation/amici.py
python/sdist/amici/_installation/amici_wrap.cxx
python/sdist/amici/_installation/amici_without_hdf5.py
python/sdist/amici/_installation/amici_wrap_without_hdf5.cxx
python/sdist/amici/_installation/include/
python/sdist/amici/_installation/lib/
python/sdist/amici/_installation/share/
python/sdist/build/*
python/sdist/amici/git_version.txt

Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def install_doxygen():
# -- Mock out some problematic modules-------------------------------------

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

Expand Down Expand Up @@ -363,7 +363,7 @@ def install_doxygen():
"BoolVector": ":class:`bool`",
"DoubleVector": ":class:`float`",
"StringVector": ":class:`str`",
"ExpDataPtrVector": ":class:`amici.amici.ExpData`",
"ExpDataPtrVector": ":class:`amici.sim.sundials.ExpData`",
}

# TODO: alias for forward type definition, remove after release of petab_sciml
Expand Down
52 changes: 27 additions & 25 deletions doc/examples/example_errors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,40 @@
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"id": "b9e6cb8843da8bc3",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import os\n",
"from contextlib import suppress\n",
"from pathlib import Path\n",
"\n",
"import amici\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from amici import (\n",
" SbmlImporter,\n",
" SensitivityMethod,\n",
" SensitivityOrder,\n",
" SteadyStateSensitivityMode,\n",
" import_model_module,\n",
" run_simulation,\n",
" simulation_status_to_str,\n",
")\n",
"from amici.importers.petab.v1 import (\n",
" EDATAS,\n",
" RDATAS,\n",
" import_petab_problem,\n",
" simulate_petab,\n",
")\n",
"from amici.plotting import plot_jacobian, plot_state_trajectories\n",
"from amici.sim.sundials import (\n",
" AMICI_SUCCESS,\n",
" ExpData,\n",
" SensitivityMethod,\n",
" SensitivityOrder,\n",
" SteadyStateSensitivityMode,\n",
" run_simulation,\n",
" simulation_status_to_str,\n",
" unscale_parameter,\n",
")\n",
"from amici.sim.sundials.plotting import plot_jacobian, plot_state_trajectories\n",
"from petab.v1.sbml import get_sbml_model\n",
"\n",
"try:\n",
Expand All @@ -51,8 +56,7 @@
" import benchmark_models_petab\n",
" except ModuleNotFoundError:\n",
" print(\"** Please restart the kernel. **\")"
],
"id": "b9e6cb8843da8bc3"
]
},
{
"cell_type": "markdown",
Expand Down Expand Up @@ -131,9 +135,9 @@
"\n",
"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",
"\n",
"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",
"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",
"\n",
"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",
"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",
"\n",
"So, let's fix that:"
]
Expand Down Expand Up @@ -162,7 +166,7 @@
" \"Status:\",\n",
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
"print(\"Simulations finished successfully.\")\n",
"print()\n",
"\n",
Expand All @@ -183,7 +187,7 @@
" \"Status:\",\n",
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
"print(\"Simulations finished successfully.\")"
]
},
Expand Down Expand Up @@ -253,7 +257,7 @@
"outputs": [],
"source": [
"# Create a copy of this simulation condition\n",
"edata = amici.ExpData(res[EDATAS][0])\n",
"edata = ExpData(res[EDATAS][0])\n",
"edata.set_timepoints(np.linspace(0, 0.33011, 5000))\n",
"amici_solver = amici_model.create_solver()\n",
"rdata = run_simulation(amici_model, amici_solver, edata)\n",
Expand Down Expand Up @@ -403,7 +407,7 @@
" \"Status:\",\n",
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])\n",
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])\n",
"print(\"Simulations finished successfully.\")"
]
},
Expand Down Expand Up @@ -631,9 +635,7 @@
"unscaled_parameter = dict(\n",
" zip(\n",
" amici_model.get_free_parameter_ids(),\n",
" starmap(\n",
" amici.unscale_parameter, zip(edata.free_parameters, edata.pscale)\n",
" ),\n",
" starmap(unscale_parameter, zip(edata.free_parameters, edata.pscale)),\n",
" )\n",
")\n",
"print(dict((p, unscaled_parameter[p]) for p in (\"Kd\", \"Kp\", \"n_par\")))"
Expand Down Expand Up @@ -796,7 +798,7 @@
" \"Status:\",\n",
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
]
},
{
Expand Down Expand Up @@ -835,7 +837,7 @@
" \"Status:\",\n",
" [simulation_status_to_str(rdata.status) for rdata in res[RDATAS]],\n",
")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
]
},
{
Expand Down Expand Up @@ -972,7 +974,7 @@
"\n",
"# hard to reproduce on GHA\n",
"if os.getenv(\"GITHUB_ACTIONS\") is None:\n",
" assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
" assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
]
},
{
Expand All @@ -998,7 +1000,7 @@
" scaled_parameters=True,\n",
" solver=amici_solver,\n",
" )\n",
" if all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS]):\n",
" if all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS]):\n",
" print(\n",
" f\"-> Succeeded with relative steady state tolerance {amici_solver.get_relative_tolerance_steady_state()}\\n\"\n",
" )\n",
Expand All @@ -1014,7 +1016,7 @@
"rdata = res[RDATAS][0]\n",
"print(f\"preeq_status={rdata.preeq_status}\")\n",
"print(f\"{rdata.preeq_numsteps=}\")\n",
"assert all(rdata.status == amici.AMICI_SUCCESS for rdata in res[RDATAS])"
"assert all(rdata.status == AMICI_SUCCESS for rdata in res[RDATAS])"
]
},
{
Expand Down
20 changes: 10 additions & 10 deletions doc/examples/example_jax/ExampleJax.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -274,16 +274,16 @@
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"id": "4c510f3e65879888",
"metadata": {},
"outputs": [],
"source": [
"from amici.importers.petab.v1 import import_petab_problem\n",
"\n",
"amici_model = import_petab_problem(petab_problem, compile_=True, verbose=False)"
],
"id": "4c510f3e65879888"
]
},
{
"cell_type": "markdown",
Expand All @@ -304,16 +304,17 @@
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"id": "beb890bd2f3d0880",
"metadata": {},
"outputs": [],
"source": [
"import amici\n",
"from amici.importers.petab.v1 import simulate_petab\n",
"from amici.sim.sundials import SensitivityOrder\n",
"\n",
"amici_solver = amici_model.create_solver()\n",
"amici_solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
"amici_solver.set_sensitivity_order(SensitivityOrder.first)\n",
"\n",
"\n",
"def amici_callback_base(parameters: jnp.array):\n",
Expand All @@ -328,8 +329,7 @@
" tuple(ret[\"sllh\"][par_id] for par_id in petab_problem.x_free_ids)\n",
" )\n",
" return llh, sllh"
],
"id": "beb890bd2f3d0880"
]
},
{
"cell_type": "markdown",
Expand Down
22 changes: 11 additions & 11 deletions doc/examples/example_jax_petab/ExampleJaxPEtab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@
"metadata": {},
"outputs": [],
"source": [
"import amici\n",
"from amici.importers.petab.v1 import simulate_petab\n",
"from amici.sim.sundials import SensitivityMethod, SensitivityOrder\n",
"\n",
"# Import the PEtab problem as a standard AMICI model\n",
"amici_model = import_petab_problem(\n",
Expand Down Expand Up @@ -594,7 +594,7 @@
"outputs": [],
"source": [
"# Profile simulation only\n",
"solver.set_sensitivity_order(amici.SensitivityOrder.none)"
"solver.set_sensitivity_order(SensitivityOrder.none)"
]
},
{
Expand All @@ -616,16 +616,16 @@
]
},
{
"metadata": {},
"cell_type": "code",
"source": [
"# Profile gradient computation using forward sensitivity analysis\n",
"solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
"solver.set_sensitivity_method(amici.SensitivityMethod.forward)"
],
"execution_count": null,
"id": "81fe95a6e7f613f1",
"metadata": {},
"outputs": [],
"execution_count": null
"source": [
"# Profile gradient computation using forward sensitivity analysis\n",
"solver.set_sensitivity_order(SensitivityOrder.first)\n",
"solver.set_sensitivity_method(SensitivityMethod.forward)"
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -653,8 +653,8 @@
"outputs": [],
"source": [
"# Profile gradient computation using adjoint sensitivity analysis\n",
"solver.set_sensitivity_order(amici.SensitivityOrder.first)\n",
"solver.set_sensitivity_method(amici.SensitivityMethod.adjoint)"
"solver.set_sensitivity_order(SensitivityOrder.first)\n",
"solver.set_sensitivity_method(SensitivityMethod.adjoint)"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions doc/examples/example_petab/petab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
]
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import petab\n",
"from amici import run_simulation\n",
"from amici.importers.petab.v1 import (\n",
" import_petab_problem,\n",
" simulate_petab,\n",
")\n",
"from amici.importers.petab.v1.petab_problem import PetabProblem\n",
"from amici.plotting import plot_state_trajectories"
"from amici.sim.sundials import run_simulation\n",
"from amici.sim.sundials.plotting import plot_state_trajectories"
]
},
{
Expand Down
Loading
Loading