Skip to content

Commit ce6897c

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

61 files changed

Lines changed: 512 additions & 382 deletions

Some content is hidden

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

.github/workflows/test_conda_install.yml

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

.gitignore

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

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

doc/conf.py

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

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

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

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

doc/python_modules.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ AMICI Python API
77
:toctree: generated
88

99
amici
10-
amici.amici
1110
amici.importers.utils
1211
amici.importers.sbml
1312
amici.importers.sbml.conserved_quantities_demartino
@@ -29,9 +28,8 @@ AMICI Python API
2928
amici.importers.petab.v1.simulator
3029
amici.jax
3130
amici.exporters.sundials.de_export
32-
amici.plotting
33-
amici.pandas
31+
amici.sim.sundials
32+
amici.sim.sundials.plotting
33+
amici.sim.sundials.gradient_check
3434
amici.logging
35-
amici.gradient_check
36-
amici.numpy
3735
amici.adapters.fiddy

python/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Build and install the AMICI Python package
2+
#
3+
# This file is not part of the AMICI Python package itself, but is included
4+
# in the main CMakeLists.txt to provide targets for building and installing
5+
# the AMICI Python package.
6+
17
if(DEFINED ENV{PYTHON_EXECUTABLE})
28
set(Python3_EXECUTABLE $ENV{PYTHON_EXECUTABLE})
39
endif()

python/sdist/MANIFEST.in

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
recursive-include amici/ThirdParty/SuiteSparse *
2-
recursive-include amici/ThirdParty/sundials *
3-
recursive-include amici/ThirdParty/gsl *.hpp
4-
recursive-include amici/cmake *
5-
recursive-include amici/include/amici *.h
6-
recursive-include amici/src *
7-
recursive-include amici/swig *
1+
recursive-include amici/_installation/ThirdParty/SuiteSparse *
2+
recursive-include amici/_installation/ThirdParty/sundials *
3+
recursive-include amici/_installation/ThirdParty/gsl *.hpp
4+
recursive-include amici/_installation/cmake *
5+
recursive-include amici/_installation/include/amici *.h
6+
recursive-include amici/_installation/src *
7+
recursive-include amici/_installation/swig *
88
recursive-include amici/exporters/sundials/templates *
99
include amici/*
1010
include version.txt
1111
include LICENSE.md
12-
exclude amici/*.so
13-
exclude amici/*.dll
12+
exclude amici/_installation/*.so
13+
exclude amici/_installation/*.dll
1414
prune **/build
1515
prune **/install
16-
prune amici/share
17-
prune amici/lib
18-
prune amici/ThirdParty/SuiteSparse/lib
19-
prune amici/ThirdParty/SuiteSparse/include
16+
prune amici/_installation/share
17+
prune amici/_installation/lib
18+
prune amici/_installation/ThirdParty/SuiteSparse/lib
19+
prune amici/_installation/ThirdParty/SuiteSparse/include
2020
prune __pycache__

python/sdist/amici/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/sdist/amici/ThirdParty

Lines changed: 0 additions & 1 deletion
This file was deleted.

python/sdist/amici/__init__.py

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -135,49 +135,15 @@ def get_model_dir(model_id: str | None = None, jax: bool = False) -> Path:
135135
amiciSrcPath = os.path.join(amici_path, "src")
136136
#: absolute root path of the amici module
137137
amiciModulePath = os.path.dirname(__file__)
138-
#: boolean indicating if this is the full package with swig interface or
139-
# the raw package without extension
140-
has_clibs: bool = any(
141-
os.path.isfile(os.path.join(amici_path, wrapper))
142-
for wrapper in ["amici.py", "amici_without_hdf5.py"]
143-
)
144-
#: boolean indicating if amici was compiled with hdf5 support
145-
hdf5_enabled: bool = False
138+
146139

147140
# Get version number from file
148-
with open(os.path.join(amici_path, "version.txt")) as f:
141+
with open(os.path.join(amici_path, "_installation", "version.txt")) as f:
149142
__version__ = f.read().strip()
150143

151144
__commit__ = _get_commit_hash()
152145

153-
# Import SWIG module and swig-dependent submodules if required and available
154146
if not _imported_from_setup():
155-
if has_clibs:
156-
# prevent segfaults under pytest
157-
# see also:
158-
# https://github.com/swig/swig/issues/2881
159-
# https://github.com/AMICI-dev/AMICI/issues/2565
160-
with warnings.catch_warnings():
161-
warnings.filterwarnings(
162-
"ignore",
163-
category=DeprecationWarning,
164-
message="builtin type .* has no __module__ attribute",
165-
)
166-
from . import amici
167-
168-
from .amici import *
169-
170-
# has to be done before importing readSolverSettingsFromHDF5
171-
# from .swig_wrappers
172-
hdf5_enabled = "readSolverSettingsFromHDF5" in dir()
173-
# These modules require the swig interface and other dependencies
174-
from .numpy import ExpDataView, ReturnDataView # noqa: F401
175-
from .pandas import *
176-
from .swig_wrappers import *
177-
178-
# These modules don't require the swig interface
179-
from typing import Protocol, runtime_checkable
180-
181147
from .importers.sbml import ( # noqa: F401
182148
SbmlImporter,
183149
assignment_rules_to_observables,
@@ -189,20 +155,6 @@ def get_model_dir(model_id: str | None = None, jax: bool = False) -> Path:
189155
except (ImportError, ModuleNotFoundError):
190156
JAXModel = object
191157

192-
@runtime_checkable
193-
class ModelModule(Protocol): # noqa: F811
194-
"""Type of AMICI-generated model modules.
195-
196-
To enable static type checking."""
197-
198-
def get_model(self) -> amici.Model:
199-
"""Create a model instance."""
200-
...
201-
202-
AmiciModel = amici.Model | amici.ModelPtr
203-
else:
204-
ModelModule = ModuleType
205-
206158

207159
class add_path:
208160
"""Context manager for temporarily changing PYTHONPATH.
@@ -262,6 +214,9 @@ def _module_from_path(module_name: str, module_path: Path | str) -> ModuleType:
262214
return module
263215

264216

217+
ModelModule = ModuleType
218+
219+
265220
def import_model_module(
266221
module_name: str, module_path: Path | str
267222
) -> ModelModule:

python/sdist/amici/__main__.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
import sys
44

5-
from . import (
6-
CpuTimer,
7-
__version__,
8-
compiled_with_openmp,
9-
has_clibs,
10-
hdf5_enabled,
11-
)
5+
from . import __version__
6+
7+
try:
8+
from .sim.sundials import (
9+
CpuTimer,
10+
compiled_with_openmp,
11+
has_clibs,
12+
hdf5_enabled,
13+
)
14+
except ImportError:
15+
has_clibs = False
1216

1317

1418
def print_info():
@@ -20,14 +24,14 @@ def print_info():
2024
if has_clibs:
2125
features.append("extensions")
2226

23-
if compiled_with_openmp():
24-
features.append("OpenMP")
27+
if compiled_with_openmp():
28+
features.append("OpenMP")
2529

26-
if hdf5_enabled:
27-
features.append("HDF5")
30+
if hdf5_enabled:
31+
features.append("HDF5")
2832

29-
if CpuTimer.uses_thread_clock:
30-
features.append("thread_clock")
33+
if CpuTimer.uses_thread_clock:
34+
features.append("thread_clock")
3135

3236
print(
3337
f"AMICI ({sys.platform}) version {__version__} ({','.join(features)})"

0 commit comments

Comments
 (0)