Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/test_petab_sciml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ name: PEtab
on:
push:
branches:
- develop
- main
- 'release*'
pull_request:
branches:
- main
- develop
- jax_sciml
merge_group:
workflow_dispatch:

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_sbml_semantic_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ on:
- python/sdist/amici/exporters/sundials/de_export.py
- python/sdist/amici/de_model_components.py
- python/sdist/amici/de_model.py
- python/sdist/amici/sbml_import.py
- python/sdist/amici/import_utils.py
- python/sdist/amici/importers/sbml/**
- python/sdist/amici/importers/utils.py
- scripts/run-SBMLTestsuite.sh
- tests/sbml/testSBMLSuite.py
- tests/sbml/conftest.py
Expand Down
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ flags:
carryforward: false
sbmlsuite:
paths:
- "python/amici/sbml_import.py"
- "python/amici/de_export.py"
- python/amici/importers/sbml/**
- python/amici/exporters/sundials/de_export.py
carryforward: true
2 changes: 1 addition & 1 deletion doc/python_interface.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SBML import
-----------

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

.. _amici_python_sbml_support:

Expand Down
17 changes: 9 additions & 8 deletions doc/python_modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ AMICI Python API

amici
amici.amici
amici.sbml_import
amici.pysb_import
amici.bngl_import
amici.importers.utils
amici.importers.sbml
amici.importers.sbml.conserved_quantities_demartino
amici.importers.sbml.conserved_quantities_rref
amici.importers.sbml.sbml_utils
amici.importers.sbml.splines
amici.importers.pysb
amici.importers.bngl
amici.importers.antimony
amici.petab
amici.petab.conditions
amici.petab.import_helpers
Expand All @@ -21,7 +27,6 @@ AMICI Python API
amici.petab.sbml_import
amici.petab.simulations
amici.petab.simulator
amici.import_utils
amici.jax
amici.exporters.sundials.de_export
amici.de_model
Expand All @@ -30,9 +35,5 @@ AMICI Python API
amici.pandas
amici.logging
amici.gradient_check
amici.conserved_quantities_demartino
amici.conserved_quantities_rref
amici.numpy
amici.sbml_utils
amici.splines
amici.adapters.fiddy
5 changes: 2 additions & 3 deletions python/sdist/amici/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import importlib.util
import os
import re
import sys
import warnings
from collections.abc import Callable
from pathlib import Path
Expand Down Expand Up @@ -178,11 +177,11 @@ def get_model_dir(model_id: str | None = None, jax: bool = False) -> Path:
# These modules don't require the swig interface
from typing import Protocol, runtime_checkable

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

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

Choose a reason for hiding this comment

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

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

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

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

logger = get_logger(__name__, logging.ERROR)

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

from .constants import SymbolId
from .import_utils import (
from .importers.utils import (
RESERVED_SYMBOLS,
ObservableTransformation,
amici_time_symbol,
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/exporters/sundials/cxxcodeprinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, amici.exporters should not import anything from amici.importers, only from the symbolic middle layer.



class AmiciCxxCodePrinter(CXX11CodePrinter):
Expand Down
2 changes: 1 addition & 1 deletion python/sdist/amici/exporters/sundials/de_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
81 changes: 81 additions & 0 deletions python/sdist/amici/importers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"""Unified model import interface for AMICI.
This subpackage aggregates functionality for importing models from various
formats into AMICI.
Re-exported symbols (imported conditionally where dependencies are optional):
- SBML: `SbmlImporter` (requires `libsbml` and related deps)
- PySB: `pysb2amici`, `pysb2jax`, `ode_model_from_pysb_importer` (requires `pysb`)
- Antimony:`antimony2sbml`, `antimony2amici` (requires `antimony` Python package)
- Utils: `MeasurementChannel`, noise helpers, `RESERVED_SYMBOLS`,
`ObservableTransformation`
"""

from __future__ import annotations

# Utils are internal and safe to import unconditionally
from .utils import (
RESERVED_SYMBOLS,
MeasurementChannel,
ObservableTransformation,
noise_distribution_to_cost_function,
noise_distribution_to_observable_transformation,
)

__all__: list[str] = [
# Utils
"MeasurementChannel",
"noise_distribution_to_cost_function",
"noise_distribution_to_observable_transformation",
"RESERVED_SYMBOLS",
"ObservableTransformation",
]

# SBML importer (optional)
try:
from .sbml import (
SbmlImporter, # noqa: E402,F401
sbml2jax, # noqa: E402,F401
smbl2amici, # noqa: E402,F401
)

__all__ += [
"sbml2amici",
"sbml2jax",
"SbmlImporter",
]
except Exception:
# Leave unavailable if optional dependency is missing
pass

# PySB importer (optional)
try:
from .pysb import (
ode_model_from_pysb_importer, # noqa: E402,F401
pysb2amici, # noqa: E402,F401
pysb2jax, # noqa: E402,F401
)

__all__ += [
"pysb2amici",
"pysb2jax",
"ode_model_from_pysb_importer",
]
except Exception:
pass

# Antimony importer (optional)
try:
from .antimony import antimony2amici, antimony2sbml # noqa: E402,F401

__all__ += ["antimony2sbml", "antimony2amici"]
except Exception:
pass

# BNGL importer (optional)
try:
from .bngl import bngl2amici # noqa: E402,F401

__all__.append("bngl2amici")
except Exception:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -37,7 +36,7 @@
Parameter,
SigmaY,
)
from .import_utils import (
from amici.importers.utils import (
MeasurementChannel,
_default_simplify,
_get_str_symbol_identifiers,
Expand All @@ -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]
Expand Down Expand Up @@ -267,7 +266,7 @@ def pysb2amici(
events=_events,
)

from .exporters.sundials.de_export import (
from amici.exporters.sundials.de_export import (
DEExporter,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -2947,7 +2946,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading
Loading