Fix PresetTimeCallback being skipped with certain constant lags#368
Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
Closed
Conversation
When constant lags like [0.2, 4] are used, propagated tstops accumulate floating-point error through repeated t + lag additions. After 45 steps of lag 0.2, the propagated tstop for t=9.0 becomes 8.999999999999996. The handle_discontinuities! function was removing all tstops within 10eps(t) of the current time, including user-specified tstops from PresetTimeCallback. This caused callbacks to be silently skipped when a propagated tstop happened to land within eps of the callback time. The fix restricts the tstop cleanup to only remove from tstops_propagated, never from opts.tstops. User-specified tstops should never be removed by discontinuity handling. Fixes SciML/DifferentialEquations.jl#1124 Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.
Summary
PresetTimeCallbackwas silently skipped when constant lag multiples coincided with preset callback times due to floating-point accumulation errorRoot Cause
When constant lags like
[0.2, 4]are used, propagated tstops accumulate floating-point error through repeatedt + lagadditions. After 45 steps of lag 0.2, the propagated tstop for t=9.0 becomes8.999999999999996.The
handle_discontinuities!function was removing all tstops within10eps(t)of the current time from bothopts.tstops(user callbacks) andtstops_propagated(lag-generated stops). When the propagated tstop landed just below 9.0, and integrator.t was snapped to that value, the user's 9.0 tstop was within the epsilon tolerance and got erroneously removed.The Fix
The fix restricts the tstop cleanup in
handle_discontinuities!to only remove fromtstops_propagated, never fromopts.tstops. User-specified tstops (fromPresetTimeCallback, etc.) should never be removed by discontinuity handling.Test Plan
Fixes SciML/DifferentialEquations.jl#1124
🤖 Generated with Claude Code