Skip to content

Fix callback interpolation at tstops and restart BDF after rewinds - #4664

Merged
ChrisRackauckas merged 9 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4655-callback-interp-accepted-interval
Oct 31, 2026
Merged

ChrisRackauckas merged 9 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/4655-callback-interp-accepted-interval

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

Callbacks now use the accepted step size after a tstop clamp while the controller retains its proposed next step. Rewinding preserves the modification flag after interpolation-stage reevaluation, and QNDF2 resets its multistep history at that event. QNDF2 startup / rescale counting uses attempts since the last history reset (integrator.iter - iter_at_event); the error estimator uses accepted steps since the reset (success_iter - success_iter_at_event). On cold start / reinit!, initialize! only zeroes those anchors and leaves the multistep history as-is (empty from the cache constructor on a fresh init; leftover from the previous solve on reinit!); if reinit! zeroes iter without calling initialize!, perform_step! re-anchors when iter falls to or below the stored anchor. The Core fix also corrects saveat values and ContinuousCallback event times on a first step clamped onto a tstop (Rodas5P, ImplicitEuler, TRBDF2 were wrong on master; Tsit5/Vern9 were already correct), and the same accepted-interval restore fixes saveat corruption when a composite switches methods on any later clamped step (AutoSwitch / default dtfac, reported by @condekiq on #4655).

The flag restoration is necessary because reeval_internals_due_to_modification! rebuilds interpolation stages and clears derivative_discontinuity, but does not rebuild BDF history; the next BDF step must still see the event. It is deliberately local to a successful rewind.

Independent review: Claude Code claude-opus-5-5[1m], rounds 1-5. Round 5 on c5ad840 rated it VERDICT MERGE, RISK low-medium, high confidence. It found no blocking issues. Not an auto-merge candidate: this changes the Core step-acceptance path shared by every solver.

Two earlier BDF numerical changes from the first draft remain dropped after independent review because they alter numerics and have no discriminating test; they are tracked separately in #4670:

  • QNDF2 rescale on the first post-startup step (cnt > 0), which changed no-event QNDF2 trajectories.
  • QNDF order/dtprev persistence across rejected restart attempts, which changed post-event QNDF rejection counts (e.g. Robertson QNDF nrej 33 → 27).

Not fixed here

Tests

The original 672 assertions are unchanged: ImplicitEuler, TRBDF2, Rodas5P, QBDF2, QBDF, FBDF, Tsit5, and Vern9, in-place/out-of-place, forward/backward, with/without rewind. An additional 30 assertions cover analytic saveat and ContinuousCallback event times on a clamped first step (u' = 1). A further 26 assertions cover saveat when a CompositeAlgorithm switches methods with dtfac = 2 on a non-first step clamped onto tf (exact u' = 1), asserting the switch iteration, the stiff member, dt == t - tprev, and analytic values. QBDF/QBDF2 exercise QNDF/QNDF2 without including the independent default-QNDF cold-start error addressed by #4615. The additional 512 assertions cover default QNDF/QNDF2 and their QBDF variants after established nonconstant history, including adaptive and fixed stepping and explicit derivative modifications. A further 3 assertions pin Robertson QNDF2 / dt=1e-3 / tol=1e-4 (no events) to Success with naccept=54, nreject=1. An additional 2 assertions cover init → solve! → reinit! → solve! on that same Robertson case and require Success after the re-solve. Four more assertions cover reinit!(; reinit_cache=false) after a mid-solve DiscreteCallback on Robertson QNDF2 and require the re-solve to double the first run's naccept/nreject (stats accumulate across that reinit!). Expected states follow exactly from u'=0 or u'=1 after the event; assertions use Julia's default ≈ tolerance, and the solver is asked for abstol=reltol=1e-10.

No package versions or dependency bounds were changed.

Verification

Julia 1.12.7. Job-local writable depot; TMPDIR under the job tree. Commands and observed tails:

Negative controls: master and prior heads

On clean master (0fac2d061), the original assertion files fail as expected for the Core/BDF fix surface:

Callback interpolation on a tstop-clamped step            |  384  288  672
BDF history after a discontinuity                         |  384  128  512

The new saveat test on master (prior job): 24 pass / 6 fail (Rodas5P, ImplicitEuler, TRBDF2).

@condekiq's composite/saveat reproducer on clean master (a329b3b39): saveat max relerr 0.155, dense 9.1e-14, (t-tprev, dt) = (7.85e-9, 1.57e-8) with final member Rodas5P. On this PR head: both max relerr 9.1e-14, dt == t - tprev.

The scaled composite-switch saveat regression on master: 12 pass / 14 fail; on this head: 26 / 26.

The 3-assertion early-rejection test on ed03841d5 (round-2 prior head) fails all 3: Unstable == Success, 701 == 54, 234 == 1.

The new reinit! regression (Robertson QNDF2 dt=1e-3 tol=1e-4) fails at c49e20041: first solve Success naccept=54 nreject=1, after reinit!+solve! → Unstable at t=0.

The re-anchor regression (Robertson QNDF2 with mid-solve DiscreteCallback, then reinit!(; reinit_cache=false) + solve!) fails when the iter <= iter_at_event branches are deleted: first 130/5, after re-solve 400/123 (expected 260/10). On the head with the branches restored it passes (130/5 → 260/10).

PR assertion suites (672 + 30 + 26 + 512 + 3 + 2 + 4)

julia +1.12 -O1 --compiled-modules=existing --project=. -e '
include("test/InterfaceI/tstop_callback_interpolation.jl")
include("lib/OrdinaryDiffEqBDF/test/bdf_restart_tests.jl")
'
Callback interpolation on a tstop-clamped step            |  672    672
saveat and ContinuousCallback on a tstop-clamped first step |   30     30
saveat on composite switch during a non-first clamped step |   26     26
BDF history after a discontinuity                         |  512    512
QNDF2 no-event early rejection step count                 |    3      3
QNDF2 reinit! preserves Success on Robertson              |    2      2
QNDF2 reinit!(; reinit_cache=false) re-anchors after an event |    4      4

Round-3 early3 / reinit! probes vs master (matched Core)

Reviewer probe early3.jl (7 problems × QNDF/QNDF2/QBDF/QBDF2/FBDF × 5 dts × 2 tols = 350 cases; fresh solve and reinit!+resolve; exact ==). Shared-Core pair (master BDF vs this head's BDF under identical head Core):

fresh solve identical: 350 / 350; reinit!+resolve identical: 350 / 350

reinit!(; reinit_cache=false) after a mid-solve event: re-solve doubles the first solve's accept/reject counts (e.g. rober QNDF2 130/5 → 260/10, vdp 115/15 → 230/30).

OrdinaryDiffEqBDF GROUP=Core

BDF Restart Tests | 521  521
...
Testing OrdinaryDiffEqBDF tests passed

(Includes 512 history + 3 early-rejection + 2 reinit! + 4 re-anchor.)

Runic / typos

Runic --check and typos on all *.jl files changed against origin/master (prior rounds) and on the new composite-saveat test file (573792e0a): both exit 0.

What was not verified

  • ModelingToolkit downstream (its runner was lost in earlier rounds).
  • GPU suites.
  • Full DelayDiffEq and StochasticDiffEq suites with QNDF2.
  • Root InterfaceII / QA / Everything groups.
  • CI on GitHub after this push.
  • Julia 1.13 Waltman / DelayDiffEq failure (deterministic on master and this head alike in prior rounds).
  • A rebase onto a329b3b (one unrelated commit on master since the merge base).

Risk assessment

  • Risk: medium
  • Blast radius: the Core step path shared by all solvers (accepted-step size after tstop clamp; modification-flag restore on rewind) plus QNDF/QNDF2 history reset and QNDF2 attempt-since-event startup counting / reinit! anchor handling
  • Evidence: 672+30+26+512+3+2+4 local assertions green; master negative controls 288/672 and 128/512 fail; composite/saveat reproducer master 0.155 vs PR 9.1e-14; composite-switch regression 12/26 fail on master / 26/26 on head; early3 350/350 fresh and reinit identical under matched Core; re-anchor negative control 400/123 without the branch; BDF Core green; Runic/typos clean
  • Independent review: Claude Code claude-opus-5-5[1m], a different harness from both authors (Codex CLI and Cursor Agent), rounds 1-5. Round 5 on c5ad840 rated it low-medium, high confidence, VERDICT MERGE, no blocking findings. Its reinit! re-solve count with the re-anchor branch deleted was 400/124; this PR's run measured 400/123. Either way the new test fails without the branch.
  • Merge: needs human review: the change touches step-acceptance code shared by every solver, and the ModelingToolkit downstream CI result on this head is pending.

Fixes #4655.

Please ignore this draft until reviewed by @ChrisRackauckas.


Authorship: Codex CLI gpt-6-astra wrote 00f5e0f69 and 36896dcb3 (transcripts: <job>/log.txt, log-followup1.txt). Cursor Agent auto wrote ed03841d5, c49e20041, 3e9c2c82f, c5ad840b6, and 573792e0a (transcripts: <job>/log.txt, <job>/log.txt, <job>/log.txt, <job>/log.txt, <job>/log.txt).

Orchestrated by Claude Code (claude-opus-5-5[1m]), https://claude.ai/code/session_015tNYhuzygK9z8yhh6MNCAz

Risk assessment (independent review, Grok Build grok-4.7, reviewed head 771789f)

  • Risk: medium
  • Blast radius: Every adaptive ODE step goes through _loopfooter!. After a tstop clamp, callbacks, saveat, and change_t_via_interpolation! now see the accepted dt while the controller's next step still comes from dtpropose. On the non-SDE path, change_t_via_interpolation! leaves derivative_discontinuity set, so multistep methods restart after a rewind. QNDF2 startup and its error estimate count from event anchors. No new dependency, no removed or renamed public name, no Project.toml version bump. SDE change_t still only updates sqdt.
  • Evidence: Head 771789f76c86fd3ccf8b9785a2ca3efb0cb62cf9 (unchanged at the end). Julia 1.13 (julia +release), JULIA_NUM_THREADS=4.
  • Independent review: Grok Build grok-4.7 rated it medium, high confidence: the footer restores the step that was actually taken, the QNDF2 anchor arithmetic matches an already-incremented iter, and both new test files passed on Julia 1.13 against this worktree.
  • Merge: needs human review — the edit is on the shared accept path for every adaptive solver, and this PR's own InterfaceI and BDF Core jobs have not finished. Not an auto-merge while those are queued.

🤖 Posted by an AI agent — harness: Grok Build · model: grok-4.7 (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Risk assessment (independent review, Codex CLI 0.164.0-alpha.11.1 gpt-6-astra, slot 1, head 771789f)

  • Risk: medium-high (MH1: The accepted-step callback interval changes in Core for all adaptive solvers, with additional BDF history/cache changes; this is broader than a peripheral numerical fix.)
  • Verdict: MERGE
  • Session: 01a18da8-0055-70e2-850a-45982d205850
  • Blocking priorities: none

Review round 1, written by the reviewer named above (Codex CLI 0.164.0-alpha.11.1 / gpt-6-astra) in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands.

Summary: The PR preserves the accepted interval during callbacks and restarts QNDF2 history after interpolation rewinds. Analytic callback and restart tests cover the intended failures, and I found no blocking defect in the final diff.

Blast radius: Core adaptive-step acceptance, callback interpolation and rewind, QNDF/QNDF2-family restart histories, and reinit! cache anchors.

Evidence: Exact-head source and analytic-test review; BDF and InterfaceI CI pass; 257 success, 2 failure, 1 skipped checks. Failed Core4 and NonlinearSolve signatures match recent default-branch logs; no local base/head numerical run.

Blocking findings

None.

Non-blocking findings

  1. lib/OrdinaryDiffEqBDF/test/bdf_restart_tests.jl:48: Exact 54/1 step-count assertions are a preservation oracle, not an independent accuracy oracle. Keep the analytic affine restart cases as the correctness evidence and consider recording an independently derived accuracy check alongside the Robertson counts.
  2. lib/OrdinaryDiffEqBDF/src/bdf_perform_step.jl:559: The added comments narrate comparison with master and are longer than necessary; describe the preserved restart-state contract directly.

Comment cleanup has no runtime cost; adding an independent accuracy check costs one test comparison if a published reference is already available.

What I ran

The exact-head checkout was verified with git rev-parse HEAD (exit 0, SHA in header). git diff origin/master...HEAD and git diff --check origin/master...HEAD completed with exit 0; the latter produced no diagnostics. I inspected changed files, callers, tests, package manifests, and the absence of root AGENTS.md/CLAUDE.md. git log -1 --format=%B, git log --no-merges -1 --format=%B, and git log --no-merges -1 --format=%B origin/master..HEAD were inspected (exit 0); author trailers below come from the newest PR-specific non-merge commit. The header Base is fetched origin/master; GitHub's comparison base at review time was 59ba40e4b5bbae713d8df7b792f6ea62f033ff78.

I traced accepted_dt through tstop clamping, controller proposal calculation, and callbacks, and checked the derivative-discontinuity flag after change_t_via_interpolation!. I checked attempt-based QNDF2 anchors, accepted-step error-estimator counters, cache initialization and reinit! re-anchoring. Tests use u(t)=1+t and related analytic trajectories for in-place/out-of-place, forward/backward, callback rewind, saveat, method-switch, and event-history cases; G1/G3 evidence is substantive rather than success-code-only.

I read linked issues 4655, 4670, and 4675. The reported Rodas5P midpoint 1.25 versus analytic 1.5, and rewound endpoint 2.75 versus 3, agree with the old dt=2 scaling over an accepted interval of length 1. Those issue outputs are external evidence, not reviewer executions. The unrelated startup-policy changes discussed in 4670 are absent from this final diff.

CI: BDF Core and InterfaceI pass. Failed logs Core4 and NonlinearSolve contain respectively the Enzyme assertion and Newton line-search exception. I compared failure text with recent completed default-branch runs, rather than accepting the description's classification. Master IntegrationTest 41050161729 has the same Core4 ensembles.jl:19 Enzyme AssertionError: mi2 !== nothing; master Sublibrary CI 41058796614 has the same Julia-1 Newton LineSearchException: Search direction is not a direction of descent. Step length: 0.0. These are matching baseline failures, not green integration validation.

What I did not verify

No Julia process was run by this reviewer for this PR, so no reviewer Julia version or test exit code applies. I did not independently execute the new tests on both fetched master and head, repeat the body's large ablation matrix, or verify all callback/AD/GPU combinations. Missing local fail-before/pass-after evidence prevents treating this as a low-risk verified fix. The first assessment froze risk and candidates before opening the PR description. A fresh independent assessor then froze a complete review of this exact PR head before reading its description, any prior review, other assessment notes, or coordinator-run Julia output. The final comparison and REVIEWER_GRADE below come from that fresh assessment. It subsequently evaluated prior same-head findings and newly available raw execution evidence; prior claims are distinguished from executions in this review session. The independent freeze remains unchanged.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

ChrisRackauckas and others added 2 commits September 27, 2026 15:34
Keep the accepted interval available during callbacks without replacing the
controller's next-step proposal. Preserve rewind modification signals and
restart QNDF/QNDF2 history using accepted steps since the event.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.157.1
Agent-Model: gpt-6-astra
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4655-codex/log.txt on amdci2.julia.csail.mit.edu
Use the successful-step index at the last event so rejected attempts and
repeated DelayDiffEq stage evaluations cannot advance the startup counter.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.157.1
Agent-Model: gpt-6-astra
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4655-codex/log.txt on amdci2.julia.csail.mit.edu
Independent review required reverting the QNDF2 cnt>0 rescale and the
QNDF order/dtprev cache persistence, neither of which a test discriminated.
Add analytic saveat/ContinuousCallback coverage for the Core side fix.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4664-cursor-fix/log.txt on amdci2
ChrisRackauckas and others added 2 commits September 28, 2026 04:45
Accepted-step startup counting diverged from master after early
rejections (Robertson QNDF2 dt=1e-3 became Unstable). Restore
attempt-based startup/rescale with master's thresholds, keep
relative success_iter for the error estimator, and pin the
Robertson step counts.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.09.26-dd393fe
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4664-cursor-fix2/log.txt on amdci2
Calling reset_qndf2_history! from initialize! wiped cold-start state and
made reinit! without events diverge from master. Anchor event counters
only in initialize!, and re-anchor in perform_step! when iter falls to or
below the stored anchor so reinit!(; reinit_cache=false) stays correct.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4664-cursor-fix3/log.txt on amdci2
ChrisRackauckas and others added 2 commits September 28, 2026 11:35
Cover reinit!(; reinit_cache=false) after an event so a missing
iter<=iter_at_event branch fails (130/5 → ~400/124). Clarify that
initialize! leaves leftover history on reinit!, not an empty one.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4664-cursor-fix4/log.txt on amdci2
Covers the AutoSwitch/default dtfac path that corrupts saveat on a
non-first tf clamp (SciML#4655 follow-up from condekiq).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/4655-condekiq/log.txt on amdci2
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <[email protected]>
Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration)
Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4664/log.txt
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Merged the default branch into this PR (clean merge, no conflicts; head 0b1997c) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run.


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 31, 2026 11:20
@ChrisRackauckas
ChrisRackauckas merged commit 7af986d into SciML:master Oct 31, 2026
260 of 262 checks passed
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.

Callback interpolation after a tstop-clamped step uses the restored proposal dt

2 participants