Skip to content

Make PresetTimeCallback robust to tstop roundoff#305

Closed
AshtonSBradley wants to merge 1 commit into
SciML:masterfrom
AshtonSBradley:asb/issue-1124-preset-time-roundoff
Closed

Make PresetTimeCallback robust to tstop roundoff#305
AshtonSBradley wants to merge 1 commit into
SciML:masterfrom
AshtonSBradley:asb/issue-1124-preset-time-roundoff

Conversation

@AshtonSBradley

@AshtonSBradley AshtonSBradley commented May 7, 2026

Copy link
Copy Markdown

Summary

  • Fixes PresetTimeCallback matching when an integrator reaches a preset floating-point time within roundoff instead of at the exact stored tstop.
  • Keeps the exact insorted path, then checks the nearest sorted preset time with a small floating-point tolerance after promoting the solver time and preset time together.
  • Adds focused regressions for a 9.0 preset time reached as 8.999999999999996, covering integer vector, Julia range, and floating vector schedules; this is the callback-side behavior behind PresetTimeCallback skipped for certain constant lags in DDEs DifferentialEquations.jl#1124.

Explanation

PresetTimeCallback currently checks preset times with exact sorted membership. That can skip the callback when upstream time stepping lands on the intended stop with a representational roundoff, which showed up in the downstream DDE reproducer from SciML/DifferentialEquations.jl#1124.

This makes the callback predicate robust to that case by preserving the exact membership check first, then comparing only the nearest candidate tstops from the sorted preset-time vector. The comparison promotes t and the candidate tstop together, so schedules like [2, 9] and 2:7:9 are handled the same way as [2.0, 9.0] when the solver time is floating-point. Non-floating comparisons and exact matches keep the existing behavior.

Tests

  • julia --project=. -e 'using Pkg; Pkg.test()'
    • Passed: DiffEqCallbacks | 373 pass / 373 total.
  • julia -e 'using Pkg; Pkg.activate(; temp=true); Pkg.develop(path="/private/tmp/DiffEqCallbacks-1124"); Pkg.add("OrdinaryDiffEqTsit5"); include("/private/tmp/DiffEqCallbacks-1124/test/preset_time.jl")'
    • Passed with no test failures.
  • Downstream DDE reproducer based on PresetTimeCallback skipped for certain constant lags in DDEs DifferentialEquations.jl#1124 with local DiffEqCallbacks and explicit MethodOfSteps(Tsit5()).
    • Passed: fired preset events included (:up, 9.0) and sol.retcode = SciMLBase.ReturnCode.Success.
  • julia --project=@runic -e 'using Runic; exit(Runic.main(["--check", "src/preset_time.jl", "test/preset_time.jl"]))'
    • Passed.
  • git diff --check
    • Passed.

@AshtonSBradley AshtonSBradley marked this pull request as ready for review May 7, 2026 22:15
@ChrisRackauckas

Copy link
Copy Markdown
Member

Why not just use the values from Julia's range?

@AshtonSBradley AshtonSBradley force-pushed the asb/issue-1124-preset-time-roundoff branch from 3684dbb to 8ef936f Compare May 7, 2026 22:28
@AshtonSBradley AshtonSBradley force-pushed the asb/issue-1124-preset-time-roundoff branch from 8ef936f to de2a691 Compare May 8, 2026 01:39
@ChrisRackauckas

Copy link
Copy Markdown
Member

Seems like this was AI slip, not the real issue.

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.

2 participants