Skip to content

Support PEtab v2 condition changes of pysb.Parameters - #3583

Draft
dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:pysb_v2_parameter_targets
Draft

dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:pysb_v2_parameter_targets

Conversation

@dweindl

@dweindl dweindl commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Adds support for pysb.Parameters as PEtab v2 condition targets for PySB models, in the first period and in later periods, including parameters used in pysb.Initials. Based on #3582 (only the last commit is new).

Parameter targets are handled during the PySB → DEModel conversion, similar to how the SBML importer handles parameter targets of events:

  • parameters that are changed only in the first period become DEModel expressions (piecewise over the experiment indicators), so conservation laws keep working;
  • parameters that are changed in later periods become constant state variables and event assignment targets.

First-period target values must not refer to other condition targets, as required by the PEtab v2 specification. Previously, such references could produce invalid or order-dependent model code.

PEtab test suite: PySB cases 0002, 0005, 0009, 0010 and 0017 were previously skipped and now pass locally (simulations, and gradients compared against finite differences). 0012 (compartment) is still skipped. The test suite has no PySB cases with changes at t > 0; those are covered by test_pysb_condition_changes.

Closes #3068.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.99329% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.87%. Comparing base (0ed2e65) to head (3ef2b7d).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
...hon/sdist/amici/importers/petab/_petab_importer.py 97.02% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3583      +/-   ##
==========================================
+ Coverage   80.52%   80.87%   +0.34%     
==========================================
  Files         332      331       -1     
  Lines       23698    23932     +234     
  Branches     1690     1674      -16     
==========================================
+ Hits        19082    19354     +272     
+ Misses       4610     4567      -43     
- Partials        6       11       +5     
Flag Coverage Δ
cpp 75.13% <23.97%> (+0.01%) ⬆️
cpp_python 34.87% <23.97%> (+0.08%) ⬆️
petab 49.27% <98.99%> (+2.29%) ⬆️
petab_sciml 16.47% <6.84%> (+0.01%) ⬆️
petab_sciml_benchmarks 15.09% <6.84%> (+0.01%) ⬆️
python 72.81% <23.97%> (+0.03%) ⬆️
sbmlsuite 49.72% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
python/sdist/amici/_symbolic/de_model.py 94.03% <100.00%> (+0.01%) ⬆️
...ython/sdist/amici/_symbolic/de_model_components.py 96.77% <100.00%> (+0.10%) ⬆️
python/sdist/amici/importers/pysb/__init__.py 95.22% <100.00%> (+0.50%) ⬆️
python/tests/petab_/test_petab_v2.py 100.00% <100.00%> (ø)
...hon/sdist/amici/importers/petab/_petab_importer.py 92.90% <97.02%> (+4.17%) ⬆️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

dweindl and others added 3 commits November 16, 2026 14:10
* Event assignments to entities that are not (solver) state variables
  now raise a `ValueError` in `DEModel.generate_basic_variables`, i.e.,
  before code generation, and in `Event.get_state_update`. Such
  assignments were silently dropped.
* Add `Event.assignment_targets` and `Event.check_assignment_targets`.
* `ode_model_from_pysb_importer` disables conservation laws with a
  warning for models with events, as the SBML importer does, instead of
  raising.

Preparation for PEtab v2 condition changes in later periods for PySB
models (AMICI-dev#3068).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Condition changes in any period but the first one, including the main
period after pre-equilibration, failed with a `TypeError`. They are now
implemented as events:

* Species targets are resolved via pattern matching against the generated
  reaction network. This also removes the requirement of a `pysb.Initial`
  with an identical pattern for first-period changes, and fixes changes of
  the same species in multiple experiments.
* Target values of later-period changes may depend on the current model
  state, model parameters, `time`, and parameter-table parameters.
* No events are created for periods without changes.
* `time` is allowed in first-period target values.

Invalid targets now raise:

* `pysb.Expression`s and observables are algebraic entities and not valid
  condition targets. Their changes were silently ignored.
* Compartments and parameters that compartment sizes depend on (also via
  `pysb.Expression`s) are not supported, as BioNetGen evaluates
  compartment sizes during network generation.
* Changes of `pysb.Parameter`s remain unsupported for now.
* Entities named `t` (reserved by AMICI) in changes after the first
  period, as event assignments don't use the renames of the PySB import.

The JAX backend raises `NotImplementedError` for changes after the first
period, as `pysb2jax` doesn't support events.

Relates to AMICI-dev#3068.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PEtab v2 allows `pysb.Parameter`s as condition targets. Since they can't
be changed to arbitrary expressions in the PySB model, targeted
parameters are handled during the PySB-to-`DEModel` conversion
(`_parameter_targets` of `pysb2amici`/`pysb2jax`), similar to the SBML
importer:

* Parameters that are only changed in the first period become `DEModel`
  expressions (piecewise in the experiment indicators). Conservation laws
  remain available.
* Parameters that are changed in later periods become constant state
  variables that are assigned by the period-start events. Changing a
  parameter used in a `pysb.Initial` after the first period does not
  affect the species.

First-period target values must not refer to other condition targets,
as required by the PEtab v2 specification. Such references resulted in
invalid or order-dependent model code.

Closes AMICI-dev#3068.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the pysb_v2_parameter_targets branch from 653831b to 3ef2b7d Compare November 16, 2026 13:11
@dweindl dweindl self-assigned this Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PEtab PEtab-import related PySB PySB import related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend support for PEtab v2 / PySB

1 participant