Skip to content

NordsieckBDF: rebase dense output when a callback truncates the step - #4540

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nordsieck-callback-addsteps
Sep 12, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nordsieck-callback-addsteps

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Draft. Please ignore until reviewed by @ChrisRackauckas.

What changed and why

_ode_addsteps! for the four Nordsieck caches (NordsieckBDF, DNordsieckBDF, in-place and constant) was a literal return nothing. When a ContinuousCallback locates a root inside an accepted step, OrdinaryDiffEqCore shortens integrator.dt to the root and calls ode_addsteps!(…, always_calc_begin = true) so the solver can rebuild integrator.k for the truncated interval. QNDF, FBDF and DFBDF do this in stiff_addsteps.jl; Nordsieck ignored it, so k kept the columns centred on the original endpoint and scaled by the original step while the interpolant evaluated s = Θ - 1 with Θ computed from the truncated dt. Dense output over the event step was wrong by ~1e-2 at reltol = 1e-8 and did not pass through the saved event value, for both the ODE and DAE solvers.

The fix rebuilds k from the committed Nordsieck array cache.zn (columns about tprev + h, h = cache.hscale), then re-expresses the same polynomial about the new endpoint: with b = dt / h and a = b - 1, s = a + b s', which is an in-place Taylor shift by a followed by scaling column j by b^(j-1). Rebuilding from zn rather than from k keeps repeated calls idempotent (a following u_modified! reevaluation calls ode_addsteps! again with the same dt). The constant-cache method allocates new columns because k[j] aliases zn[j] there.

No public API change. OrdinaryDiffEqBDF is at 2.4.9 on master, which is not yet registered, so no version bump.

Failing before / passing after

Test added to lib/OrdinaryDiffEqBDF/test/nordsieck_tests.jl: u' = -u (scalar out-of-place and vector in-place) and the index-1 DAE u1' = -u1, 0 = u2 - u1, with a ContinuousCallback at u = 0.5 whose affect does nothing. It checks that the event step was really truncated, that sol(t_event) matches the saved value, and that sol(τ) at interior points of the event step is within 1e-6 of exp(-τ).

On unmodified master (75adf30) with only the test added:

NordsieckBDF / DNordsieckBDF: dense output over a step truncated by a callback: Test Failed
  Expression: ≈(first(sol(t1)), first(sol.u[i]), atol = 1.0e-10)
   Evaluated: 0.48981388085931105 ≈ 0.5 (atol=1.0e-10)
NordsieckBDF / DNordsieckBDF: dense output over a step truncated by a callback: Test Failed
  Expression: abs(first(sol(τ)) - exact(τ)) < 1.0e-6
   Evaluated: 0.0010450286506006323 < 1.0e-6
…
Test Summary:                                                                  | Pass  Fail  Total   Time
NordsieckBDF / DNordsieckBDF: dense output over a step truncated by a callback |    3    30     33  23.1s

With this PR:

Test Summary:                                                                  | Pass  Total   Time
NordsieckBDF / DNordsieckBDF: dense output over a step truncated by a callback |   33     33  16.7s

All other testsets in nordsieck_tests.jl pass in both runs.

Verification

Run from lib/OrdinaryDiffEqBDF on Julia 1.12.4.

GROUP=QA julia --project -e 'using Pkg; Pkg.test()':

Test Summary:    | Pass  Broken  Total     Time
Allocation Tests |    4      18     22  5m11.9s
Test Summary: | Pass  Broken  Total     Time
JET Tests     |   18      23     41  1m17.9s
Test Summary: | Pass  Total     Time
Aqua          |   21     21  1m16.6s
     Testing OrdinaryDiffEqBDF tests passed

(the Broken entries are pre-existing markers in the QA suite; none were added.)

GROUP=Core julia --project -e 'using Pkg; Pkg.test()':

Test Summary:         | Pass  Total     Time
DAE Convergence Tests |   50     50  1m37.7s
DAE AD Tests          |   40     40  10m23.5s
DAE Event Tests       |    4      4  11.6s
DAE derivative_discontinuity! Tests |   11     11
DAE Initialization Tests |   38  (2 broken, pre-existing)  40
DAE Nonlinear Solve Path Tests |   16     16  36.4s
BDF Inference Tests   |    1      1  2.6s
BDF Convergence Tests |   84     84  4m13.2s
BDF Regression Tests  |   49     49  4m19.8s
BDF Time Reversal Tests |   20     20  1m43.7s
FBDF Time Filter Tests |   41     41  28.0s
FBDF Filter Regression Tests |  273    273  20.2s
Nordsieck BDF Tests   |  134    134  4m27.2s
LHL Factorization Tests |   19     19  1m07.1s
     Testing OrdinaryDiffEqBDF tests passed

Formatting checked with Runic 1.9.0 (--check clean) and typos on the changed files.

Not verified

  • GPU group (needs hardware).
  • Downstream packages (DelayDiffEq history lookups through this interpolant should now be correct over event steps, but I did not run its suite).

Found while testing, deliberately left out of this PR

An out-of-place DAEProblem with any ContinuousCallback errors on master, independent of this change:

MethodError: no method matching get_tmp_cache(::ODEIntegrator{DNordsieckBDF…}, ::DNordsieckBDF…, ::DNordsieckBDFConstantCache)
  get_tmp_cache(::Any, ::OrdinaryDiffEqAlgorithm, ::OrdinaryDiffEqConstantCache)   # DAEAlgorithm is not an OrdinaryDiffEqAlgorithm
  get_tmp_cache(::Any, ::DAEAlgorithm, ::OrdinaryDiffEqMutableCache)

reached from DiffEqBase.find_callback_time → get_condition → get_tmp. The regression test here therefore covers the in-place DAE only. The missing get_tmp_cache(::Any, ::DAEAlgorithm, ::OrdinaryDiffEqConstantCache) method is a one-line OrdinaryDiffEqCore fix with its own test and will go in a separate PR.

🤖 Generated with Claude Code (Claude Code 2.1.270, model: claude-fable-5-1)

https://claude.ai/code/session_01A1EvyhqnXh4tSeovg5e8y8

The Nordsieck `_ode_addsteps!` was a no-op, so after a continuous
callback shortened an accepted step the stored columns stayed centred on
the original endpoint with the original scaling while the interpolant
evaluated them with the truncated dt. sol(t) over that step was off by
~1e-2 at reltol 1e-8 and did not pass through the saved event value, for
both NordsieckBDF and DNordsieckBDF.

Rebuild k from the committed Nordsieck array, Taylor-shift by
(dt - h)/h and rescale by (dt/h)^j so the same polynomial is expressed
about the new endpoint. Rebuilding from zn rather than k keeps repeated
calls (e.g. a subsequent u_modified reevaluation) idempotent.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Agent-Harness: Claude Code 2.1.270
Agent-Model: claude-fable-5-1
Agent-Session: https://claude.ai/code/session_01A1EvyhqnXh4tSeovg5e8y8
Claude-Session: https://claude.ai/code/session_01A1EvyhqnXh4tSeovg5e8y8
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 12, 2026 23:34
@ChrisRackauckas
ChrisRackauckas merged commit 16fd07f into SciML:master Sep 12, 2026
136 of 141 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.

2 participants