Skip to content

Fix adjoint sensitivities for events that are both state-triggered and state-updating - #3258

Draft
dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:fix-asa-event-trigger-time-sensitivity
Draft

Fix adjoint sensitivities for events that are both state-triggered and state-updating#3258
dweindl wants to merge 3 commits into
AMICI-dev:mainfrom
dweindl:fix-asa-event-trigger-time-sensitivity

Conversation

@dweindl

@dweindl dweindl commented Sep 8, 2026

Copy link
Copy Markdown
Member

deltaxB/deltaqB embed dtaudx/dtaudp (trigger-time-sensitivity terms), but these were evaluated at whatever state the generated function happens to be called with -- in practice the post-event state. That's the wrong side of the discontinuity: the equivalent forward-mode quantity (stau) is deliberately computed pre-event. Fix: eliminate w via its own algebraic definition, then substitute x -> x_old.

Verified via direct FSA-vs-ASA comparison (bypassing FD entirely) on a 72-case corpus of affected SBML semantic test suite models: divergence for the affected parameter previously ranged from ~0.001% up to ~1% relative (worst observed: FSA=0.16456 vs ASA=0.16303); after the fix, it drops to ~1e-13-3e-11 relative (floating-point noise) with zero regressions.

Corpus (SBML semantic test suite case IDs), for future reference/test cases:

  • Explicit SBML events (state-triggered and state-updating): 00026, 00041, 00074, 00619, 00620, 00621, 00634, 00635, 00636, 00646, 00647, 00648, 00652, 00653, 00654, 00679, 00680, 00681, 00689, 00700, 00707, 00723, 00736, 00743, 00744, 00745, 00746, 00747, 00749, 00750, 00751, 00752, 00753, 00754, 00755, 00756, 00789, 00790, 00791, 00845, 00846, 00847, 00883, 00884, 00945, 00946, 00947, 00948, 01045, 01046, 01047, 01071, 01072, 01073, 01094, 01106
  • Piecewise reaction-rate laws (no explicit , but AMICI hits the same code path via an internal root): 00191, 00192, 00193, 00194, 00198, 00199, 00200, 00201, 00270, 00272, 00273, 00274, 00276, 00277, 00278, 00279

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

Fixes #3257. Maybe #18 too, to be confirmed.
Tests will be implemented as part of #3251 and #3253.

@codecov

codecov Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.53%. Comparing base (3d695c5) to head (8a7efac).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3258      +/-   ##
==========================================
+ Coverage   78.52%   78.53%   +0.01%     
==========================================
  Files         318      318              
  Lines       22199    22205       +6     
  Branches     1490     1490              
==========================================
+ Hits        17432    17439       +7     
+ Misses       4759     4758       -1     
  Partials        8        8              
Flag Coverage Δ
cpp 72.31% <100.00%> (+0.01%) ⬆️
cpp_python 35.27% <100.00%> (+0.02%) ⬆️
petab 48.46% <100.00%> (+0.02%) ⬆️
petab_sciml 16.45% <16.66%> (+<0.01%) ⬆️
petab_sciml_benchmarks 15.00% <16.66%> (+<0.01%) ⬆️
python 70.75% <100.00%> (+<0.01%) ⬆️
sbmlsuite-jax 31.72% <16.66%> (-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 91.87% <100.00%> (+0.05%) ⬆️
python/sdist/amici/adapters/fiddy.py 88.18% <ø> (-2.37%) ⬇️

... and 3 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 dweindl self-assigned this Sep 8, 2026
@dweindl
dweindl force-pushed the fix-asa-event-trigger-time-sensitivity branch from c4a55d8 to 8cddbcd Compare September 9, 2026 16:06
dweindl and others added 3 commits September 9, 2026 22:23
Add fiddy-based finite differences sensitivity checks to the SBML semantic
test suite.

Splits the single forward-only sensitivity check into three independent
nodes per case (forward/adjoint/consistency), generalizes the retry
scaffold, fixes cross-test-node model-parameter contamination, and skips known-affected cases (events/piecewise,
zero-state models) with adjoint/forward distinguished where relevant. Disables
fiddy's function-call caching by default (pure overhead here, source of
a flaky CI failure).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…d state-updating

deltaxB/deltaqB embed dtaudx/dtaudp (trigger-time-sensitivity terms), but
these were evaluated at whatever state the generated function happens to
be called with -- in practice the post-event state. That's the wrong side
of the discontinuity: the equivalent forward-mode quantity (stau) is
deliberately computed pre-event. Fix: eliminate w via its own algebraic
definition, then substitute x -> x_old.

Verified via direct FSA-vs-ASA comparison (bypassing FD entirely) on a
72-case corpus of affected SBML semantic test suite models: divergence
for the affected parameter previously ranged from ~0.001% up to ~1%
relative (worst observed: FSA=0.16456 vs ASA=0.16303); after the fix, it
drops to ~1e-13-3e-11 relative (floating-point noise) with zero
regressions.

Corpus (SBML semantic test suite case IDs), for future reference/test
cases:

- Explicit SBML events (state-triggered and state-updating): 00026,
  00041, 00074, 00619, 00620, 00621, 00634, 00635, 00636, 00646, 00647,
  00648, 00652, 00653, 00654, 00679, 00680, 00681, 00689, 00700, 00707,
  00723, 00736, 00743, 00744, 00745, 00746, 00747, 00749, 00750, 00751,
  00752, 00753, 00754, 00755, 00756, 00789, 00790, 00791, 00845, 00846,
  00847, 00883, 00884, 00945, 00946, 00947, 00948, 01045, 01046, 01047,
  01071, 01072, 01073, 01094, 01106
- Piecewise reaction-rate laws (no explicit <event>, but AMICI hits the
  same code path via an internal root): 00191, 00192, 00193, 00194,
  00198, 00199, 00200, 00201, 00270, 00272, 00273, 00274, 00276, 00277,
  00278, 00279

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@dweindl
dweindl force-pushed the fix-asa-event-trigger-time-sensitivity branch from 583959f to 8a7efac Compare September 9, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adjoint sensitivities wrong for events that are both state-triggered and state-updating

1 participant