Repository navigation
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3565 +/- ##
==========================================
+ Coverage 80.51% 80.68% +0.17%
==========================================
Files 331 331
Lines 23688 24449 +761
Branches 1691 1681 -10
==========================================
+ Hits 19072 19727 +655
- Misses 4610 4716 +106
Partials 6 6
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
dweindl
force-pushed
the
explicit_roots_at_t0
branch
from
November 15, 2026 21:35
1420223 to
85496eb
Compare
dweindl
marked this pull request as ready for review
November 16, 2026 09:15
dweindl
marked this pull request as draft
November 16, 2026 09:53
A `piecewise` or trigger condition on time whose trigger time is the initial time, e.g., `piecewise(2, time <= 0, 0)` simulated from `t0 = 0` or `time <= 1` from `t0 = 1`, kept its value at `t0` for the whole simulation. Trigger times are only processed when they are reached after the current time, so a trigger time at `t0` was never processed. As for the root functions tracked by the solver (AMICI-dev#3490), the direction of the root function now decides the Heaviside variable after `t0` for trigger times within the root-finding tolerance of `t0`. These trigger times are marked as handled, so that they are not processed again when reached. This also covers trigger times that coincide with `t0` only up to roundoff. The Heaviside variable at `t0` is initialized from the sign of the computed root function, while the trigger time is computed from the solved expression, and both may disagree. E.g., for `k * time >= 1` with `t0 = 1 / k = 1 / 49`, `k * t0 - 1` evaluates to slightly below zero, while the trigger time is not after `t0`, so the condition stayed false. Conversely, a decreasing root function that is slightly negative at `t0`, while the trigger time is after `t0`, was flipped to true when the trigger time was reached. Within the tolerance and noise level, the final side is now decided by the slope only. As for a root function that is zero at `t0`, the event then triggers if its Heaviside variable was 0 at the end of the previous simulation period, or, for the first one, if its initial value is false. For that, the model keeps the Heaviside variables passed to `Model::reinit_events`. The same criterion is used for Heaviside variables that change in turn. Fixes AMICI-dev#3515. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dweindl
force-pushed
the
explicit_roots_at_t0
branch
from
November 16, 2026 12:31
85496eb to
6019e1d
Compare
dweindl
marked this pull request as ready for review
November 18, 2026 10:41
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
piecewiseand trigger conditions on time whose threshold is the initial time, e.g.,piecewise(2, time <= 0, 0)fromt0 = 0ortime <= 1fromt0 = 1, which kept their value att0for the whole simulation. The state cases of #3515 were already fixed by #3490.Conditions on time are handled at their explicit trigger times, which are only processed when they are reached after the current time (
get_next_trigger_timepointusesupper_bound), so a trigger time att0was never processed. Now, as for the root functions tracked by the solver,handle_initial_eventsdecides the Heaviside variables of trigger times within the root-finding tolerance oft0by the direction of the root function, and marks these trigger times as handled, so they are not flipped back when reached within roundoff aftert0. For that, the initialization oft_last_trigger_moved fromrun()/run_steady_state()tohandle_initial_events.This also covers trigger times that coincide with
t0only up to roundoff. The Heaviside variable att0is initialized from the sign of the computed root function, while the trigger time comes from the solved expression, and both may disagree. E.g., fork * time >= 1witht0 = 1 / k = 1 / 49,k * t0 - 1is slightly negative, but the trigger time is not aftert0, so the condition stayed false for the whole simulation. Within the tolerance and noise level, the final side is now decided by the slope of the root function alone. Whether the event triggers is then decided, as for a root function that is zero att0, against the Heaviside variable at the end of the previous simulation period (Model::get_h_old), so an event that already triggered att0during presimulation or preequilibration does not trigger again.Known limitation, as for the state cases: values evaluated exactly at
t0already use the value after the switch, e.g., an observablepiecewise(2, time <= 0, 0)is 0 att = 0.For trigger times within roundoff after
t0, the switch now also happens silently att0, without recording a discontinuity. Therefore, the sensitivity with respect to such a trigger time is the one for a trigger time<= t0(no jump contribution), consistent with #3490 for root functions tracked by the solver.Fixes #3515.
🤖 Generated with Claude Code