diff --git a/.github/workflows/test_petab_sciml.yml b/.github/workflows/test_petab_sciml.yml index 097b722090..868ef74ff2 100644 --- a/.github/workflows/test_petab_sciml.yml +++ b/.github/workflows/test_petab_sciml.yml @@ -2,14 +2,11 @@ name: PEtab on: push: branches: - - develop - main - 'release*' pull_request: branches: - main - - develop - - jax_sciml merge_group: workflow_dispatch: diff --git a/.github/workflows/test_sbml_semantic_test_suite.yml b/.github/workflows/test_sbml_semantic_test_suite.yml index 81ccae5fc5..b3394d54ea 100644 --- a/.github/workflows/test_sbml_semantic_test_suite.yml +++ b/.github/workflows/test_sbml_semantic_test_suite.yml @@ -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 diff --git a/codecov.yml b/codecov.yml index 2779b486d1..98f92e7f89 100644 --- a/codecov.yml +++ b/codecov.yml @@ -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 diff --git a/doc/examples/example_large_models/example_performance_optimization.ipynb b/doc/examples/example_large_models/example_performance_optimization.ipynb index fe35582a5b..a8c7d43c2c 100644 --- a/doc/examples/example_large_models/example_performance_optimization.ipynb +++ b/doc/examples/example_large_models/example_performance_optimization.ipynb @@ -72,7 +72,7 @@ "\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", @@ -80,7 +80,7 @@ "\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", @@ -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)." ] diff --git a/doc/examples/example_splines/ExampleSplines.ipynb b/doc/examples/example_splines/ExampleSplines.ipynb index b343e1695c..53358d0fc9 100644 --- a/doc/examples/example_splines/ExampleSplines.ipynb +++ b/doc/examples/example_splines/ExampleSplines.ipynb @@ -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", ")" ] @@ -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", ")" ] @@ -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", ")" @@ -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", @@ -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", ")" @@ -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", ")" @@ -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", ")" @@ -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", ")" ] @@ -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", ")" @@ -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", diff --git a/doc/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb b/doc/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb index 5cbb78cd69..86cfb94763 100644 --- a/doc/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb +++ b/doc/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb @@ -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" ] }, @@ -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", @@ -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", @@ -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", @@ -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", + " )" ] }, { diff --git a/doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb b/doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb index f2b696c98c..4b1cc32213 100644 --- a/doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb +++ b/doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb @@ -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", diff --git a/doc/python_interface.rst b/doc/python_interface.rst index 011e2d618b..44689ccb86 100644 --- a/doc/python_interface.rst +++ b/doc/python_interface.rst @@ -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: @@ -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 ------------ @@ -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, diff --git a/doc/python_modules.rst b/doc/python_modules.rst index 87a5f691c2..4bb4258e3d 100644 --- a/doc/python_modules.rst +++ b/doc/python_modules.rst @@ -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 @@ -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 @@ -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 diff --git a/python/benchmark/benchmark_pysb.py b/python/benchmark/benchmark_pysb.py index 95697eceaf..ed22462437 100644 --- a/python/benchmark/benchmark_pysb.py +++ b/python/benchmark/benchmark_pysb.py @@ -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")) diff --git a/python/sdist/amici/__init__.py b/python/sdist/amici/__init__.py index 3e293c8806..908be46445 100644 --- a/python/sdist/amici/__init__.py +++ b/python/sdist/amici/__init__.py @@ -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 diff --git a/python/sdist/amici/de_model.py b/python/sdist/amici/de_model.py index 34194a97c7..445b4b068d 100644 --- a/python/sdist/amici/de_model.py +++ b/python/sdist/amici/de_model.py @@ -45,7 +45,7 @@ var_in_function_signature, ) from .exporters.sundials.cxxcodeprinter import csc_matrix -from .import_utils import ( +from .importers.utils import ( ObservableTransformation, SBMLException, _default_simplify, @@ -63,7 +63,7 @@ ) if TYPE_CHECKING: - from .splines import AbstractSpline + from amici.importers.sbml.splines import AbstractSpline logger = get_logger(__name__, logging.ERROR) diff --git a/python/sdist/amici/de_model_components.py b/python/sdist/amici/de_model_components.py index 0641fe9211..e460497718 100644 --- a/python/sdist/amici/de_model_components.py +++ b/python/sdist/amici/de_model_components.py @@ -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, diff --git a/python/sdist/amici/exporters/sundials/cxxcodeprinter.py b/python/sdist/amici/exporters/sundials/cxxcodeprinter.py index 3cc1751b4f..4d204e2748 100644 --- a/python/sdist/amici/exporters/sundials/cxxcodeprinter.py +++ b/python/sdist/amici/exporters/sundials/cxxcodeprinter.py @@ -12,7 +12,7 @@ from sympy.utilities.iterables import numbered_symbols from toposort import toposort -from ...import_utils import symbol_with_assumptions +from amici.importers.utils import symbol_with_assumptions class AmiciCxxCodePrinter(CXX11CodePrinter): diff --git a/python/sdist/amici/exporters/sundials/de_export.py b/python/sdist/amici/exporters/sundials/de_export.py index 1e908bb967..e0215579fc 100644 --- a/python/sdist/amici/exporters/sundials/de_export.py +++ b/python/sdist/amici/exporters/sundials/de_export.py @@ -5,8 +5,8 @@ equation model and generate executable C++ simulation code. The user generally won't have to directly call any function from this module as this will be done by -:py:func:`amici.pysb_import.pysb2amici`, -:py:func:`amici.sbml_import.SbmlImporter.sbml2amici` and +:py:func:`amici.importers.pysb.pysb2amici`, +:py:func:`amici.importers.sbml.SbmlImporter.sbml2amici` and :py:func:`amici.petab_import.import_model`. """ @@ -28,10 +28,10 @@ __commit__, __version__, get_model_dir, - splines, ) from ...de_model import DEModel from ...de_model_components import * +from ...importers.sbml import splines from ...logging import get_logger, log_execution_time, set_log_level from ...sympy_utils import ( _custom_pow_eval_derivative, diff --git a/python/sdist/amici/importers/__init__.py b/python/sdist/amici/importers/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/python/sdist/amici/antimony_import.py b/python/sdist/amici/importers/antimony/__init__.py similarity index 97% rename from python/sdist/amici/antimony_import.py rename to python/sdist/amici/importers/antimony/__init__.py index ad269f11fe..118e054098 100644 --- a/python/sdist/amici/antimony_import.py +++ b/python/sdist/amici/importers/antimony/__init__.py @@ -53,7 +53,7 @@ def antimony2amici(ant_model: str | Path, *args, **kwargs): For documentation see :meth:`amici.sbml_import.SbmlImporter.sbml2amici`. """ - from .sbml_import import SbmlImporter + from amici.importers.sbml import SbmlImporter sbml_str = antimony2sbml(ant_model) sbml_importer = SbmlImporter(sbml_str, from_file=False) diff --git a/python/sdist/amici/bngl_import.py b/python/sdist/amici/importers/bngl/__init__.py similarity index 77% rename from python/sdist/amici/bngl_import.py rename to python/sdist/amici/importers/bngl/__init__.py index 8624ca15f1..c493b4c226 100644 --- a/python/sdist/amici/bngl_import.py +++ b/python/sdist/amici/importers/bngl/__init__.py @@ -7,7 +7,7 @@ from pysb.importers.bngl import model_from_bngl -from .pysb_import import pysb2amici +from ..pysb import pysb2amici def bngl2amici(bngl_model: str, *args, **kwargs) -> None: @@ -19,10 +19,10 @@ def bngl2amici(bngl_model: str, *args, **kwargs) -> None: module :param args: - see :func:`amici.pysb_import.pysb2amici` for additional arguments + see :func:`amici.importers.pysb.pysb2amici` for additional arguments :param kwargs: - see :func:`amici.pysb_import.pysb2amici` for additional arguments + see :func:`amici.importers.pysb.pysb2amici` for additional arguments """ if "model" in kwargs: diff --git a/python/sdist/amici/pysb_import.py b/python/sdist/amici/importers/pysb/__init__.py similarity index 98% rename from python/sdist/amici/pysb_import.py rename to python/sdist/amici/importers/pysb/__init__.py index e29ee986e9..8728af88cc 100644 --- a/python/sdist/amici/pysb_import.py +++ b/python/sdist/amici/importers/pysb/__init__.py @@ -23,9 +23,8 @@ import sympy as sp import amici - -from .de_model import DEModel -from .de_model_components import ( +from amici.de_model import DEModel +from amici.de_model_components import ( Constant, DifferentialState, Event, @@ -37,7 +36,7 @@ Parameter, SigmaY, ) -from .import_utils import ( +from amici.importers.utils import ( MeasurementChannel, _default_simplify, _get_str_symbol_identifiers, @@ -46,7 +45,7 @@ noise_distribution_to_cost_function, noise_distribution_to_observable_transformation, ) -from .logging import get_logger, log_execution_time, set_log_level +from amici.logging import get_logger, log_execution_time, set_log_level CL_Prototype = dict[str, dict[str, Any]] ConservationLaw = dict[str, dict | str | sp.Basic] @@ -89,7 +88,7 @@ def pysb2jax( :param observation_model: The different measurement channels that make up the observation - model, see also :class:`amici.import_utils.MeasurementChannel`. + model, see also :class:`amici.importers.utils.MeasurementChannel`. The ID is expected to be the name of a :class:`pysb.Expression` or :class:`pysb.Observable` in the provided model that should be mapped to an observable. @@ -188,7 +187,7 @@ def pysb2amici( :param observation_model: The different measurement channels that make up the observation - model, see also :class:`amici.import_utils.MeasurementChannel`. + model, see also :class:`amici.importers.utils.MeasurementChannel`. The ID is expected to be the name of a :class:`pysb.Expression` or :class:`pysb.Observable` in the provided model that should be mapped to an observable. @@ -267,7 +266,7 @@ def pysb2amici( events=_events, ) - from .exporters.sundials.de_export import ( + from amici.exporters.sundials.de_export import ( DEExporter, ) @@ -289,7 +288,7 @@ def pysb2amici( if compile: exporter.compile_model() - from . import import_model_module + from amici import import_model_module return import_model_module( module_name=model_name, module_path=output_dir @@ -318,16 +317,16 @@ def ode_model_from_pysb_importer( instance. :param model: - see :func:`amici.pysb_import.pysb2amici` + see :func:`amici.importers.pysb.pysb2amici` :param constant_parameters: - see :func:`amici.pysb_import.pysb2amici` + see :func:`amici.importers.pysb.pysb2amici` :param observation_model: - see :func:`amici.pysb_import.pysb2amici` + see :func:`amici.importers.pysb.pysb2amici` :param compute_conservation_laws: - see :func:`amici.pysb_import.pysb2amici` + see :func:`amici.importers.pysb.pysb2amici` :param simplify: see :attr:`amici.DEModel._simplify` @@ -590,8 +589,8 @@ def _process_pysb_expressions( :param observation_model: A map of observable names to - :class:`amici.import_utils.MeasurementChannel`. - see also :func:`amici.pysb_import.pysb2amici` + :class:`amici.importers.utils.MeasurementChannel`. + see also :func:`amici.importers.pysb.pysb2amici` :param ode_model: DEModel instance @@ -769,7 +768,7 @@ def _process_pysb_observables( :param observation_model: Mapping from observable name to - :class:`amici.import_utils.MeasurementChannel`. + :class:`amici.importers.utils.MeasurementChannel`. :param pysb_model_has_obs_and_noise: if set to ``True``, the pysb model is expected to have extra diff --git a/python/sdist/amici/sbml_import.py b/python/sdist/amici/importers/sbml/__init__.py similarity index 99% rename from python/sdist/amici/sbml_import.py rename to python/sdist/amici/importers/sbml/__init__.py index aa74016248..913608f920 100644 --- a/python/sdist/amici/sbml_import.py +++ b/python/sdist/amici/importers/sbml/__init__.py @@ -27,12 +27,13 @@ from sympy.matrices.dense import MutableDenseMatrix import amici - -from . import get_model_dir, has_clibs -from .constants import SymbolId -from .de_model import DEModel -from .de_model_components import Expression, symbol_to_type -from .import_utils import ( +from amici import get_model_dir, has_clibs +from amici.constants import SymbolId +from amici.de_model import DEModel +from amici.de_model_components import Expression, symbol_to_type +from amici.importers.sbml.splines import AbstractSpline +from amici.importers.sbml.utils import SBMLException +from amici.importers.utils import ( RESERVED_SYMBOLS, MeasurementChannel, _check_unsupported_functions, @@ -55,10 +56,8 @@ symbol_with_assumptions, toposort_symbols, ) -from .logging import get_logger, log_execution_time, set_log_level -from .sbml_utils import SBMLException -from .splines import AbstractSpline -from .sympy_utils import smart_is_zero_matrix, smart_multiply +from amici.logging import get_logger, log_execution_time, set_log_level +from amici.sympy_utils import smart_is_zero_matrix, smart_multiply SymbolicFormula = dict[sp.Symbol, sp.Expr] @@ -321,7 +320,7 @@ def sbml2amici( :param observation_model: The different measurement channels that make up the observation - model, see :class:`amici.import_utils.MeasurementChannel`. + model, see :class:`amici.importers.utils.MeasurementChannel`. If ``None``, default observables will be added (for all state variables of the model and all species, compartments, and assignment rule targets) and normally distributed @@ -398,7 +397,7 @@ def sbml2amici( output_dir = output_dir or get_model_dir(model_name) - from .exporters.sundials.de_export import ( + from amici.exporters.sundials.de_export import ( DEExporter, ) @@ -423,7 +422,7 @@ def sbml2amici( ) exporter.compile_model() - from . import import_model_module + from amici import import_model_module return import_model_module( module_name=model_name, module_path=output_dir @@ -464,7 +463,7 @@ def sbml2jax( :param observation_model: The different measurement channels that make up the observation - model, see :class:`amici.import_utils.MeasurementChannel`. + model, see :class:`amici.importers.utils.MeasurementChannel`. Only time-resolved observables are supported here. If ``None``, default observables will be added (for all state variables of the model and all species, compartments, @@ -2953,7 +2952,7 @@ def _transform_dxdt_to_concentration( an assignment or rate rule. :param species_id: - The identifier of the species (generated in "sbml_import.py"). + The identifier of the species (generated in "__init__.py"). :param dxdt: The element-wise product of the row in the stoichiometric diff --git a/python/sdist/amici/conserved_quantities_demartino.py b/python/sdist/amici/importers/sbml/conserved_quantities_demartino.py similarity index 99% rename from python/sdist/amici/conserved_quantities_demartino.py rename to python/sdist/amici/importers/sbml/conserved_quantities_demartino.py index cf651241d1..d549755221 100644 --- a/python/sdist/amici/conserved_quantities_demartino.py +++ b/python/sdist/amici/importers/sbml/conserved_quantities_demartino.py @@ -4,7 +4,7 @@ import sys from collections.abc import MutableSequence, Sequence -from .logging import get_logger +from amici.logging import get_logger logger = get_logger(__name__, logging.ERROR) diff --git a/python/sdist/amici/conserved_quantities_rref.py b/python/sdist/amici/importers/sbml/conserved_quantities_rref.py similarity index 100% rename from python/sdist/amici/conserved_quantities_rref.py rename to python/sdist/amici/importers/sbml/conserved_quantities_rref.py diff --git a/python/sdist/amici/splines.py b/python/sdist/amici/importers/sbml/splines.py similarity index 99% rename from python/sdist/amici/splines.py rename to python/sdist/amici/importers/sbml/splines.py index 297be494fb..8b7a88df35 100644 --- a/python/sdist/amici/splines.py +++ b/python/sdist/amici/importers/sbml/splines.py @@ -17,7 +17,7 @@ Any, ) - from . import sbml_import + from amici.importers import sbml BClike = None | str | tuple[None | str, None | str] @@ -35,15 +35,16 @@ import sympy as sp from sympy.core.parameters import evaluate -from .constants import SymbolId -from .import_utils import ( +from amici.constants import SymbolId +from amici.logging import get_logger + +from ..utils import ( amici_time_symbol, annotation_namespace, sbml_time_symbol, symbol_with_assumptions, ) -from .logging import get_logger -from .sbml_utils import ( +from .utils import ( SbmlAnnotationError, add_assignment_rule, add_parameter, @@ -557,7 +558,7 @@ def method(self) -> str: """Spline method.""" raise NotImplementedError() - def check_if_valid(self, importer: sbml_import.SbmlImporter) -> None: + def check_if_valid(self, importer: sbml.SbmlImporter) -> None: """ Check if the spline described by this object can be correctly be implemented by AMICI. E.g., check whether the formulas @@ -1351,7 +1352,7 @@ def _from_annotation( return kwargs - def parameters(self, importer: sbml_import.SbmlImporter) -> set[sp.Symbol]: + def parameters(self, importer: sbml.SbmlImporter) -> set[sp.Symbol]: """Returns the SBML parameters used by this spline""" return self._parameters().intersection( set(importer.symbols[SymbolId.PARAMETER].keys()) @@ -1363,9 +1364,7 @@ def _parameters(self) -> set[sp.Symbol]: parameters.update(y.free_symbols) return parameters - def ode_model_symbol( - self, importer: sbml_import.SbmlImporter - ) -> sp.Function: + def ode_model_symbol(self, importer: sbml.SbmlImporter) -> sp.Function: """ Returns the `sympy` object to be used by :py:class:`amici.de_model.DEModel`. @@ -1658,7 +1657,7 @@ def method(self) -> str: def derivatives_by_fd(self) -> bool: return self._derivatives_by_fd - def check_if_valid(self, importer: sbml_import.SbmlImporter) -> None: + def check_if_valid(self, importer: sbml.SbmlImporter) -> None: """ Check if the spline described by this object can be correctly be implemented by AMICI. E.g., check whether the formulas diff --git a/python/sdist/amici/sbml_utils.py b/python/sdist/amici/importers/sbml/utils.py similarity index 99% rename from python/sdist/amici/sbml_utils.py rename to python/sdist/amici/importers/sbml/utils.py index 92ade098ce..0b933938ca 100644 --- a/python/sdist/amici/sbml_utils.py +++ b/python/sdist/amici/importers/sbml/utils.py @@ -19,7 +19,7 @@ from sympy.core.parameters import evaluate from sympy.printing.mathml import MathMLContentPrinter -from .import_utils import ( +from amici.importers.utils import ( SBMLException, amici_time_symbol, sbml_time_symbol, diff --git a/python/sdist/amici/import_utils.py b/python/sdist/amici/importers/utils.py similarity index 99% rename from python/sdist/amici/import_utils.py rename to python/sdist/amici/importers/utils.py index d6c19bfcaa..67a160ff70 100644 --- a/python/sdist/amici/import_utils.py +++ b/python/sdist/amici/importers/utils.py @@ -129,7 +129,7 @@ def __init__( Noise distribution associated with the observable. This is usually a string identifier (e.g., 'normal', 'log-normal'; see - :func:`amici.import_utils.noise_distribution_to_cost_function`). + :func:`amici.importers.utils.noise_distribution_to_cost_function`). If ``None``, a normal distribution is assumed. Alternatively, a callable can be passed to account for a diff --git a/python/sdist/amici/jax/ode_export.py b/python/sdist/amici/jax/ode_export.py index 5c27cc22a0..ebf0d164b7 100644 --- a/python/sdist/amici/jax/ode_export.py +++ b/python/sdist/amici/jax/ode_export.py @@ -5,8 +5,8 @@ differential equation model and generate executable jax simulation code. The user generally won't have to directly call any function from this module as this will be done by -:py:func:`amici.pysb_import.pysb2jax`, -:py:func:`amici.sbml_import.SbmlImporter.` and +:py:func:`amici.importers.pysb.pysb2jax`, +:py:func:`amici.importers.sbml.SbmlImporter.` and :py:func:`amici.petab_import.import_model`. """ diff --git a/python/sdist/amici/petab/import_helpers.py b/python/sdist/amici/petab/import_helpers.py index 5e2f770f21..5726cbf49f 100644 --- a/python/sdist/amici/petab/import_helpers.py +++ b/python/sdist/amici/petab/import_helpers.py @@ -24,7 +24,7 @@ from sympy.abc import _clash import amici -from amici.import_utils import MeasurementChannel +from amici.importers.utils import MeasurementChannel logger = logging.getLogger(__name__) diff --git a/python/sdist/amici/petab/parameter_mapping.py b/python/sdist/amici/petab/parameter_mapping.py index aa3d57f108..41b1d72dd9 100644 --- a/python/sdist/amici/petab/parameter_mapping.py +++ b/python/sdist/amici/petab/parameter_mapping.py @@ -40,7 +40,7 @@ from sympy.abc import _clash import amici -from amici.sbml_import import get_species_initial +from amici.importers.sbml import get_species_initial from .. import AmiciModel from . import PREEQ_INDICATOR_ID diff --git a/python/sdist/amici/petab/petab_import.py b/python/sdist/amici/petab/petab_import.py index 28d1b02033..83d40ab654 100644 --- a/python/sdist/amici/petab/petab_import.py +++ b/python/sdist/amici/petab/petab_import.py @@ -79,8 +79,8 @@ def import_petab_problem( :param kwargs: Additional keyword arguments to be passed to - :meth:`amici.sbml_import.SbmlImporter.sbml2amici` or - :func:`amici.pysb_import.pysb2amici`, depending on the model type. + :meth:`amici.importers.sbml.SbmlImporter.sbml2amici` or + :func:`amici.importers.pysb.pysb2amici`, depending on the model type. :return: The imported model (if ``jax=False``) or JAX problem (if ``jax=True``). diff --git a/python/sdist/amici/petab/petab_importer.py b/python/sdist/amici/petab/petab_importer.py index d8207c15e1..044b12f445 100644 --- a/python/sdist/amici/petab/petab_importer.py +++ b/python/sdist/amici/petab/petab_importer.py @@ -36,9 +36,9 @@ import amici -from .. import MeasurementChannel, SensitivityOrder, get_model_dir +from .. import SensitivityOrder, get_model_dir from ..de_model import DEModel -from ..import_utils import amici_time_symbol +from ..importers.utils import MeasurementChannel, amici_time_symbol from ..logging import get_logger from .sbml_import import _add_global_parameter from .simulations import EDATAS, LLH, RDATAS, RES, S2LLH, SLLH, SRES @@ -453,7 +453,7 @@ def _do_import_pysb( logger.info(f"Number of fixed parameters: {len(fixed_parameters)}") logger.debug(f"Fixed parameters are {fixed_parameters}") - from amici.pysb_import import pysb2amici, pysb2jax + from amici.importers.pysb import pysb2amici, pysb2jax # Create Python module from PySB model if self._jax: diff --git a/python/sdist/amici/petab/pysb_import.py b/python/sdist/amici/petab/pysb_import.py index 806198439b..e4e4bcc8e4 100644 --- a/python/sdist/amici/petab/pysb_import.py +++ b/python/sdist/amici/petab/pysb_import.py @@ -222,7 +222,7 @@ def import_model_pysb( :param kwargs: Additional keyword arguments to be passed to - :func:`amici.pysb_import.pysb2amici`. + :func:`amici.importers.pysb.pysb2amici`. """ set_log_level(logger, verbose) @@ -291,7 +291,7 @@ def import_model_pysb( ] if jax: - from amici.pysb_import import pysb2jax + from amici.importers.pysb import pysb2jax pysb2jax( model=pysb_model, @@ -304,7 +304,7 @@ def import_model_pysb( ) return else: - from amici.pysb_import import pysb2amici + from amici.importers.pysb import pysb2amici pysb2amici( model=pysb_model, diff --git a/python/sdist/amici/petab/sbml_import.py b/python/sdist/amici/petab/sbml_import.py index 26936de986..1c85a25eda 100644 --- a/python/sdist/amici/petab/sbml_import.py +++ b/python/sdist/amici/petab/sbml_import.py @@ -282,10 +282,10 @@ def import_model_sbml( :param kwargs: Additional keyword arguments to be passed to - :meth:`amici.sbml_import.SbmlImporter.sbml2amici`. + :meth:`amici.importers.sbml.SbmlImporter.sbml2amici`. :return: - The created :class:`amici.sbml_import.SbmlImporter` instance. + The created :class:`amici.importers.sbml.SbmlImporter` instance. """ from petab.v1.models.sbml_model import SbmlModel diff --git a/python/sdist/amici/testing/models.py b/python/sdist/amici/testing/models.py index b418ce0a7a..b80aa79e73 100644 --- a/python/sdist/amici/testing/models.py +++ b/python/sdist/amici/testing/models.py @@ -8,11 +8,11 @@ import sympy as sp from amici import AmiciModel, MeasurementChannel, SbmlImporter -from amici.sbml_utils import amici_time_symbol -from amici.splines import CubicHermiteSpline +from amici.importers.sbml.splines import CubicHermiteSpline +from amici.importers.utils import amici_time_symbol from .. import Model, import_model_module -from ..antimony_import import antimony2amici, antimony2sbml +from ..importers.antimony import antimony2amici, antimony2sbml model_dirac_ant = r""" p1 = 1; diff --git a/python/tests/conftest.py b/python/tests/conftest.py index 3e32bd42ee..731b1ec1d2 100644 --- a/python/tests/conftest.py +++ b/python/tests/conftest.py @@ -58,7 +58,7 @@ def sbml_example_presimulation_module(): def pysb_example_presimulation_module(): """PySB example_presimulation model module fixture""" pysb = pytest.importorskip("pysb") - from amici.pysb_import import pysb2amici + from amici.importers.pysb import pysb2amici constant_parameters = ["DRUG_0", "KIN_0"] diff --git a/python/tests/splines_utils.py b/python/tests/splines_utils.py index 6b5cf19f54..f29c61743f 100644 --- a/python/tests/splines_utils.py +++ b/python/tests/splines_utils.py @@ -18,9 +18,12 @@ import petab.v1 as petab import sympy as sp from amici.gradient_check import _check_results -from amici.petab.petab_import import import_petab_problem -from amici.petab.simulations import EDATAS, LLH, RDATAS, SLLH, simulate_petab -from amici.sbml_utils import ( +from amici.importers.sbml.splines import ( + AbstractSpline, + CubicHermiteSpline, + UniformGrid, +) +from amici.importers.sbml.utils import ( add_compartment, add_inflow, add_parameter, @@ -29,7 +32,8 @@ amici_time_symbol, create_sbml_model, ) -from amici.splines import AbstractSpline, CubicHermiteSpline, UniformGrid +from amici.petab.petab_import import import_petab_problem +from amici.petab.simulations import EDATAS, LLH, RDATAS, SLLH, simulate_petab from amici.testing import TemporaryDirectoryWinSafe as TemporaryDirectory from petab.v1.models.sbml_model import SbmlModel diff --git a/python/tests/test_antimony_import.py b/python/tests/test_antimony_import.py index ab4156c897..fbe95f1cb5 100644 --- a/python/tests/test_antimony_import.py +++ b/python/tests/test_antimony_import.py @@ -1,6 +1,6 @@ import amici import numpy as np -from amici.antimony_import import antimony2amici +from amici.importers.antimony import antimony2amici from amici.testing import skip_on_valgrind diff --git a/python/tests/test_bngl.py b/python/tests/test_bngl.py index c1eec8feea..0fe78a40f0 100644 --- a/python/tests/test_bngl.py +++ b/python/tests/test_bngl.py @@ -7,7 +7,7 @@ from contextlib import suppress -from amici.bngl_import import bngl2amici +from amici.importers.bngl import bngl2amici from amici.testing import TemporaryDirectoryWinSafe, skip_on_valgrind from pysb.importers.bngl import model_from_bngl from pysb.simulator import ScipyOdeSimulator @@ -40,12 +40,13 @@ @skip_on_valgrind @pytest.mark.parametrize("example", tests) def test_compare_to_pysb_simulation(example): - import amici.import_utils + import amici + from amici.importers.utils import RESERVED_SYMBOLS, MeasurementChannel # allow "NULL" as model symbol # (used in CaOscillate_Func and Repressilator examples) with suppress(ValueError): - amici.import_utils.RESERVED_SYMBOLS.remove("NULL") + RESERVED_SYMBOLS.remove("NULL") atol = 1e-8 rtol = 1e-8 @@ -78,7 +79,7 @@ def test_compare_to_pysb_simulation(example): kwargs = { "compute_conservation_laws": cl, "observation_model": list( - map(amici.MeasurementChannel, pysb_model.observables.keys()) + map(MeasurementChannel, pysb_model.observables.keys()) ), } diff --git a/python/tests/test_compare_conservation_laws_sbml.py b/python/tests/test_compare_conservation_laws_sbml.py index 7c5a128970..481e7a0343 100644 --- a/python/tests/test_compare_conservation_laws_sbml.py +++ b/python/tests/test_compare_conservation_laws_sbml.py @@ -45,7 +45,7 @@ def edata_fixture(): @pytest.fixture(scope="session") def models(): - from amici.antimony_import import antimony2sbml + from amici.importers.antimony import antimony2sbml ant_model = """model *model_constant_species() const compartment compartment_ = 1; diff --git a/python/tests/test_conserved_quantities_demartino.py b/python/tests/test_conserved_quantities_demartino.py index 64fc7861e4..9aaa829162 100644 --- a/python/tests/test_conserved_quantities_demartino.py +++ b/python/tests/test_conserved_quantities_demartino.py @@ -6,12 +6,14 @@ import numpy as np import pytest import sympy as sp -from amici.conserved_quantities_demartino import ( +from amici.importers.sbml.conserved_quantities_demartino import ( _fill, _kernel, compute_moiety_conservation_laws, ) -from amici.conserved_quantities_demartino import _output as output +from amici.importers.sbml.conserved_quantities_demartino import ( + _output as output, +) from amici.logging import get_logger, log_execution_time from amici.testing import skip_on_valgrind diff --git a/python/tests/test_conserved_quantities_rref.py b/python/tests/test_conserved_quantities_rref.py index 7a131ebee3..6b3d6c682f 100644 --- a/python/tests/test_conserved_quantities_rref.py +++ b/python/tests/test_conserved_quantities_rref.py @@ -1,7 +1,11 @@ import numpy as np import pytest import sympy as sp -from amici.conserved_quantities_rref import nullspace_by_rref, pivots, rref +from amici.importers.sbml.conserved_quantities_rref import ( + nullspace_by_rref, + pivots, + rref, +) from amici.testing import skip_on_valgrind diff --git a/python/tests/test_de_model.py b/python/tests/test_de_model.py index 5ffe245d27..4a569af03b 100644 --- a/python/tests/test_de_model.py +++ b/python/tests/test_de_model.py @@ -1,6 +1,6 @@ import sympy as sp from amici.de_model_components import Event -from amici.import_utils import amici_time_symbol +from amici.importers.utils import amici_time_symbol from amici.testing import skip_on_valgrind diff --git a/python/tests/test_events.py b/python/tests/test_events.py index dff8e9ae81..e78a7a93a4 100644 --- a/python/tests/test_events.py +++ b/python/tests/test_events.py @@ -13,8 +13,8 @@ SensitivityOrder, import_model_module, ) -from amici.antimony_import import antimony2amici from amici.gradient_check import check_derivatives +from amici.importers.antimony import antimony2amici from amici.testing import skip_on_valgrind from amici.testing.models import create_amici_model, create_sbml_model from numpy.testing import assert_allclose @@ -877,7 +877,6 @@ def test_multiple_event_assignment_with_compartment(tempdir): @skip_on_valgrind def test_event_priorities(tempdir): """Test SBML event priorities.""" - from amici.antimony_import import antimony2amici model_name = "test_event_priorities" antimony2amici( @@ -974,7 +973,6 @@ def test_event_priorities(tempdir): def test_random_event_ordering(tempdir): """For simultaneously executed events, the order of execution must be random.""" - from amici.antimony_import import antimony2amici model_name = "test_event_prio_rnd" antimony2amici( @@ -1040,7 +1038,6 @@ def test_random_event_ordering(tempdir): def test_event_uses_values_from_trigger_time(tempdir): """For simultaneously executed events, check that values from trigger times are used to compute the state update.""" - from amici.antimony_import import antimony2amici model_name = "test_event_vals_trig_time" antimony2amici( @@ -1124,7 +1121,6 @@ def test_event_uses_values_from_trigger_time(tempdir): @skip_on_valgrind def test_posteq_events_are_handled(tempdir): """Test that events are handled during post-equilibration.""" - from amici.antimony_import import antimony2amici model_name = "test_posteq_events_are_handled" antimony2amici( @@ -1195,7 +1191,6 @@ def test_preeq_presim_preserve_heaviside_state(tempdir): I.e., the trigger.initialValue is only applied in the very beginning. """ - from amici.antimony_import import antimony2amici model_name = "test_preeq_presim_preserve_heaviside_state" antimony2amici( @@ -1273,7 +1268,6 @@ def test_preeq_presim_preserve_heaviside_state(tempdir): def test_gh2926(tempdir): """Two simultaneous events. Event `E1` changes the root function for the piecewise-switch from 0 to <0.""" - from amici.antimony_import import antimony2amici model_name = "test_gh2926" antimony2amici( diff --git a/python/tests/test_jax.py b/python/tests/test_jax.py index f2354b9bff..1f335db4c8 100644 --- a/python/tests/test_jax.py +++ b/python/tests/test_jax.py @@ -12,9 +12,9 @@ import numpy as np import optimistix from amici import MeasurementChannel as MC +from amici.importers.pysb import pysb2amici, pysb2jax from amici.jax import JAXProblem, ReturnValue, run_simulations from amici.petab.petab_import import import_petab_problem -from amici.pysb_import import pysb2amici, pysb2jax from amici.testing import TemporaryDirectoryWinSafe, skip_on_valgrind from beartype import beartype from numpy.testing import assert_allclose @@ -322,10 +322,10 @@ def test_serialisation(lotka_volterra): # noqa: F811 def test_time_dependent_discontinuity(tmp_path): """Models with time dependent discontinuities are handled.""" - from amici.antimony_import import antimony2sbml + from amici.importers.antimony import antimony2sbml + from amici.importers.sbml import SbmlImporter from amici.jax._simulation import solve from amici.jax.petab import DEFAULT_CONTROLLER_SETTINGS - from amici.sbml_import import SbmlImporter ant_model = """ model time_disc @@ -375,10 +375,10 @@ def test_time_dependent_discontinuity(tmp_path): def test_time_dependent_discontinuity_equilibration(tmp_path): """Time dependent discontinuities are handled during equilibration.""" - from amici.antimony_import import antimony2sbml + from amici.importers.antimony import antimony2sbml + from amici.importers.sbml import SbmlImporter from amici.jax._simulation import eq from amici.jax.petab import DEFAULT_CONTROLLER_SETTINGS - from amici.sbml_import import SbmlImporter ant_model = """ model time_disc_eq diff --git a/python/tests/test_misc.py b/python/tests/test_misc.py index 272a2daccc..9ca0b82bfa 100644 --- a/python/tests/test_misc.py +++ b/python/tests/test_misc.py @@ -7,7 +7,7 @@ import amici import pytest import sympy as sp -from amici.import_utils import smart_subs_dict +from amici.importers.utils import smart_subs_dict from amici.testing import skip_on_valgrind diff --git a/python/tests/test_ode_export.py b/python/tests/test_ode_export.py index 86e064e9c4..b11425a98f 100644 --- a/python/tests/test_ode_export.py +++ b/python/tests/test_ode_export.py @@ -2,7 +2,7 @@ import sympy as sp from amici.exporters.sundials.cxxcodeprinter import csc_matrix -from amici.import_utils import symbol_with_assumptions +from amici.importers.utils import symbol_with_assumptions from amici.testing import skip_on_valgrind diff --git a/python/tests/test_petab_import.py b/python/tests/test_petab_import.py index 6687c35b81..a79f1a5406 100644 --- a/python/tests/test_petab_import.py +++ b/python/tests/test_petab_import.py @@ -51,7 +51,7 @@ def get_fixed_parameters_model(): p8' = 1 p9 := p8 """ - from amici.antimony_import import antimony2sbml + from amici.importers.antimony import antimony2sbml sbml_str = antimony2sbml(ant_model) sbml_doc = libsbml.SBMLReader().readSBMLFromString(sbml_str) diff --git a/python/tests/test_preequilibration.py b/python/tests/test_preequilibration.py index 3c326a49c3..22074dcf0d 100644 --- a/python/tests/test_preequilibration.py +++ b/python/tests/test_preequilibration.py @@ -647,7 +647,7 @@ def test_get_model_for_preeq(preeq_fixture): @skip_on_valgrind def test_partial_eq(): """Check that partial equilibration is possible.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici ant_str = """ model test_partial_eq @@ -705,7 +705,7 @@ def test_partial_eq(): def test_preequilibration_t0(tempdir): """Test that preequilibration uses the correct initial time.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici ant_str = """ model test_preequilibration_t0 @@ -752,7 +752,7 @@ def test_preequilibration_t0(tempdir): def test_preequilibration_events(tempdir): """Test that events are handled correctly during preequilibration.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici ant_str = """ model test_preequilibration_events diff --git a/python/tests/test_pysb.py b/python/tests/test_pysb.py index fef1d4110e..7f2823d26f 100644 --- a/python/tests/test_pysb.py +++ b/python/tests/test_pysb.py @@ -19,8 +19,8 @@ from amici import ParameterScaling, parameter_scaling_from_int_vector from amici.de_model_components import Event from amici.gradient_check import check_derivatives -from amici.import_utils import amici_time_symbol -from amici.pysb_import import pysb2amici +from amici.importers.pysb import pysb2amici +from amici.importers.utils import amici_time_symbol from amici.testing import TemporaryDirectoryWinSafe, skip_on_valgrind from numpy.testing import assert_allclose from pysb.simulator import ScipyOdeSimulator diff --git a/python/tests/test_sbml_import.py b/python/tests/test_sbml_import.py index 4a51df9024..136f5ef7a6 100644 --- a/python/tests/test_sbml_import.py +++ b/python/tests/test_sbml_import.py @@ -1,4 +1,4 @@ -"""Tests related to amici.sbml_import""" +"""Tests related to amici.importers.sbml""" import os import re @@ -13,13 +13,13 @@ import sympy as sp from amici import import_model_module from amici.gradient_check import check_derivatives -from amici.import_utils import ( +from amici.importers.sbml import SbmlImporter, SymbolId +from amici.importers.utils import ( MeasurementChannel as MC, ) -from amici.import_utils import ( +from amici.importers.utils import ( symbol_with_assumptions, ) -from amici.sbml_import import SbmlImporter, SymbolId from amici.testing import TemporaryDirectoryWinSafe as TemporaryDirectory from amici.testing import skip_on_valgrind from conftest import MODEL_STEADYSTATE_SCALED_XML @@ -50,7 +50,7 @@ def simple_sbml_model(): def test_event_trigger_to_root_function(): """Test that root functions for event triggers are generated correctly.""" - from amici.sbml_import import _parse_event_trigger as to_trig + from amici.importers.sbml import _parse_event_trigger as to_trig a, b = sp.symbols("a b") @@ -284,7 +284,7 @@ def test_presimulation(sbml_example_presimulation_module): def test_presimulation_events(tempdir): """Test that events are handled during presimulation.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici model_name = "test_presim_events" antimony2amici( @@ -374,7 +374,7 @@ def test_presimulation_events_and_sensitivities(tempdir): """Test that presimulation with adjoint sensitivities works and test that events are handled during presimulation.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici model_name = "test_presim_events2" model = antimony2amici( @@ -875,7 +875,7 @@ def test_hardcode_parameters(): def test_constraints(tempdir): """Test non-negativity constraint handling.""" from amici import Constraint - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici ant_model = """ model test_non_negative_species @@ -925,7 +925,7 @@ def test_constraints(tempdir): def test_import_same_model_name(tempdir): """Test for error when loading a model with the same extension name as an already loaded model.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici # create three versions of a toy model with different parameter values # to detect which model was loaded @@ -1036,7 +1036,7 @@ def test_regression_2642(tempdir): @skip_on_valgrind def test_regression_2700(tempdir): """Check comparison operators.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici model_name = "regression_2700" antimony2amici( @@ -1064,7 +1064,7 @@ def test_heaviside_init_values_and_bool_to_float_conversion(tempdir): FIXME: Test that Heavisides for Boolean / piecewise functions use a correct initial value. https://github.com/AMICI-dev/AMICI/issues/2724 """ - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici model_name = "test_bool2float" antimony2amici( @@ -1100,7 +1100,7 @@ def test_heaviside_init_values_and_bool_to_float_conversion(tempdir): def test_t0(tempdir): """Test that a custom initial time for the simulation is applied correctly during species initialization.""" - from amici.antimony_import import antimony2amici + from amici.importers.antimony import antimony2amici model_name = "test_t0" antimony2amici( @@ -1126,7 +1126,7 @@ def test_t0(tempdir): @skip_on_valgrind def test_contains_periodic_subexpression(): """Test that periodic subexpressions are detected.""" - from amici.import_utils import contains_periodic_subexpression as cps + from amici.importers.utils import contains_periodic_subexpression as cps t = sp.Symbol("t") @@ -1141,8 +1141,9 @@ def test_contains_periodic_subexpression(): def test_time_dependent_initial_assignment(compute_conservation_laws: bool): """Check that dynamic expressions for initial assignments are only evaluated at t=t0.""" - from amici.antimony_import import antimony2sbml - from amici.import_utils import amici_time_symbol + from amici.importers.antimony import antimony2sbml + from amici.importers.sbml import splines + from amici.importers.utils import amici_time_symbol ant_model = """ x1' = 1 @@ -1160,7 +1161,7 @@ def test_time_dependent_initial_assignment(compute_conservation_laws: bool): sbml_document = sbml_reader.readSBMLFromString(sbml_str) sbml_model = sbml_document.getModel() - spline = amici.splines.CubicHermiteSpline( + spline = splines.CubicHermiteSpline( sbml_id="spline1", nodes=[0, 1, 2], values_at_nodes=[3, 4, 5], diff --git a/python/tests/test_sbml_import_special_functions.py b/python/tests/test_sbml_import_special_functions.py index 8e9ff1412f..bf58be6f55 100644 --- a/python/tests/test_sbml_import_special_functions.py +++ b/python/tests/test_sbml_import_special_functions.py @@ -9,8 +9,8 @@ import pytest from amici import MeasurementChannel as MC from amici import SbmlImporter -from amici.antimony_import import antimony2amici from amici.gradient_check import check_derivatives +from amici.importers.antimony import antimony2amici from amici.testing import TemporaryDirectoryWinSafe, skip_on_valgrind from conftest import MODEL_STEADYSTATE_SCALED_XML from numpy.testing import ( diff --git a/python/tests/test_splines_python.py b/python/tests/test_splines_python.py index 539fb1dd4d..76fe4de4a7 100644 --- a/python/tests/test_splines_python.py +++ b/python/tests/test_splines_python.py @@ -7,17 +7,18 @@ import math -import amici import sympy as sp +from amici.importers.sbml.splines import CubicHermiteSpline, UniformGrid +from amici.importers.utils import amici_time_symbol from amici.testing import skip_on_valgrind @skip_on_valgrind def test_SplineUniform(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[0.0, 2.0, 0.5, 1.0], ) assert math.isclose(float(spline.evaluate(0.0)), 0.0) @@ -31,9 +32,9 @@ def test_SplineUniform(): @skip_on_valgrind def test_SplineNonUniform(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, + evaluate_at=amici_time_symbol, nodes=[0.0, 0.1, 0.5, 1.0], values_at_nodes=[0.0, 2.0, 0.5, 1.0], ) @@ -48,10 +49,10 @@ def test_SplineNonUniform(): @skip_on_valgrind def test_SplineExplicit(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=5), values_at_nodes=[0.0, 2.0, 0.5, 1.0, 0.75], derivatives_at_nodes=[1.0, 0.0, 0.1, -0.1, 0.0], ) @@ -68,10 +69,10 @@ def test_SplineExplicit(): @skip_on_valgrind def test_SplineZeroBC(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[0.0, 2.0, 0.5, 1.0], bc="zeroderivative", ) @@ -84,10 +85,10 @@ def test_SplineZeroBC(): @skip_on_valgrind def test_SplineLogarithmic(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=5), values_at_nodes=[0.2, 2.0, 0.5, 1.0, 0.75], logarithmic_parametrization=True, ) @@ -104,10 +105,10 @@ def test_SplineLogarithmic(): @skip_on_valgrind def test_SplineUniformConstantExtrapolation(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[0.0, 2.0, 0.5, 1.0], extrapolate="constant", ) @@ -126,10 +127,10 @@ def test_SplineUniformConstantExtrapolation(): @skip_on_valgrind def test_SplineUniformLinearExtrapolation(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[0.0, 2.0, 0.5, 1.0], extrapolate="linear", ) @@ -148,10 +149,10 @@ def test_SplineUniformLinearExtrapolation(): @skip_on_valgrind def test_SplineUniformPolynomialExtrapolation(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[0.0, 2.0, 0.5, 1.0], extrapolate="polynomial", ) @@ -170,10 +171,10 @@ def test_SplineUniformPolynomialExtrapolation(): @skip_on_valgrind def test_SplineUniformPeriodicExtrapolation(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[1.0, 2.0, 0.5, 1.0], extrapolate="periodic", ) @@ -192,9 +193,9 @@ def test_SplineUniformPeriodicExtrapolation(): @skip_on_valgrind def test_SplineNonUniformPeriodicExtrapolation(): - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, + evaluate_at=amici_time_symbol, nodes=[0.0, 0.1, 0.5, 1.0], values_at_nodes=[1.0, 2.0, 0.5, 1.0], extrapolate="periodic", @@ -229,10 +230,10 @@ def check_gradient(spline, t, params, params_values, expected, rel_tol=1e-9): def test_SplineUniformSensitivity(): params = (a, b, c) = sp.symbols("a b c") params_values = [0.5, 1.0, 2.5] - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[3 * a + b, c**2 - 3, 1, sp.log(b) + 3 * c - 6 * a], ) check_gradient(spline, 0.00, params, params_values, [3.0, 1.0, 0.0]) @@ -264,9 +265,9 @@ def test_SplineUniformSensitivity(): def test_SplineNonUniformSensitivity(): params = (a, b, c) = sp.symbols("a b c") params_values = [0.5, 1.0, 2.5] - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, + evaluate_at=amici_time_symbol, nodes=[0.0, 0.1, 0.5, 1.0], values_at_nodes=[3 * a + b, c**2 - 3, 1, sp.log(b) + 3 * c - 6 * a], ) @@ -292,10 +293,10 @@ def test_SplineNonUniformSensitivity(): def test_SplineExplicitSensitivity(): params = (a, b, c) = sp.symbols("a b c") params_values = [0.5, 1.0, 2.5] - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[3 * a + b, c**2 - 3, 1, sp.log(b) + 3 * c - 6 * a], derivatives_at_nodes=[ c**3 - 2, @@ -338,10 +339,10 @@ def test_SplineExplicitSensitivity(): def test_SplineLogarithmicSensitivity(): params = (a, b, c) = sp.symbols("a b c") params_values = [0.5, 1.0, 2.5] - spline = amici.splines.CubicHermiteSpline( + spline = CubicHermiteSpline( sbml_id="f", - evaluate_at=amici.sbml_utils.amici_time_symbol, - nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4), + evaluate_at=amici_time_symbol, + nodes=UniformGrid(0, 1, number_of_nodes=4), values_at_nodes=[3 * a + b, c**2 - 3, 1, sp.log(b) + 3 * c - 6 * a], logarithmic_parametrization=True, ) diff --git a/python/tests/test_splines_short.py b/python/tests/test_splines_short.py index 61851e09ed..7f7ea72e2c 100644 --- a/python/tests/test_splines_short.py +++ b/python/tests/test_splines_short.py @@ -7,7 +7,7 @@ import numpy as np import sympy as sp -from amici.splines import CubicHermiteSpline, UniformGrid +from amici.importers.sbml.splines import CubicHermiteSpline, UniformGrid from amici.testing import skip_on_valgrind from splines_utils import check_splines_full, example_spline_1 diff --git a/tests/sbml/testSBMLSuite.py b/tests/sbml/testSBMLSuite.py index bce52440a4..6ad10fcb6e 100755 --- a/tests/sbml/testSBMLSuite.py +++ b/tests/sbml/testSBMLSuite.py @@ -113,7 +113,7 @@ def test_sbml_testsuite_case(test_id, result_path, sbml_semantic_cases_dir): rtol, ) - except amici.sbml_import.SBMLException as err: + except amici.importers.sbml.SBMLException as err: pytest.skip(str(err)) finally: if model_dir: diff --git a/tests/sbml/testSBMLSuiteJax.py b/tests/sbml/testSBMLSuiteJax.py index 03ee853103..a604b9ac5f 100644 --- a/tests/sbml/testSBMLSuiteJax.py +++ b/tests/sbml/testSBMLSuiteJax.py @@ -170,7 +170,7 @@ def test_sbml_testsuite_case_jax( settings, rdata, results, wrapper, dummy, atol, rtol ) write_result_file(simulated, test_id, result_path_jax) - except amici.sbml_import.SBMLException as err: + except amici.importers.sbml.SBMLException as err: pytest.skip(str(err)) except NotImplementedError as err: if "The JAX backend does not support" in str(err):