Repository navigation
Fix DDE+SDIRK2 iip/scalar divergence: restore nlsolver.c=c[1] in IIP stage 1 - #3690
Merged
ChrisRackauckas merged 1 commit intoMay 27, 2026
Conversation
The OOP path of `_perform_step` in `generic_imex_perform_step.jl` sets `nlsolver.c = c[1]` before the stage-1 `nlsolve!` (line 1404); the IIP path was missing this assignment. `nlsolver.c` determines `cache.tstep = integrator.t + nlsolver.c * dt` inside the Newton solver, which is the time argument passed to `f` during the implicit solve. Without this assignment, the IIP path's stage-1 implicit solve carried over the stale `c` value left behind by the previous outer step's stage 2 (= `c[2]`). For `SDIRK2` (`c = [1, 0]`), this means stage 1 ran at `t` instead of `t + dt`, and the cancellation in the SDIRK2 stage-2 algebra reduces both stages to the same fixed point `zs[1] == zs[2] == dt*f(t, uprev)`. The embedded error estimate `btilde[1]*zs[1] + btilde[2]*zs[2] = (zs[1] - zs[2])/2` then collapses to 0, letting the PI controller grow `dt` unboundedly. Reproduces as `DimensionMismatch` in `lib/DelayDiffEq/test/interface/multi_algorithm.jl`'s `Constant delays` testset: iip solves of `prob_dde_constant_2delays_ip` produce 11 timesteps while scalar solves produce 36 (and the iip trajectory is visibly wrong — `u` jumps linearly between discontinuity tstops). Regression bisected to PR SciML#3641 (commit 99187d0, 2026-05-17). That commit dropped `nlsolver.c = c[1]` from both IIP and OOP. A follow-up restored it in OOP only; the @generated rewrite in SciML#3643 and the inline in SciML#3676 preserved the asymmetry. After this patch the `Constant delays` testset goes 27/27 green for all nine algorithms (BS3, Tsit5, RK4, Vern6, SDIRK2, TRBDF2, KenCarp4, Rosenbrock23, Rodas4). SDIRK2 sol.errors[:l∞] = 0.0035, well under the 3.8e-1 threshold. No other algorithm's iip-vs-scalar step counts or l∞ errors changed. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
ChrisRackauckas
marked this pull request as ready for review
May 27, 2026 14:41
3 of 4 tasks
4 tasks done
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.
Summary
One-line fix in
lib/OrdinaryDiffEqSDIRK/src/generic_imex_perform_step.jlto restore annlsolver.c = c[1]assignment that the OOP path has but the IIP path was missing. Please ignore until reviewed by @ChrisRackauckas.Bug
lib/DelayDiffEq/test/interface/multi_algorithm.jl'sConstant delaystestset throwsDimensionMismatchon SDIRK2:iip takes giant steps that snap exactly to discontinuity tstops (0.2, 0.333, 0.4, 0.533, ...) with
uchanging linearly between them — visibly not the actual DDE solution. Both returnReturnCode.Success, so the controller blew dt up without ever rejecting.Root cause
In
generic_imex_perform_step.jl, the OOP_perform_step(line 1404) correctly setsnlsolver.c = c[1]before the stage-1nlsolve!. The IIP_perform_step_iip!(line 117–119) was missing this assignment:nlsolver.ccontrolscache.tstep = integrator.t + nlsolver.c * dtinside the Newton solver, which is the time argument passed tofduring the implicit solve. Without the assignment, IIP stage 1 carried over the stalecleft behind by the previous outer step's stage 2 (=c[2]).For SDIRK2 (
c = [1, 0],Ai = [[1,0],[-1,1]]), once stage 1 mistakenly usesc=0instead ofc=1, the SDIRK2 stage-2 algebra reduces both stages to the same fixed pointzs[1] == zs[2] == dt*f(t, uprev). The embedded error estimatebtilde[1]*zs[1] + btilde[2]*zs[2] = (zs[1] - zs[2]) / 2then collapses to exactly 0, so the PI controller is free to grow dt unboundedly.Why only SDIRK2
explicit_first_stage = true(most of them) skip thenlsolve!at stage 1 entirely, so the missing assignment never matters.s = 1(ImplicitEuler) have no stage 2 to leave a stalecbehind.SSPSDIRK2/Trapezoidthe cancellation algebra works out differently and the error estimate doesn't collapse to exactly 0.c = [1, 0]+ 2-stage tableau is the unique configuration where the missing assignment produceszs[1] == zs[2]exactly.Bisect
Regression introduced in #3641 (commit
99187d02e, 2026-05-17, Fix behavioral regressions in generic SDIRK/IMEX perform_step). That commit droppednlsolver.c = c[1]andnlsolver.γ = γfrom both IIP and OOP stage-1 sites. A follow-up restored them in OOP; #3643's@generatedrewrite and #3676's inline both preserved the IIP gap.Verification
Ran the
Constant delaystestset locally on Julia 1.11 with this patch:DimensionMismatch: a has size (11,), b has size (36,)on SDIRK2.sol.errors[:l∞] = 0.0035, well under the 3.8e-1 threshold.Test plan
Constant delaystestset passes locally for all 9 algorithmstest (DelayDiffEq_Integrators, *)andtest (DelayDiffEq_Interface, *)go green🤖 Generated with Claude Code