Skip to content

Fix BDF step rejection for backward-in-time integration - #4503

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-bdf-backward-reject-controller
Sep 11, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-bdf-backward-reject-controller

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Summary

bdf_step_reject_controller! performs its step-size selection (hₖ₋₁ > hₖ, hₙ = min(h, hₖ₋₁)) on signed step sizes. For backward-in-time integration (tdir < 0, e.g. adjoint solves in SciMLSensitivity) dt is negative, so min picks the candidate with the larger magnitude. On repeated step failures the retry dt can converge to a fixed point where EEst > 1 forever — the solver then burns maxiters in an infinite reject loop instead of shrinking the step.

This is what broke the SciMLSensitivity downstream/test/Core3/dae_adjoint.jl EnzymeVJP/InterpolatingAdjoint tests on Julia 1.13: the backward adjoint FBDF solve stalls at t ≈ 0.0088 with ~10⁶ consecutive rejections at a frozen dt = -6.09e-4, hits MaxIters, and returns gradients from a truncated adjoint trajectory. The regression surfaced after #4484 moved reinitFBDF! ahead of the cache destructuring (the correct order), which changed the restart trajectory enough to route onto this path — the sign bug itself predates that commit and also reproduces on the released OrdinaryDiffEqBDF 2.4.7.

Fix: do the step-size selection on magnitudes (h = abs(integrator.dt)) and restore the direction with integrator.tdir when writing integrator.dt. Forward-in-time behavior is unchanged (tdir = 1).

Test plan

New regression test BDF step rejection shrinks |dt| for backward integration in lib/OrdinaryDiffEqBDF/test/bdf_regression_tests.jl drives the real reject controller on an FBDF integrator for both tdir = ±1, forcing consfailcnt > 2 at order 3 with a small terkm1.

Before the fix (unfixed code):

BDF step rejection shrinks |dt| for backward integration: Test Failed
  Expression: abs(integ.dt) <= abs(dt0) / 2
   Evaluated: 3.5704529489329065e-10 <= 1.0000000000000002e-10

i.e. |dt| grew by ~1.8x on a rejected backward step. After the fix all 4 tests pass, and the downstream dae_adjoint.jl suite passes (44/44), including the two previously failing EnzymeVJP assertions:

dpe  = [-15.50462892, -4.7545349e-9, 2.85388009e-5]   vs fd_p  = [-15.50462891, -4.7545349e-9, 2.85388010e-5]
du0e = [3.94242063, -0.00030100]                      vs fd_u  = [3.94242063, -0.00030100]

Also ran bdf_regression_tests.jl (all pass) and fbdf_time_filter_tests.jl + fbdf_filter_regression_tests.jl (all pass).

🤖 Generated with Devin (harness: Devin CLI 3000.10.21, model: SWE-2 High). Session: local Devin CLI session (no shareable URL); session db at /home/crackauc/.local/share/devin/cli/sessions.db

bdf_step_reject_controller! selects the next step size with
min(h, hₖ₋₁) / hₖ₋₁ > hₖ on the signed step sizes h = dt/2, F·h.
For tdir < 0 (backward integration, e.g. adjoint solves) dt is
negative, so min picks the candidate with the *larger* magnitude.
On repeated failures the retry dt can stay at a fixed point with
EEst > 1 forever, looping until maxiters. This showed up as
SciMLSensitivity DAE-adjoint tests failing on Julia 1.13 after the
FBDF reinit ordering fix (SciML#4484) moved restarts onto this path.

Do the step-size selection on magnitudes and restore the sign via
integrator.tdir when writing back integrator.dt. Behavior is
unchanged for forward-in-time integration (tdir = 1).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Agent-Harness: Devin CLI 3000.10.21
Agent-Model: SWE-2 High
Agent-Session: local Devin CLI session (no shareable URL); session db at /home/crackauc/.local/share/devin/cli/sessions.db
@ChrisRackauckas
ChrisRackauckas merged commit 21a97f0 into SciML:master Sep 11, 2026
135 of 141 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 13, 2026
- Unify companion global error estimators into GlobalErrorEstimation (#4492)
- Add adjoint-based global error control as a SciMLSensitivity extension (#3953)
- ExpRK: cache ishermitian (rebase of #4305, + review fixes) (#4497)
- Mark discrete time-grid search helpers as Enzyme inactive (#4496)
- GlobalAdjoint: every-step trajectory scope and step-grid control (#4495)
- GlobalAdjoint: defer to adjoint_sensitivities default instead of pinning an adjoint (#4498)
- Release GlobalDiffEq 1.7.1 (#4501)
- Fix GlobalDiffEq precompilation on Julia 1.13 and companion accuracy (#4500)
- Make mass-matrix identity/zero/diagonal checks GPU-safe (#4502)
- Fix BDF step rejection for backward-in-time integration (#4503)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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