Skip to content

Commit df9523d

Browse files
authored
separate out importer code (#3023)
* move files & refactor * fixups * conditional import guards * fixup actions * remove unified import interface * fixups * fixup * fixup * fixup * Update ExampleSplinesSwameye2003.ipynb * fix doc
1 parent b8c0fef commit df9523d

Some content is hidden

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

54 files changed

+240
-231
lines changed

.github/workflows/test_petab_sciml.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ name: PEtab
22
on:
33
push:
44
branches:
5-
- develop
65
- main
76
- 'release*'
87
pull_request:
98
branches:
109
- main
11-
- develop
12-
- jax_sciml
1310
merge_group:
1411
workflow_dispatch:
1512

.github/workflows/test_sbml_semantic_test_suite.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ on:
1010
- python/sdist/amici/exporters/sundials/de_export.py
1111
- python/sdist/amici/de_model_components.py
1212
- python/sdist/amici/de_model.py
13-
- python/sdist/amici/sbml_import.py
14-
- python/sdist/amici/import_utils.py
13+
- python/sdist/amici/importers/sbml/**
14+
- python/sdist/amici/importers/utils.py
1515
- scripts/run-SBMLTestsuite.sh
1616
- tests/sbml/testSBMLSuite.py
1717
- tests/sbml/conftest.py

codecov.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ flags:
4141
carryforward: false
4242
sbmlsuite:
4343
paths:
44-
- "python/amici/sbml_import.py"
45-
- "python/amici/de_export.py"
44+
- python/amici/importers/sbml/**
45+
- python/amici/exporters/sundials/de_export.py
4646
carryforward: true

doc/examples/example_large_models/example_performance_optimization.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@
7272
"\n",
7373
"#### Parameters as constants\n",
7474
"\n",
75-
"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",
75+
"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",
7676
"The PEtab import will automatically pass all parameters with `petab.ESTIMATE==False` as `constant_parameters` arguments.\n",
7777
"\n",
7878
"See also the following section for the case that no sensitivities are required at all.\n",
7979
"\n",
8080
"\n",
8181
"#### Not generating sensitivity code\n",
8282
"\n",
83-
"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",
83+
"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",
8484
"\n",
8585
"Example:\n",
8686
"```bash\n",
@@ -239,7 +239,7 @@
239239
"\n",
240240
"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",
241241
"\n",
242-
"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",
242+
"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",
243243
"\n",
244244
"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)."
245245
]

doc/examples/example_splines/ExampleSplines.ipynb

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,13 @@
223223
"outputs": [],
224224
"source": [
225225
"# Create a spline object\n",
226-
"spline = amici.splines.CubicHermiteSpline(\n",
226+
"from amici.importers.sbml.splines import CubicHermiteSpline, UniformGrid\n",
227+
"from amici.importers.utils import amici_time_symbol\n",
228+
"\n",
229+
"spline = CubicHermiteSpline(\n",
227230
" sbml_id=\"f\",\n",
228-
" evaluate_at=amici.sbml_utils.amici_time_symbol, # the spline function is evaluated at the current time point\n",
229-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
231+
" evaluate_at=amici_time_symbol, # the spline function is evaluated at the current time point\n",
232+
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
230233
" values_at_nodes=[1, -1, 2],\n",
231234
")"
232235
]
@@ -485,10 +488,10 @@
485488
},
486489
"outputs": [],
487490
"source": [
488-
"spline = amici.splines.CubicHermiteSpline(\n",
491+
"spline = CubicHermiteSpline(\n",
489492
" sbml_id=\"f\",\n",
490-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
491-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
493+
" evaluate_at=amici_time_symbol,\n",
494+
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
492495
" values_at_nodes=sp.symbols(\"f0:3\"),\n",
493496
")"
494497
]
@@ -619,10 +622,10 @@
619622
"outputs": [],
620623
"source": [
621624
"# A simple spline for which finite differencing would give a different result\n",
622-
"spline = amici.splines.CubicHermiteSpline(\n",
625+
"spline = CubicHermiteSpline(\n",
623626
" sbml_id=\"f\",\n",
624-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
625-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
627+
" evaluate_at=amici_time_symbol,\n",
628+
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
626629
" values_at_nodes=[1.0, -1.0, 1.0],\n",
627630
" derivatives_at_nodes=[10.0, -10.0, -10.0],\n",
628631
")"
@@ -717,10 +720,10 @@
717720
},
718721
"outputs": [],
719722
"source": [
720-
"spline = amici.splines.CubicHermiteSpline(\n",
723+
"spline = CubicHermiteSpline(\n",
721724
" sbml_id=\"f\",\n",
722-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
723-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
725+
" evaluate_at=amici_time_symbol,\n",
726+
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
724727
" values_at_nodes=[-2, 1, -1],\n",
725728
" extrapolate=(\n",
726729
" None,\n",
@@ -812,10 +815,10 @@
812815
},
813816
"outputs": [],
814817
"source": [
815-
"spline = amici.splines.CubicHermiteSpline(\n",
818+
"spline = CubicHermiteSpline(\n",
816819
" sbml_id=\"f\",\n",
817-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
818-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=3),\n",
820+
" evaluate_at=amici_time_symbol,\n",
821+
" nodes=UniformGrid(0, 1, number_of_nodes=3),\n",
819822
" values_at_nodes=[-2, 1, -2], # first and last node must coincide\n",
820823
" extrapolate=\"periodic\",\n",
821824
")"
@@ -904,10 +907,10 @@
904907
},
905908
"outputs": [],
906909
"source": [
907-
"spline = amici.splines.CubicHermiteSpline(\n",
910+
"spline = CubicHermiteSpline(\n",
908911
" sbml_id=\"f\",\n",
909-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
910-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4),\n",
912+
" evaluate_at=amici_time_symbol,\n",
913+
" nodes=UniformGrid(0, 1, number_of_nodes=4),\n",
911914
" values_at_nodes=[-1, 2, 4, 2],\n",
912915
" bc=\"zeroderivative\",\n",
913916
")"
@@ -963,10 +966,10 @@
963966
},
964967
"outputs": [],
965968
"source": [
966-
"spline = amici.splines.CubicHermiteSpline(\n",
969+
"spline = CubicHermiteSpline(\n",
967970
" sbml_id=\"f\",\n",
968-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
969-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=4),\n",
971+
" evaluate_at=amici_time_symbol,\n",
972+
" nodes=UniformGrid(0, 1, number_of_nodes=4),\n",
970973
" values_at_nodes=[-1, 2, 4, 2],\n",
971974
" bc=\"natural\",\n",
972975
")"
@@ -1029,10 +1032,10 @@
10291032
},
10301033
"outputs": [],
10311034
"source": [
1032-
"spline = amici.splines.CubicHermiteSpline(\n",
1035+
"spline = CubicHermiteSpline(\n",
10331036
" sbml_id=\"f\",\n",
1034-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
1035-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5),\n",
1037+
" evaluate_at=amici_time_symbol,\n",
1038+
" nodes=UniformGrid(0, 1, number_of_nodes=5),\n",
10361039
" values_at_nodes=[2, 0.05, 0.1, 2, 1],\n",
10371040
")"
10381041
]
@@ -1068,10 +1071,10 @@
10681071
},
10691072
"outputs": [],
10701073
"source": [
1071-
"spline = amici.splines.CubicHermiteSpline(\n",
1074+
"spline = CubicHermiteSpline(\n",
10721075
" sbml_id=\"f\",\n",
1073-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
1074-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=5),\n",
1076+
" evaluate_at=amici_time_symbol,\n",
1077+
" nodes=UniformGrid(0, 1, number_of_nodes=5),\n",
10751078
" values_at_nodes=[2, 0.05, 0.1, 2, 1],\n",
10761079
" logarithmic_parametrization=True,\n",
10771080
")"
@@ -1191,10 +1194,10 @@
11911194
"df = None\n",
11921195
"for n in num_nodes + amici_only_nodes:\n",
11931196
" # Create model\n",
1194-
" spline = amici.splines.CubicHermiteSpline(\n",
1197+
" spline = CubicHermiteSpline(\n",
11951198
" sbml_id=\"f\",\n",
1196-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
1197-
" nodes=amici.splines.UniformGrid(0, 1, number_of_nodes=n),\n",
1199+
" evaluate_at=amici_time_symbol,\n",
1200+
" nodes=UniformGrid(0, 1, number_of_nodes=n),\n",
11981201
" values_at_nodes=np.random.rand(n),\n",
11991202
" )\n",
12001203
" sbml_doc = libsbml.SBMLReader().readSBML(\"example_splines.xml\")\n",

doc/examples/example_splines_swameye/ExampleSplinesSwameye2003.ipynb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
"import os\n",
5454
"\n",
5555
"import amici\n",
56+
"import amici.importers.sbml.splines as splines\n",
5657
"import libsbml\n",
5758
"import numpy as np\n",
5859
"import pandas as pd\n",
5960
"import petab\n",
6061
"import pypesto.petab\n",
6162
"import sympy as sp\n",
63+
"from amici.importers.utils import amici_time_symbol\n",
6264
"from matplotlib import pyplot as plt"
6365
]
6466
},
@@ -176,9 +178,9 @@
176178
"values_at_nodes = [\n",
177179
" sp.Symbol(f\"pEpoR_t{str(t).replace('.', '_dot_')}\") for t in nodes\n",
178180
"] # new parameter symbols for spline values\n",
179-
"spline = amici.splines.CubicHermiteSpline(\n",
181+
"spline = splines.CubicHermiteSpline(\n",
180182
" sbml_id=\"pEpoR\", # matches name of species in SBML model\n",
181-
" evaluate_at=amici.sbml_utils.amici_time_symbol, # the spline is evaluated at the current time\n",
183+
" evaluate_at=amici_time_symbol, # the spline is evaluated at the current time\n",
182184
" nodes=nodes,\n",
183185
" values_at_nodes=values_at_nodes, # values at the nodes (in linear scale)\n",
184186
" extrapolate=(None, \"constant\"), # because steady state is reached\n",
@@ -782,9 +784,9 @@
782784
"values_at_nodes = [\n",
783785
" sp.Symbol(f\"pEpoR_t{str(t).replace('.', '_dot_')}\") for t in nodes\n",
784786
"]\n",
785-
"spline = amici.splines.CubicHermiteSpline(\n",
787+
"spline = splines.CubicHermiteSpline(\n",
786788
" sbml_id=\"pEpoR\",\n",
787-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
789+
" evaluate_at=amici_time_symbol,\n",
788790
" nodes=nodes,\n",
789791
" values_at_nodes=values_at_nodes,\n",
790792
" extrapolate=(None, \"constant\"),\n",
@@ -1492,9 +1494,9 @@
14921494
" sp.Symbol(f\"derivative_pEpoR_t{str(t).replace('.', '_dot_')}\")\n",
14931495
" for t in nodes[:-1]\n",
14941496
"]\n",
1495-
"spline = amici.splines.CubicHermiteSpline(\n",
1497+
"spline = splines.CubicHermiteSpline(\n",
14961498
" sbml_id=\"pEpoR\",\n",
1497-
" evaluate_at=amici.sbml_utils.amici_time_symbol,\n",
1499+
" evaluate_at=amici_time_symbol,\n",
14981500
" nodes=nodes,\n",
14991501
" values_at_nodes=values_at_nodes,\n",
15001502
" derivatives_at_nodes=derivatives_at_nodes\n",
@@ -1591,7 +1593,9 @@
15911593
"source": [
15921594
"# Derivative parameters must be added separately\n",
15931595
"for p in derivatives_at_nodes:\n",
1594-
" amici.sbml_utils.add_parameter(sbml_model, p, value=0.0, constant=True)"
1596+
" amici.importers.sbml.utils.add_parameter(\n",
1597+
" sbml_model, p, value=0.0, constant=True\n",
1598+
" )"
15951599
]
15961600
},
15971601
{

doc/examples/example_steady_states/ExampleEquilibrationLogic.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@
109109
"from amici import (\n",
110110
" MeasurementChannel as MC,\n",
111111
")\n",
112-
"from amici.antimony_import import antimony2sbml\n",
112+
"from amici.importers.antimony import antimony2sbml\n",
113113
"from amici.plotting import (\n",
114114
" plot_observable_trajectories,\n",
115115
" plot_state_trajectories,\n",

doc/python_interface.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SBML import
1919
-----------
2020

2121
AMICI can import :term:`SBML` models via the
22-
:py:func:`amici.sbml_import.SbmlImporter` class.
22+
:py:func:`amici.importers.sbml.SbmlImporter` class.
2323

2424
.. _amici_python_sbml_support:
2525

@@ -113,13 +113,13 @@ PySB import
113113
-----------
114114

115115
AMICI can import :term:`PySB` models via
116-
:py:func:`amici.pysb_import.pysb2amici`.
116+
:py:func:`amici.importers.pysb.pysb2amici`.
117117

118118
BNGL import
119119
-----------
120120

121121
AMICI can import :term:`BNGL` models via
122-
:py:func:`amici.bngl_import.bngl2amici`.
122+
:py:func:`amici.importers.bngl.bngl2amici`.
123123

124124
PEtab import
125125
------------
@@ -162,7 +162,7 @@ An example using Antimony to specify the Lotka-Volterra equations is shown below
162162
end
163163
"""
164164
module_name = "test_antimony_example_lv"
165-
from amici.antimony_import import antimony2amici
165+
from amici.importers.antimony import antimony2amici
166166
antimony2amici(
167167
ant_model,
168168
model_name=module_name,

doc/python_modules.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ AMICI Python API
88

99
amici
1010
amici.amici
11-
amici.sbml_import
12-
amici.pysb_import
13-
amici.bngl_import
11+
amici.importers.utils
12+
amici.importers.sbml
13+
amici.importers.sbml.conserved_quantities_demartino
14+
amici.importers.sbml.conserved_quantities_rref
15+
amici.importers.sbml.utils
16+
amici.importers.sbml.splines
17+
amici.importers.pysb
18+
amici.importers.bngl
19+
amici.importers.antimony
1420
amici.petab
1521
amici.petab.conditions
1622
amici.petab.import_helpers
@@ -21,7 +27,6 @@ AMICI Python API
2127
amici.petab.sbml_import
2228
amici.petab.simulations
2329
amici.petab.simulator
24-
amici.import_utils
2530
amici.jax
2631
amici.exporters.sundials.de_export
2732
amici.de_model
@@ -30,9 +35,5 @@ AMICI Python API
3035
amici.pandas
3136
amici.logging
3237
amici.gradient_check
33-
amici.conserved_quantities_demartino
34-
amici.conserved_quantities_rref
3538
amici.numpy
36-
amici.sbml_utils
37-
amici.splines
3839
amici.adapters.fiddy

python/benchmark/benchmark_pysb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616
import pandas as pd
1717
import pysb
18-
from amici.pysb_import import pysb2amici
18+
from amici.importers.pysb import pysb2amici
1919
from pysb.simulator import ScipyOdeSimulator
2020

2121
sys.path.insert(0, os.path.join("..", "tests"))

0 commit comments

Comments
 (0)