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
3 changes: 0 additions & 3 deletions .github/workflows/test_petab_sciml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ name: PEtab
on:
push:
branches:
- develop
- main
- 'release*'
pull_request:
branches:
- main
- develop
- jax_sciml
merge_group:
workflow_dispatch:

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_sbml_semantic_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
- python/sdist/amici/exporters/sundials/de_export.py
- python/sdist/amici/de_model_components.py
- python/sdist/amici/de_model.py
- python/sdist/amici/sbml_import.py
- python/sdist/amici/import_utils.py
- python/sdist/amici/importers/sbml/**
- python/sdist/amici/importers/utils.py
- scripts/run-SBMLTestsuite.sh
- tests/sbml/testSBMLSuite.py
- tests/sbml/conftest.py
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ flags:
carryforward: false
sbmlsuite:
paths:
- "python/amici/sbml_import.py"
- "python/amici/de_export.py"
- python/amici/importers/sbml/**
- python/amici/exporters/sundials/de_export.py
carryforward: true
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@
"\n",
"#### Parameters as constants\n",
"\n",
"By default, AMICI will generate sensitivity equations with respect to all model parameters. If it is clear upfront, that sensitivities with respect to certain parameters will not be required, their IDs can be passed to [amici.sbml_import.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.sbml_import.SbmlImporter.html#amici.sbml_import.SbmlImporter.sbml2amici) or [amici.pysb_import.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.pysb_import.html?highlight=pysb2amici#amici.pysb_import.pysb2amici) via the `constant_parameters` argument to not generate the respective equations. This will reduce CPU time and RAM requirements during import and simulation.\n",
"By default, AMICI will generate sensitivity equations with respect to all model parameters. If it is clear upfront, that sensitivities with respect to certain parameters will not be required, their IDs can be passed to [amici.importers.sbml.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.sbml.SbmlImporter.html#amici.importers.sbml.SbmlImporter.sbml2amici) or [amici.importers.pysb.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.pysb.html?highlight=pysb2amici#amici.importers.pysb.pysb2amici) via the `constant_parameters` argument to not generate the respective equations. This will reduce CPU time and RAM requirements during import and simulation.\n",
"The PEtab import will automatically pass all parameters with `petab.ESTIMATE==False` as `constant_parameters` arguments.\n",
"\n",
"See also the following section for the case that no sensitivities are required at all.\n",
"\n",
"\n",
"#### Not generating sensitivity code\n",
"\n",
"If only forward simulations of a model are required, a modest import speedup can be obtained from not generating sensitivity code. This can be enabled via the `generate_sensitivity_code` argument of [amici.sbml_import.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.sbml_import.SbmlImporter.html#amici.sbml_import.SbmlImporter.sbml2amici) or [amici.pysb_import.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.pysb_import.html?highlight=pysb2amici#amici.pysb_import.pysb2amici).\n",
"If only forward simulations of a model are required, a modest import speedup can be obtained from not generating sensitivity code. This can be enabled via the `generate_sensitivity_code` argument of [amici.importers.sbml.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.sbml.SbmlImporter.html#amici.importers.sbml.SbmlImporter.sbml2amici) or [amici.importers.pysb.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.pysb.html?highlight=pysb2amici#amici.importers.pysb.pysb2amici).\n",
"\n",
"Example:\n",
"```bash\n",
Expand Down Expand Up @@ -239,7 +239,7 @@
"\n",
"By default, AMICI will try to perform some basic simplification of model expressions. For complex model expressions, or for large models, this can become costly. It very much depends on the model expressions, whether the benefits outweigh the cost.\n",
"\n",
"Simplification of model expressions can be disabled by passing `simplify=None` to [amici.sbml_import.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.sbml_import.SbmlImporter.html#amici.sbml_import.SbmlImporter.sbml2amici) or [amici.pysb_import.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.pysb_import.html?highlight=pysb2amici#amici.pysb_import.pysb2amici).\n",
"Simplification of model expressions can be disabled by passing `simplify=None` to [amici.importers.sbml.SbmlImporter.sbml2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.sbml.SbmlImporter.html#amici.importers.sbml.SbmlImporter.sbml2amici) or [amici.importers.pysb.pysb2amici](https://amici.readthedocs.io/en/latest/generated/amici.importers.pysb.html?highlight=pysb2amici#amici.importers.pysb.pysb2amici).\n",
"\n",
"Depending on the given model, different simplification schemes may be cheaper or more beneficial than the default. SymPy's simplification functions are [well documented](https://docs.sympy.org/latest/modules/simplify/simplify.html)."
]
Expand Down
63 changes: 33 additions & 30 deletions doc/examples/example_splines/ExampleSplines.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,13 @@
"outputs": [],
"source": [
"# Create a spline object\n",
"spline = amici.splines.CubicHermiteSpline(\n",
"from amici.importers.sbml.splines import CubicHermiteSpline, UniformGrid\n",
"from amici.importers.utils import amici_time_symbol\n",
"\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol, # the spline function is evaluated at the current time point\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
" evaluate_at=amici_time_symbol, # the spline function is evaluated at the current time point\n",
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
" values_at_nodes=[1, -1, 2],\n",
")"
]
Expand Down Expand Up @@ -485,10 +488,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
" values_at_nodes=sp.symbols(\"f0:3\"),\n",
")"
]
Expand Down Expand Up @@ -619,10 +622,10 @@
"outputs": [],
"source": [
"# A simple spline for which finite differencing would give a different result\n",
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
" values_at_nodes=[1.0, -1.0, 1.0],\n",
" derivatives_at_nodes=[10.0, -10.0, -10.0],\n",
")"
Expand Down Expand Up @@ -717,10 +720,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
" values_at_nodes=[-2, 1, -1],\n",
" extrapolate=(\n",
" None,\n",
Expand Down Expand Up @@ -812,10 +815,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
" values_at_nodes=[-2, 1, -2], # first and last node must coincide\n",
" extrapolate=\"periodic\",\n",
")"
Expand Down Expand Up @@ -904,10 +907,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=4),\n",
" values_at_nodes=[-1, 2, 4, 2],\n",
" bc=\"zeroderivative\",\n",
")"
Expand Down Expand Up @@ -963,10 +966,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=4),\n",
" values_at_nodes=[-1, 2, 4, 2],\n",
" bc=\"natural\",\n",
")"
Expand Down Expand Up @@ -1029,10 +1032,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=5),\n",
" values_at_nodes=[2, 0.05, 0.1, 2, 1],\n",
")"
]
Expand Down Expand Up @@ -1068,10 +1071,10 @@
},
"outputs": [],
"source": [
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=5),\n",
" values_at_nodes=[2, 0.05, 0.1, 2, 1],\n",
" logarithmic_parametrization=True,\n",
")"
Expand Down Expand Up @@ -1191,10 +1194,10 @@
"df = None\n",
"for n in num_nodes + amici_only_nodes:\n",
" # Create model\n",
" spline = amici.splines.CubicHermiteSpline(\n",
" spline = CubicHermiteSpline(\n",
" sbml_id=\"f\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=n),\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=UniformGrid(0, 1, number_of_nodes=n),\n",
" values_at_nodes=np.random.rand(n),\n",
" )\n",
" sbml_doc = libsbml.SBMLReader().readSBML(\"example_splines.xml\")\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
"import os\n",
"\n",
"import amici\n",
"import amici.importers.sbml.splines as splines\n",
"import libsbml\n",
"import numpy as np\n",
"import pandas as pd\n",
"import petab\n",
"import pypesto.petab\n",
"import sympy as sp\n",
"from amici.importers.utils import amici_time_symbol\n",
"from matplotlib import pyplot as plt"
]
},
Expand Down Expand Up @@ -176,9 +178,9 @@
"values_at_nodes = [\n",
" sp.Symbol(f\"pEpoR_t{str(t).replace('.', '_dot_')}\") for t in nodes\n",
"] # new parameter symbols for spline values\n",
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = splines.CubicHermiteSpline(\n",
" sbml_id=\"pEpoR\", # matches name of species in SBML model\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol, # the spline is evaluated at the current time\n",
" evaluate_at=amici_time_symbol, # the spline is evaluated at the current time\n",
" nodes=nodes,\n",
" values_at_nodes=values_at_nodes, # values at the nodes (in linear scale)\n",
" extrapolate=(None, \"constant\"), # because steady state is reached\n",
Expand Down Expand Up @@ -782,9 +784,9 @@
"values_at_nodes = [\n",
" sp.Symbol(f\"pEpoR_t{str(t).replace('.', '_dot_')}\") for t in nodes\n",
"]\n",
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = splines.CubicHermiteSpline(\n",
" sbml_id=\"pEpoR\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=nodes,\n",
" values_at_nodes=values_at_nodes,\n",
" extrapolate=(None, \"constant\"),\n",
Expand Down Expand Up @@ -1492,9 +1494,9 @@
" sp.Symbol(f\"derivative_pEpoR_t{str(t).replace('.', '_dot_')}\")\n",
" for t in nodes[:-1]\n",
"]\n",
"spline = amici.splines.CubicHermiteSpline(\n",
"spline = splines.CubicHermiteSpline(\n",
" sbml_id=\"pEpoR\",\n",
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
" evaluate_at=amici_time_symbol,\n",
" nodes=nodes,\n",
" values_at_nodes=values_at_nodes,\n",
" derivatives_at_nodes=derivatives_at_nodes\n",
Expand Down Expand Up @@ -1591,7 +1593,9 @@
"source": [
"# Derivative parameters must be added separately\n",
"for p in derivatives_at_nodes:\n",
" amici.sbml_utils.add_parameter(sbml_model, p, value=0.0, constant=True)"
" amici.importers.sbml.utils.add_parameter(\n",
" sbml_model, p, value=0.0, constant=True\n",
" )"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
"from amici import (\n",
" MeasurementChannel as MC,\n",
")\n",
"from amici.antimony_import import antimony2sbml\n",
"from amici.importers.antimony import antimony2sbml\n",
"from amici.plotting import (\n",
" plot_observable_trajectories,\n",
" plot_state_trajectories,\n",
Expand Down
8 changes: 4 additions & 4 deletions doc/python_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SBML import
-----------

AMICI can import :term:`SBML` models via the
:py:func:`amici.sbml_import.SbmlImporter` class.
:py:func:`amici.importers.sbml.SbmlImporter` class.

.. _amici_python_sbml_support:

Expand Down Expand Up @@ -113,13 +113,13 @@ PySB import
-----------

AMICI can import :term:`PySB` models via
:py:func:`amici.pysb_import.pysb2amici`.
:py:func:`amici.importers.pysb.pysb2amici`.

BNGL import
-----------

AMICI can import :term:`BNGL` models via
:py:func:`amici.bngl_import.bngl2amici`.
:py:func:`amici.importers.bngl.bngl2amici`.

PEtab import
------------
Expand Down Expand Up @@ -162,7 +162,7 @@ An example using Antimony to specify the Lotka-Volterra equations is shown below
end
"""
module_name = "test_antimony_example_lv"
from amici.antimony_import import antimony2amici
from amici.importers.antimony import antimony2amici
antimony2amici(
ant_model,
model_name=module_name,
Expand Down
17 changes: 9 additions & 8 deletions doc/python_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ AMICI Python API

amici
amici.amici
amici.sbml_import
amici.pysb_import
amici.bngl_import
amici.importers.utils
amici.importers.sbml
amici.importers.sbml.conserved_quantities_demartino
amici.importers.sbml.conserved_quantities_rref
amici.importers.sbml.utils
amici.importers.sbml.splines
amici.importers.pysb
amici.importers.bngl
amici.importers.antimony
amici.petab
amici.petab.conditions
amici.petab.import_helpers
Expand All @@ -21,7 +27,6 @@ AMICI Python API
amici.petab.sbml_import
amici.petab.simulations
amici.petab.simulator
amici.import_utils
amici.jax
amici.exporters.sundials.de_export
amici.de_model
Expand All @@ -30,9 +35,5 @@ AMICI Python API
amici.pandas
amici.logging
amici.gradient_check
amici.conserved_quantities_demartino
amici.conserved_quantities_rref
amici.numpy
amici.sbml_utils
amici.splines
amici.adapters.fiddy
2 changes: 1 addition & 1 deletion python/benchmark/benchmark_pysb.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import pandas as pd
import pysb
from amici.pysb_import import pysb2amici
from amici.importers.pysb import pysb2amici
from pysb.simulator import ScipyOdeSimulator

sys.path.insert(0, os.path.join("..", "tests"))
Expand Down
4 changes: 2 additions & 2 deletions python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def get_model_dir(model_id: str | None = None, jax: bool = False) -> Path:
# These modules don't require the swig interface
from typing import Protocol, runtime_checkable

from .import_utils import MeasurementChannel # noqa: F401
from .sbml_import import ( # noqa: F401
from .importers.sbml import ( # noqa: F401
SbmlImporter,
assignment_rules_to_observables,
)
from .importers.utils import MeasurementChannel # noqa: F401

try:
from .jax import JAXModel
Expand Down
4 changes: 2 additions & 2 deletions python/sdist/amici/de_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
var_in_function_signature,
)
from .exporters.sundials.cxxcodeprinter import csc_matrix
from .import_utils import (
from .importers.utils import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay for now, but I'd say we should make the core symbolic code not import anything from amici.importers, only vice verse. Can be addressed when moving de_model.py.

ObservableTransformation,
SBMLException,
_default_simplify,
Expand All @@ -63,7 +63,7 @@
)

if TYPE_CHECKING:
from .splines import AbstractSpline
from amici.importers.sbml.splines import AbstractSpline

logger = get_logger(__name__, logging.ERROR)

Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/de_model_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sympy as sp

from .constants import SymbolId
from .import_utils import (
from .importers.utils import (
RESERVED_SYMBOLS,
ObservableTransformation,
amici_time_symbol,
Expand Down
Loading
Loading