Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
895e83d
event assignments jax - sbml cases 348 - 404
BSnelling Dec 1, 2025
32a7f45
fix up sbml test cases - not implemented priority, update t_eps, fix …
BSnelling Dec 5, 2025
d7b9054
initialValue False not implemented
BSnelling Dec 5, 2025
aebcbc0
try fix other test cases
BSnelling Dec 5, 2025
f29a550
params only in explicit triggers - and matrix only in JAX again
BSnelling Dec 5, 2025
8c1641a
oops committed breakpoint
BSnelling Dec 5, 2025
16d7a69
looking for initialValue test cases
BSnelling Dec 8, 2025
b550a7a
do not update h pre-solve
BSnelling Dec 9, 2025
b653355
handle_t0_event
BSnelling Dec 9, 2025
df8aca0
reinstate time skip (hack diffrax bug?)
BSnelling Dec 9, 2025
c48d9fc
Update python/sdist/amici/jax/_simulation.py
BSnelling Dec 10, 2025
7e95ada
Revert "Update python/sdist/amici/jax/_simulation.py"
BSnelling Dec 10, 2025
f093a2e
rm clip controller
BSnelling Dec 10, 2025
c0d4a84
handle t0 event near zero
BSnelling Dec 10, 2025
e582cb3
skip non-time dependent event assignment cases
BSnelling Dec 10, 2025
bbe8406
first pass petabv2 - updating JAXProblem init
BSnelling Dec 15, 2025
f314804
petabv2 test cases up to 15-ish
BSnelling Dec 19, 2025
272aeeb
petab v2 test cases up to 27-ish
BSnelling Jan 6, 2026
7b8fded
rework petabv2 jax test cases with ExperimentsToSbmlEvents and no v1 …
BSnelling Jan 9, 2026
d286063
fix some rebase issues
BSnelling Jan 9, 2026
6dd921b
add test skip for petab v1
BSnelling Jan 9, 2026
1789f37
remaining petab v2 test cases
BSnelling Jan 21, 2026
315ad7d
update workflows - deactivate petab_sciml wf for now
BSnelling Jan 22, 2026
3d8c169
update tests to skip on petab v2 type error
BSnelling Jan 22, 2026
a3d5312
skip some more tests and reinstate more specific implicit triggers check
BSnelling Jan 22, 2026
9d107b3
fixup benchmark skipping check
BSnelling Jan 22, 2026
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
20 changes: 10 additions & 10 deletions .github/workflows/test_petab_sciml.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: PEtab SciML
on:
push:
branches:
- main
- 'release*'
pull_request:
branches:
- main
merge_group:
workflow_dispatch:
# on:
# push:
# branches:
# - main
# - 'release*'
# pull_request:
# branches:
# - main
# merge_group:
# workflow_dispatch:

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_petab_test_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ jobs:
git clone https://github.com/PEtab-dev/petab_test_suite \
&& source ./venv/bin/activate \
&& cd petab_test_suite \
&& git checkout c12b9dc4e4c5585b1b83a1d6e89fd22447c46d03 \
&& git checkout 9542847fb99bcbdffc236e2ef45ba90580a210fa \
&& pip3 install -e .

# TODO: once there is a PEtab v2 benchmark collection
Expand All @@ -186,7 +186,7 @@ jobs:
run: |
source ./venv/bin/activate \
&& python3 -m pip uninstall -y petab \
&& python3 -m pip install git+https://github.com/petab-dev/libpetab-python.git@8dc6c1c4b801fba5acc35fcd25308a659d01050e \
&& python3 -m pip install git+https://github.com/petab-dev/libpetab-python.git@d57d9fed8d8d5f8592e76d0b15676e05397c3b4b \
&& python3 -m pip install git+https://github.com/pysb/pysb@master \
&& python3 -m pip install sympy>=1.12.1

Expand Down
1,033 changes: 912 additions & 121 deletions doc/examples/example_jax_petab/ExampleJaxPEtab.ipynb

Large diffs are not rendered by default.

43 changes: 42 additions & 1 deletion python/sdist/amici/_symbolic/de_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,14 @@ def _generate_symbol(self, name: str) -> None:
]
)
return
elif name == "allh":
self._syms[name] = sp.Matrix(
[
sym
for sym, _ in zip(self.sym("h"), self._events)
]
)
return
elif name == "deltax":
length = sp.Matrix(self.eq(name)).shape[0]
else:
Expand Down Expand Up @@ -2676,14 +2684,47 @@ def has_priority_events(self) -> bool:
"""
return any(event.get_priority() is not None for event in self._events)

def has_simultaneous_events(self) -> bool:
"""
Checks whether the model has events that can be triggered simultaneously
by checking for duplicate event triggering expressions that depend on time.

:return:
boolean indicating if simultaneous events are present
"""
t_exprs = []
for event in self._events:
if "negative" in event._name:
continue
trigger = event.get_val()
t_args = self._args_containing_t(trigger)
t_exprs.append(t_args)

t_exprs = list(itertools.chain(*t_exprs))

return len(t_exprs) != len(set(t_exprs))


def _args_containing_t(self, expr):
t = sp.Symbol("t", real=True)
hits = []
for node in sp.preorder_traversal(expr):
if isinstance(node, sp.Min):
hits.extend([arg for arg in node.args if arg.has(t) and arg != t])
elif node.is_Atom:
continue
elif node.has(t):
hits.extend([node])
return list(set(hits))

def has_implicit_event_assignments(self) -> bool:
"""
Checks whether the model has event assignments with implicit triggers

:return:
boolean indicating if event assignments with implicit triggers are present
"""
return any(event.updates_state and not event.has_explicit_trigger_times({}) for event in self._events)
return any(event.updates_state and event._implicit_symbols() for event in self._events)

def toposort_expressions(
self, reorder: bool = True
Expand Down
9 changes: 9 additions & 0 deletions python/sdist/amici/_symbolic/de_model_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,15 @@ def get_trigger_times(self) -> set[sp.Expr]:
time points at which the event triggers.
"""
return set(self._t_root)

def _implicit_symbols(self):
symbols = [str(s) for s in list(self.get_val().free_symbols)]
implicit_symbols = []
for s in symbols:
if (s.startswith("_petab_") and "indicator" in s) or s == "t":
continue
implicit_symbols.append(s)
return len(implicit_symbols) > 0

@property
def uses_values_from_trigger_time(self) -> bool:
Expand Down
15 changes: 11 additions & 4 deletions python/sdist/amici/importers/petab/_petab_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from amici._symbolic import DEModel, Event
from amici.importers.utils import MeasurementChannel, amici_time_symbol
from amici.logging import get_logger
from amici.jax.petab import JAXProblem

from .v1.sbml_import import _add_global_parameter

Expand Down Expand Up @@ -151,10 +152,6 @@ def __init__(
"PEtab v2 importer currently only supports SBML and PySB "
f"models. Got {self.petab_problem.model.type_id!r}."
)
if jax:
raise NotImplementedError(
"PEtab v2 importer currently does not support JAX. "
)

if self._debug:
print("PetabImpoter.__init__: petab_problem:")
Expand Down Expand Up @@ -577,6 +574,11 @@ def import_module(self, force_import: bool = False) -> amici.ModelModule:
else:
self._do_import_pysb()

if self._jax:
return amici.import_model_module(
Path(self.output_dir).stem, Path(self.output_dir).parent
)

return amici.import_model_module(
self._module_name,
self.output_dir,
Expand All @@ -601,6 +603,11 @@ def create_simulator(
"""
from amici.sim.sundials.petab import ExperimentManager, PetabSimulator

if self._jax:
model_module = self.import_module(force_import=force_import)
model = model_module.Model()
return JAXProblem(model, self.petab_problem)

model = self.import_module(force_import=force_import).get_model()
em = ExperimentManager(model=model, petab_problem=self.petab_problem)
return PetabSimulator(em=em)
Expand Down
10 changes: 6 additions & 4 deletions python/sdist/amici/importers/petab/v1/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ def create_parameter_mapping(
converter_config = (
libsbml.SBMLLocalParameterConverter().getDefaultProperties()
)
petab_problem.sbml_document.convert(converter_config)
petab_problem.model.sbml_document.convert(converter_config)
else:
logger.debug(
"No petab_problem.sbml_document is set. Cannot "
Expand Down Expand Up @@ -474,9 +474,11 @@ def create_parameter_mapping_for_condition(
# ExpData.x0, but in the case of pre-equilibration this would not allow for
# resetting initial states.

if states_in_condition_table := get_states_in_condition_table(
states_in_condition_table = get_states_in_condition_table(
petab_problem, condition
):
)

if states_in_condition_table:
# set indicator fixed parameter for preeq
# (we expect here, that this parameter was added during import and
# that it was not added by the user with a different meaning...)
Expand Down Expand Up @@ -525,7 +527,7 @@ def create_parameter_mapping_for_condition(
value,
fill_fixed_parameters=fill_fixed_parameters,
)
# set dummy value as above
# set dummy value as above
if condition_map_preeq:
condition_map_preeq[init_par_id] = 0.0
condition_scale_map_preeq[init_par_id] = LIN
Expand Down
7 changes: 6 additions & 1 deletion python/sdist/amici/importers/petab/v1/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import re
from _collections import OrderedDict
from itertools import chain
import pandas as pd
from pathlib import Path

import libsbml
import petab.v1 as petab
import petab.v2 as petabv2
import sympy as sp
from petab.v1.models import MODEL_TYPE_SBML
from sympy.abc import _clash
Expand Down Expand Up @@ -304,7 +306,10 @@ def import_model_sbml(

if validate:
logger.info("Validating PEtab problem ...")
petab.lint_problem(petab_problem)
if isinstance(petab_problem, petabv2.Problem):
petabv2.lint_problem(petab_problem)
else:
petab.lint_problem(petab_problem)

# Model name from SBML ID or filename
if model_name is None:
Expand Down
Loading
Loading