Skip to content

Fix PresetTimeCallback being skipped with certain constant lags#368

Closed
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-preset-time-callback-with-constant-lags
Closed

Fix PresetTimeCallback being skipped with certain constant lags#368
ChrisRackauckas-Claude wants to merge 1 commit intoSciML:masterfrom
ChrisRackauckas-Claude:fix-preset-time-callback-with-constant-lags

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • Fixes a bug where PresetTimeCallback was silently skipped when constant lag multiples coincided with preset callback times due to floating-point accumulation error
  • User-specified tstops should never be removed by discontinuity handling

Root Cause

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 from both opts.tstops (user callbacks) and tstops_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 from tstops_propagated, never from opts.tstops. User-specified tstops (from PresetTimeCallback, etc.) should never be removed by discontinuity handling.

Test Plan

  • Added regression test that reproduces the original issue
  • All existing tests pass

Fixes SciML/DifferentialEquations.jl#1124

🤖 Generated with Claude Code

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>
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.

PresetTimeCallback skipped for certain constant lags in DDEs

3 participants