Repository navigation
Fix callback interpolation at tstops and restart BDF after rewinds - #4664
Merged
ChrisRackauckas merged 9 commits intoOct 31, 2026
Conversation
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
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
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
This was referenced Oct 1, 2026
FBDF/QNDF: pass the step onto a tstop across an algebraic jump (diagonal mass matrices, #4660)
#4678
Draft
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
Member
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 |
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.
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 freshinit; leftover from the previous solve onreinit!); ifreinit!zeroesiterwithout callinginitialize!,perform_step!re-anchors wheniterfalls to or below the stored anchor. The Core fix also correctssaveatvalues 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 fixessaveatcorruption when a composite switches methods on any later clamped step (AutoSwitch / defaultdtfac, reported by @condekiq on #4655).The flag restoration is necessary because
reeval_internals_due_to_modification!rebuilds interpolation stages and clearsderivative_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:
cnt > 0), which changed no-event QNDF2 trajectories.dtprevpersistence across rejected restart attempts, which changed post-event QNDF rejection counts (e.g. Robertson QNDFnrej33 → 27).Not fixed here
QNDF2with userdt=1e-2,tol=1e-4returnsUnstableatt=0(naccept=0,nf=1073). An intermediate draft of this PR that counted accepted steps happened to avoid that failure; restoring master-compatible attempt counting makes the headUnstableon that case again, as expected.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
saveatand ContinuousCallback event times on a clamped first step (u' = 1). A further 26 assertions coversaveatwhen aCompositeAlgorithmswitches methods withdtfac = 2on a non-first step clamped ontotf(exactu' = 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 RobertsonQNDF2/dt=1e-3/tol=1e-4(no events) toSuccesswithnaccept=54,nreject=1. An additional 2 assertions coverinit→solve!→reinit!→solve!on that same Robertson case and requireSuccessafter the re-solve. Four more assertions coverreinit!(; reinit_cache=false)after a mid-solve DiscreteCallback on Robertson QNDF2 and require the re-solve to double the first run'snaccept/nreject(stats accumulate across thatreinit!). Expected states follow exactly fromu'=0oru'=1after 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;
TMPDIRunder 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:The new saveat test on master (prior job): 24 pass / 6 fail (Rodas5P, ImplicitEuler, TRBDF2).
@condekiq's composite/
saveatreproducer on clean master (a329b3b39):saveatmax relerr 0.155, dense 9.1e-14,(t-tprev, dt) = (7.85e-9, 1.57e-8)with final memberRodas5P. On this PR head: both max relerr 9.1e-14,dt == t - tprev.The scaled composite-switch
saveatregression 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 QNDF2dt=1e-3tol=1e-4) fails atc49e20041: first solveSuccess naccept=54 nreject=1, afterreinit!+solve!→Unstableatt=0.The re-anchor regression (Robertson QNDF2 with mid-solve DiscreteCallback, then
reinit!(; reinit_cache=false)+solve!) fails when theiter <= iter_at_eventbranches are deleted: first130/5, after re-solve400/123(expected260/10). On the head with the branches restored it passes (130/5 → 260/10).PR assertion suites (672 + 30 + 26 + 512 + 3 + 2 + 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 andreinit!+resolve; exact==). Shared-Core pair (master BDF vs this head's BDF under identical head Core):reinit!(; reinit_cache=false)after a mid-solve event: re-solve doubles the first solve's accept/reject counts (e.g. rober QNDF2130/5 → 260/10, vdp115/15 → 230/30).OrdinaryDiffEqBDF
GROUP=Core(Includes 512 history + 3 early-rejection + 2 reinit! + 4 re-anchor.)
Runic / typos
Runic --checkandtyposon all*.jlfiles changed againstorigin/master(prior rounds) and on the new composite-saveattest file (573792e0a): both exit 0.What was not verified
Risk assessment
reinit!anchor handlingsaveatreproducer 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 cleanFixes #4655.
Please ignore this draft until reviewed by @ChrisRackauckas.
Authorship: Codex CLI gpt-6-astra wrote
00f5e0f69and36896dcb3(transcripts:<job>/log.txt,log-followup1.txt). Cursor Agent auto wroteed03841d5,c49e20041,3e9c2c82f,c5ad840b6, and573792e0a(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)
_loopfooter!. After a tstop clamp, callbacks,saveat, andchange_t_via_interpolation!now see the accepteddtwhile the controller's next step still comes fromdtpropose. On the non-SDE path,change_t_via_interpolation!leavesderivative_discontinuityset, 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. SDEchange_tstill only updatessqdt.771789f76c86fd3ccf8b9785a2ca3efb0cb62cf9(unchanged at the end). Julia 1.13 (julia +release),JULIA_NUM_THREADS=4.wt-4664/lib/OrdinaryDiffEqBDF(manifest paths point at this worktree's Core, NonlinearSolve, and SDIRK):include("test/bdf_restart_tests.jl")exit 0. BDF history after a discontinuity 512/512 in 20.3s; QNDF2 no-event early rejection 3/3 in 4.5s (naccept==54,nreject==1);reinit!Success 2/2 in 0.6s;reinit!(; reinit_cache=false)4/4 in 5.0s. Log:review/logs/bdf-restart.log.review/env-4664-ifacewith[sources]on this worktree.CORE_PATHandBDF_PATHboth resolved underwt-4664.include("test/InterfaceI/tstop_callback_interpolation.jl")exit 0. Callback interpolation 672/672 in 2m29s; saveat and ContinuousCallback 30/30 in 54.7s; composite switch saveat 26/26 in 4.0s. Log:review/logs/tstop-interp2.log.CI on that head, read 2026-10-16: 260 checks, 29 success, 1 failure, 229 queued, 1 skipped. OrdinaryDiffEqBDF Core (Julia 1 and lts) and InterfaceI (1, lts, pre) are still queued. BDF GPU Julia 1 succeeded; that job is not these CPU restart tests. The only failure is SciMLSensitivity Core4,
AssertionError: mi2 !== nothingin Enzymeparallelrules.jlduringdownstream/test/Core4/ensembles.jl:19: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38856229758/job/116828193301. The same assertion fails on Fix SDIRK smooth_est Hairer–Wanner scaling (#2902) #4649 and DiffEqBase: run QA through SciMLTesting.run_qa with ExplicitImports #4613. Master Core4 on59ba40e4b5(2026-10-14) succeeded: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38561320093. Current masterd727918100CI is still queued (https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38883166867), so that run cannot yet show the failure as pre-existing. It is not this diff.iter, and both new test files passed on Julia 1.13 against this worktree.🤖 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
Risk assessment (independent review, Codex CLI 0.164.0-alpha.11.1 gpt-6-astra, slot 1, head 771789f)
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
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.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...HEADandgit diff --check origin/master...HEADcompleted with exit 0; the latter produced no diagnostics. I inspected changed files, callers, tests, package manifests, and the absence of rootAGENTS.md/CLAUDE.md.git log -1 --format=%B,git log --no-merges -1 --format=%B, andgit log --no-merges -1 --format=%B origin/master..HEADwere inspected (exit 0); author trailers below come from the newest PR-specific non-merge commit. The header Base is fetchedorigin/master; GitHub's comparison base at review time was59ba40e4b5bbae713d8df7b792f6ea62f033ff78.I traced
accepted_dtthrough tstop clamping, controller proposal calculation, and callbacks, and checked the derivative-discontinuity flag afterchange_t_via_interpolation!. I checked attempt-based QNDF2 anchors, accepted-step error-estimator counters, cache initialization and reinit! re-anchoring. Tests useu(t)=1+tand 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.25versus analytic1.5, and rewound endpoint2.75versus3, agree with the olddt=2scaling 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:19EnzymeAssertionError: mi2 !== nothing; master Sublibrary CI 41058796614 has the same Julia-1 NewtonLineSearchException: 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