Repository navigation
Restore the controller's step after a step shortened onto a tstop - #4751
Conversation
`_loopfooter!` restores the step the controller proposed before `modify_dt_for_tstops!` shortened it to land on a tstop, so that the next step is not grown from the (much shorter) landing step. Since `modify_dt_for_tstops!` also runs in `apply_step!` (SciML#3096), it runs twice per accepted step and the second call records the already shortened `dt` in `dtpropose`, so the restore (SciML#2869) restored the shortened step: after a stop placed 1% into a step, the next step was 0.1× the controller's proposal (the PI controller's `qmax` growth from the landing step). Record the step before either call in a new `dt_before_tstop` field and resume with it after the landing step. The landing step's error may shrink it but not grow it: scaling the restored step by the landing step's factor (up to `qmax`× on the strength of a tiny step's tiny error) overshoots, with more rejections and larger errors at matched tolerance. Callbacks of the landing step now see the accepted step in `integrator.dt`, so the current-step interpolant spans [tprev, t] (SciML#4655). Periodic tstops cost fewer steps at equal tolerance (u' = -u, stops every 0.11, 1e-8: Tsit5 199 → 151, Rodas5P 171 → 136); at matched achieved error the effect on small test problems is mostly within ±10%, larger where stops are dense relative to the step size. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ChrisRackauckas-Claude
left a comment
There was a problem hiding this comment.
Thanks @SebastianM-C, this fixes #4749 and also #4655. On the reproducer, the step after a tstop landing goes back to 1.00× the controller's proposal (master: 0.10× for Tsit5/Rodas5P, 0.51× for FBDF). In the #4655 callback, dt is 1.0 and Rodas5P's i(0.5) is 1.5. The new testsets fail on master and pass here. An automated review found one blocking item.
- DelayDiffEq gets worse (blocking).
DDEIntegratorhasnext_step_tstopbut nodt_before_tstop, so_get_dt_before_tstopfalls back todtpropose, the already-shortened landing step. The new capif landed && abs(dtnew) > abs(integrator.dt)then holds every following step to that landing step.- On
u' = -u(t-1)withMethodOfSteps(Tsit5()), tol 1e-8,tstops = 0.11:0.11:10, master takes 134 accepted steps and this branch takes 207. Limiting the cap toODEIntegratorbrings it back to 134. - DDEs without user tstops are affected too, because propagated discontinuities are tstops.
- Could you add
dt_before_tstop(plus the_get_/_set_dt_before_tstop!methods) toDDEIntegratorinlib/DelayDiffEq, or at least apply the cap only where the field exists? A DDE step-count regression test would be good either way.
- On
- Default behaviour change. Every adaptive solve with tstops now takes a different step sequence. With periodic tstops it usually takes fewer accepted steps (Rodas5P 335→265, FBDF 479→439), but sometimes with more rejections and a larger error at the stops. For FBDF with Δ = 0.37, rejections go 13→23 and the max error 6.9e-5→3.9e-4, which is above its no-tstop baseline of 2.3e-4. An FBDF work-precision comparison in the PR body would help the maintainers decide between making this the default and putting it behind a keyword. Since results change, it probably wants at least a minor version bump.
- Comments. About 18% of the added lines are comments, and the
dt_before_tstoprationale appears twice. One short comment at the helper definitions would be enough. - Minor. On accepted steps the step is recorded in
apply_step!beforefix_dt_at_bounds!, so the restored step can exceeddtmax.calc_dt_propose!clamps it later, so it isn't a bug, but recording it after the bounds are applied would be clearer.
Related: our draft #4805 (for #4750) fixes something different, the one-ulp step between tstops an ulp apart, and doesn't touch the controller. The two are complementary. This PR is the one for #4749, and whichever merges second only needs a trivial rebase.
🤖 Review by an AI agent (Claude Code, model claude-opus-5-5[1m]) on behalf of Chris Rackauckas — https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
PR: #4751 Reviewed head: 11daadf Risk assessment
Review reportVERDICT: CHANGES Riskhigh (H2: adaptive tstop handling changes step control and numerical results for the default solver) Blocking findings
Non-blocking findings
What I ran
What I did not verifyThe full BDF and DelayDiffEq suites, other Julia versions and platforms, and downstream packages beyond the DelayDiffEq probe. AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":4,"rounds":1,"author_harness":"unknown","author_model":"unknown","note":"The new ODE tests discriminate on the merge base and InterfaceI passes, but the shared acceptance path records incorrect Nordsieck history and suppresses valid step growth."} Head link: 11daadf 🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol |
Resolve the conflict in _loopfooter!: keep this branch's restore of dt_before_tstop and its growth cap, and master's restore of the accepted step before callbacks. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261126T152703Z-claude-claude-opus-5-5 Agent-Session: local session a5a71e23-1cd4-4ab9-83fc-6b9c0f657a5b (no session URL)
The landing step used to overwrite integrator.dt with the unshortened step before step_accept_controller!, so controllers that record the step (Nordsieck tau, PredictiveController dtacc) stored a step that was never taken. Controllers now see the accepted step. The unshortened step is applied afterwards, in _resume_dt_after_tstop, and only when: - modify_dt_for_tstops! actually shortened the step (an exact stop at the end of the proposed step leaves the proposal alone); - no discontinuity cap applies to the next step; - the integrator records dt_before_tstop (DelayDiffEq's integrator keeps the controller's own proposal); - resumes_dt_after_tstop(alg) holds. The new public trait is false for NordsieckBDF and DNordsieckBDF, which regrow within their own step-ratio limit, as CVODE does. The controller's step factor from the landing step then may shrink the unshortened step but not grow it, and the result is never smaller than the controller's own proposal. dt_before_tstop is clamped to dtmax. OrdinaryDiffEqCore 4.21.0 (new public trait, changed step sequences with tstops); OrdinaryDiffEqBDF 2.4.15 requires it. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261126T152703Z-claude-claude-opus-5-5 Agent-Session: local session a5a71e23-1cd4-4ab9-83fc-6b9c0f657a5b (no session URL)
|
Thanks for af36792. Keeping the accepted step in The new tests don't cover the I've also put the FBDF work-precision comparison asked for in the earlier review into the description, along with the other solvers. Overall the matched-error cost is about 5% lower. FBDF on Van der Pol is the main case that costs more (+7% / +13%, with more rejections). Generated by Claude Code |
…p landing The landing step's `dtacc` must be the step actually taken, not the step the controller asked for before it was shortened onto the tstop. On 11daadf it was 100x the accepted step for both RadauIIA5 (core PredictiveController path) and AdaptiveRadau (the FIRK override); af36792 fixed both. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018GADJLyZrg1HGFBsU9ht7f
PR: #4751 Reviewed head: 4bb4b27 Risk assessment
Review reportVERDICT: CHANGES Riskhigh (H2: recovery after a shortened tstop changes adaptive step control on default OrdinaryDiffEq paths) Blocking findings
Non-blocking findings
What I ran
What I did not verifyHosted CI, the docs build, QA, GPU, downstream suites, and Julia versions other than 1.12.4. The harness reported the Codex session recorded above. A Devin session name was unavailable for this run. AUTHOR_GRADE: {"task":"bugfix","score":2,"difficulty":4,"rounds":3,"author_harness":"unknown","author_model":"unknown","note":"The new Radau test catches both pre-fix history writes. The current head still bypasses an explicit growth limit and ignores the active composite member's opt-out."} Head link: 4bb4b27 🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol |
The next step after a step shortened onto a tstop resumes the pre-shortening proposal only with the new `resume_dt_after_tstop = true` solve/init keyword (default false). By default the controller's proposal from the accepted landing step stands, so `qmax` bounds the growth: with `PIController(Tsit5(); qmax = 2)` and a 2^-16 landing step the next step is 2^-15, and a transient right after the stop is resolved again. `_dt_shortened_for_tstop` queries `get_current_resumes_dt_after_tstop`, which for a `CompositeAlgorithm` evaluates `resumes_dt_after_tstop` on the member selected by `cache.current` instead of the wrapper. DiffEqBase accepts the keyword alongside `stage_limiter`/`step_limiter` in its keyword check, and OrdinaryDiffEqCore requires DiffEqBase 7.22. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261126T203233Z-claude-claude-opus-5-5 Agent-Session: local session 28d82478-4548-4435-9492-bfb0bfbba8bd (no session URL)
…stop Use exact dyadic steps (u' = 1, dt = dtmax = 0.125) with a stop 2^-16 into the first step and 2^-16 past the first step, and compare `dtacc` with the accepted step exactly, with and without `resume_dt_after_tstop`. The first-step case fails on master, which records 0.125 for RadauIIA5 and AdaptiveRadau; both cases failed before the controllers saw the accepted step. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_018GADJLyZrg1HGFBsU9ht7f
The DiffEqBase keyword check exempted resume_dt_after_tstop for every solver, so MethodOfSteps silently accepted a keyword it ignores. The check now receives the selected algorithm and exempts the names returned by the new documented hook DiffEqBase.solver_specific_kwargs(alg), which OrdinaryDiffEqCore specializes for OrdinaryDiffEqAlgorithm and DAEAlgorithm. stage_limiter and step_limiter stay exempt for all solvers. Tests: DelayDiffEq init and solve reject the keyword under KeywordArgError; solve and init with default algorithm selection accept it. The controller docs describe the default growth from the accepted step and the short-transient caveat of the opt-in. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261126T231403Z-claude-claude-opus-5-5 Agent-Session: local session 55017f2f-bc8c-4359-b190-2a0fbcdef634 (no session URL)
PR: #4751 Reviewed head: caa23b9 Risk assessment
Review reportVERDICT: CHANGES Riskhigh (H2: the shared accept path changes default adaptive step control after a shortened first tstop, reproduced with Tsit5) Blocking findings
Non-blocking findings
What I ran
What I did not verifyHosted CI, deferral issue status, QA, GPU and downstream suites, and Julia versions other than 1.12.4. AUTHOR_GRADE: {"task":"bugfix","score":3,"difficulty":4,"rounds":5,"author_harness":"unknown","author_model":"unknown","note":"The exact Radau testset passes and the independent probe detects the first-step bug on the base. The shared keyword exemption still makes strict DelayDiffEq calls silently accept an option they ignore."} Head link: caa23b9 🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol |
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261126T231403Z-claude-claude-opus-5-5 Agent-Session: local session 55017f2f-bc8c-4359-b190-2a0fbcdef634 (no session URL)
With resume_dt_after_tstop = true, AN5 restarted across a resizing tstop returned an 8% endpoint error with a Success retcode. AN5 now keeps its established restart step, like the Nordsieck BDF methods. The resize cases run with both option values. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261127T040210Z-claude-claude-opus-5-5 Agent-Session: local session 9d3a9ca6-424c-4f05-b24a-c1cc817d53b2 (no session URL)
Both QA environments source the checkout's OrdinaryDiffEqCore, which now requires DiffEqBase 7.22 for solver_specific_kwargs, but resolved their direct DiffEqBase dependency from the registry, where the newest release is 7.21.6. Resolution failed before any QA assertion ran. Sourcing DiffEqBase from the checkout matches the ExplicitRK, ExponentialRK, HighOrderRK and SSPRK QA environments. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261127T053510Z-claude-claude-opus-5-5 Agent-Session: local session e30f946c-684d-4eed-93ca-bc001612e0e0 (no session URL)
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: opencode <[email protected]> Agent-Harness: opencode 2.0.27 Agent-Model: opencode-go/hungerg-free Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261127T102122Z-opencode-opencode-go-hungerg-free Agent-Session: local session ses_de3781fdcffeQk4pHoPXMPpLvy (no session URL)
A custom `step_accept_controller!` may compute its proposal by mutating `integrator.dt`. Without the restore, callbacks and `current_interpolant` saw the proposed interval instead of the completed step, so dense output inside the callback was evaluated with the wrong normalization. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude <[email protected]> Agent-Harness: Claude Code 2.1.332 Agent-Model: claude-opus-5-5 Agent-Job: SciML__OrdinaryDiffEq.jl__4751--20261127T161917Z-claude-claude-opus-5-5 Agent-Session: local session 0b0c5333-f2ce-4681-bd0a-be20af559a69 (no session URL)
Review status. Counted round-10 review on this head ( CI status. The reds on this head all reproduce on Non-blocking — for the author. Two PR-description corrections came from the review (agents cannot edit contributor descriptions, so these are relayed): the verification paragraph should state that by default the controller computes the next step from the accepted landing interval — the next proposal can therefore change, including for Next step. Handed to the merge queue for a maintainer merge. 🤖 Posted by an AI agent — harness: Claude Code · model: qwen3.8-flash-next Conversation: directed-6 head session, local job directed-6-20261126 (no session URL) |
Bump version to 2.3.2 Bump version to 2.3.2 Bump version to 2.3.2 Bump version to 2.3.2 Bump version to 2.3.2 Bump version to 2.3.2 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: AI agent <[email protected]> Agent-Harness: hourly_releases Agent-Model: none (deterministic) Agent-Session: local job hourly-release-74dba2e6-d998-45b2-acda-764f0cc7c3c4 (no session URL) Agent-Session: local job hourly-release-3fa5fb01-9edb-4207-a008-f3e965ad262a (no session URL) Agent-Session: local job hourly-release-12159859-e451-418a-b40a-03a35d145353 (no session URL) Agent-Session: local job hourly-release-1f090ad0-9f29-4772-9a87-f993ebb136a2 (no session URL) Agent-Session: local job hourly-release-399633b3-4944-4d57-9c31-97c7a8620b97 (no session URL) Agent-Session: local job hourly-release-bac847af-5e64-4a93-b113-bf0e92dc91bd (no session URL)
Fixes #4749 with an opt-in
resume_dt_after_tstop = truesolve option.By default, the controller proposes the next step from the accepted landing step. Set
resume_dt_after_tstop = trueto request faster recovery on algorithms that support it. The callback interpolation test preserves behavior observed on the merge base. The work-precision results below describe an earlier always-resume revision._loopfooter!is meant to resume the step the controller proposed beforemodify_dt_for_tstops!shortened it to land on a tstop, so that the next step isn't grown from the (much shorter) landing step. Sincemodify_dt_for_tstops!also runs inapply_step!(#3096), it runs twice per accepted step, and the second call records the already-shorteneddtindtpropose. So the restore (#2869) restored the shortened step: after a stop placed 1% into a step, the next step was 0.1× the controller's proposal.Changes
Default behaviour: controllers see the accepted step
integrator.dtstays at the step actually taken whilestep_accept_controller!runs. Controllers that record the step therefore store the step that was taken: Nordsiecktau, andPredictiveController'sdtaccfor RadauIIA and the stabilized RK methods.[tprev, t]; the test for this (Callback interpolation after a tstop-clamped step uses the restored proposal dt #4655) preserves behavior observed on the merge base.qmaxholds relative to the shortened step.dtindtacc/tau.Opt-in:
solve(prob, alg; resume_dt_after_tstop = true)modify_dt_for_tstops!call in a newdt_before_tstopfield ofODEIntegrator(clamped todtmaxwhen used).max(dtnew, dt_before_tstop * min(1, dtnew / accepted_dt)), computed in_resume_dt_after_tstop. The landing step's factor may shrink the resumed step but not grow it, and the result is never smaller than the controller's own proposal. The resumed step is not limited byqmaxrelative to the landing step.modify_dt_for_tstops!actually shortened the step. A stop exactly at the end of the proposed step leaves the proposal alone.is_disco_step).dt_before_tstop. Other integrators, e.g. DelayDiffEq'sDDEIntegrator, keep the controller's own proposal.resumes_dt_after_tstop(alg),trueby default.get_current_resumes_dt_after_tstop(alg, cache)makes the active member of aCompositeAlgorithmdecide.resumes_dt_after_tstop(::NordsieckBDFAlgs) = false: the Nordsieck BDF methods regrow within their own step-ratio limit, as CVODE does.kwargshandlecheck only for algorithms that list it in the new documented hookDiffEqBase.solver_specific_kwargs(alg); OrdinaryDiffEqCore lists it forOrdinaryDiffEqAlgorithmandDAEAlgorithm. Other solvers, e.g. DelayDiffEq'sMethodOfSteps, reject it under strict keyword validation. The behaviour is documented indocs/src/api/controllers.md.Versions: OrdinaryDiffEqCore 4.21.0, which requires DiffEqBase 7.22. OrdinaryDiffEqBDF 2.4.15, which requires OrdinaryDiffEqCore 4.21.
Work-precision with
resume_dt_after_tstop = trueThese numbers compare step resumption against master. They were measured on
af36792, where resumption was always on, so they show what the option gives (the composite-member fix ina3ddbccdoesn't affect these solvers). The default path matches master on the same probes.Setup: Julia 1.13.4,
abstol = reltol = tolfortol = 1e-4 … 1e-10(Robertson:abstol = 1e-4 tol).nfwith resumption divided bynfon master interpolated, in log-log, at the same error. The table gives the geometric mean over tolerances; < 1 means resumption is cheaper.u' = -uon (0, 10), tstops every 0.11 and 0.37;10 .^ (-4:0.25:5);u' = -uTwo numbers in a cell are for the two tstop spacings, denser first. Over all 29 cases the geometric mean is 0.95: 17 cases are cheaper and 6 are more than 5% more expensive. Accepted steps go down in every case.
Where resumption costs more:
u' = -u, and 142 → 243 on Robertson.u' = -u: +9% / +23%. It is 28–34% cheaper on Van der Pol.nfdoesn't count Jacobians or factorizations, so for the implicit methods this is a proxy for cost, not wall time.Known issue with the option
AN5 with
resume_dt_after_tstop = truereturns a wrong result. On thelib/OrdinaryDiffEqNordsieckstate-resizing test, the solve reports success but the end value is off by 8.8%, against 3.5e-10 without the option. Making AN5 opt out withresumes_dt_after_tstop(::AN5) = falsefixes it. JVODE gives the same results with or without the option on that test.Tests
test/InterfaceI/ode_tstops_tests.jlqmaxby default and resumes with the option:PIController(Tsit5(); qmax = 2)and a2^-16landing step give2^-15and0.125respectively.PredictiveControllerrecords a step shortened onto a tstop at its accepted length indtacc. This covers RadauIIA5 (core controller) and AdaptiveRadau (FIRK override), with exact dyadic stops inside the first step and after it, with and without the option. The first-step case fails on master.lib/OrdinaryDiffEqBDF/test/nordsieck_tests.jl:NordsieckBDFrecords the accepted length intaufor a first-step and an interior stop, and its next proposal stays within its growth bound, with and without the option.lib/OrdinaryDiffEqCore/test/algorithm_interface_tests.jl:get_current_resumes_dt_after_tstopfollows the active member of aCompositeAlgorithm.lib/DelayDiffEq/test/interface/discontinuities.jl: forMethodOfSteps(Tsit5()), the step after an interior tstop grows past the landing step and the solve reaches the end oftspan.🤖 Generated with Claude Code
https://claude.ai/code/session_018GADJLyZrg1HGFBsU9ht7f