Repository navigation
NonlinearSolveAlg: reassemble W after a rejected step, and retry a stale Jacobian - #4282
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
…ale Jacobian `NonlinearSolveAlg`'s W-reuse gate was missing two of `do_newJW`'s terms, and the pair of them accounted for essentially every nonlinear convergence failure it recorded where `NLNewton` recorded none. `errorfail`: the `dt` cut that follows an error-test rejection typically moves `γΔt` by ~15%, which is inside `new_W_dt_cutoff` (1//5), so the retry reused a `W` whose chord iteration contracts at ~0.25 per iteration and cannot converge inside `maxiters`. On Bruss1D/TRBDF2 at rtol 1e-9, 113 of the 118 stage-1 solves that reused `W` had `EEst > 1` on entry and 112 of them failed; the corresponding `NLNewton` figure is 0 of 301. `TryAgain`: `NLNewton` hits the same `maxiters` exhaustion (15 times on that problem) but `nlsolve!` retries it in-step with a fresh Jacobian, so it reports none of them. `NonlinearSolveAlg` was excluded from that retry by an `isnewton` gate; `tracks_J_age` now admits any cache that records `J_t`. Neither change works alone: `errorfail` on its own leaves ROBER/TRBDF2 at rtol 1e-9 rejecting 39533 steps against master's 3763. Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 12, 2026
…(carries #4282 to current master) (#4505) * NonlinearSolveAlg: reassemble W after a rejected step, and retry a stale Jacobian `NonlinearSolveAlg`'s W-reuse gate was missing two of `do_newJW`'s terms, and the pair of them accounted for essentially every nonlinear convergence failure it recorded where `NLNewton` recorded none. `errorfail`: the `dt` cut that follows an error-test rejection typically moves `γΔt` by ~15%, which is inside `new_W_dt_cutoff` (1//5), so the retry reused a `W` whose chord iteration contracts at ~0.25 per iteration and cannot converge inside `maxiters`. On Bruss1D/TRBDF2 at rtol 1e-9, 113 of the 118 stage-1 solves that reused `W` had `EEst > 1` on entry and 112 of them failed; the corresponding `NLNewton` figure is 0 of 301. `TryAgain`: `NLNewton` hits the same `maxiters` exhaustion (15 times on that problem) but `nlsolve!` retries it in-step with a fresh Jacobian, so it reports none of them. `NonlinearSolveAlg` was excluded from that retry by an `isnewton` gate; `tracks_J_age` now admits any cache that records `J_t`. Neither change works alone: `errorfail` on its own leaves ROBER/TRBDF2 at rtol 1e-9 rejecting 39533 steps against master's 3763. Co-Authored-By: Chris Rackauckas <[email protected]> * NSA oop: split J refresh from W reassembly in the no-init W-reuse path The out-of-place `initialize!` for the `NonlinearSolveNoInitCache` + `StaticWOperator` reuse path now follows the same `do_newJW` split as the in-place branch: `calc_J` only runs on first use, divergence, `TryAgain`, `always_new`, or non-adaptive stepping, while a `γΔt` drift or an error-test rejection reassembles `W` from the stored `J` instead of re-evaluating the ODE Jacobian. `TryAgain` forcing a fresh `J` also keeps the `nlsolve!` stale-Jacobian retry from looping on an unchanged `W`. 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 Agent-Session: /home/crackauc/.local/share/devin/cli/summaries/history_450c9d90c1b846b9.md * Static W-reuse test: J is now refreshed less often than W `_update_nlsolvealg_W_oop!` reassembles `W` from the stored `J` on a `γΔt` drift or an error-test rejection and only re-evaluates `J` on first use, failure or retry, so `njacs == nw` no longer holds on the StaticArrays no-init path; the reuse is exactly what `0 < njacs < nw` asserts. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]> Agent-Harness: Claude Code 2.1.269 Agent-Model: claude-fable-5-1 Agent-Session: https://claude.ai/code/session_01UZBsW6FiGpRStDpX3rGMEW Claude-Session: https://claude.ai/code/session_01UZBsW6FiGpRStDpX3rGMEW --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Chris Rackauckas <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 13, 2026
- OrdinaryDiffEqDefault: require OrdinaryDiffEqCore 4.17.1 (#4520) - Add adaptive step size control to SDC (#4346) - Allow JET 0.12 in every QA test environment (#4513) - Resolve OrdinaryDiffEqDefault against the local sublibraries (#4514) - NonlinearSolveAlg: stale-Jacobian retry + rejected-step W reassembly (carries #4282 to current master) (#4505) - Do not seed a retry from the previous-step interpolant (#4473) - Say why the linear path ignores new_W_dt_cutoff (#4527) - Carry the QNDF2 difference array across steps (#4526) - Pass Θ = 0, not the absolute time, to the AN5 startup interpolant (#4534) - Make the stabilized-RK step cap and eigenvalue tolerance direction-agnostic (#4536) 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]>
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.
NonlinearSolveAlg's W-reuse gate was missing two ofdo_newJW's terms, so after an error-test rejection it kept reusing aWthat the stage could not converge against.The mechanism
do_newJWrebuildsWwhenwbad = … || (isfirststage && errorfail) || …. Adtcut after a rejected step movesγΔtby ~15%, which is insidenew_W_dt_cutoff = 1//5, so NSA — which had noerrorfailterm — reused it. The result is a chord iteration with a mismatchedW, converging linearly instead of quadratically and exhaustingmaxiters = 10:Every failure was
:exhaustedatmaxiters, all on the TRBDF2 trapezoid stage, all withcache.new_W == false. No divergence test ever fired.NLNewtonhits the same exhaustion but recovers in-step viaTryAgain→@goto REDO; NSA was excluded from that by theisnewton(nlsolver)gate.Confirmed from the outside using only public knobs, with no source patch: tightening
new_W_dt_cutoffbelow the failing drift band, or raisingmax_iter, both drive the failures to zero.And the decisive negative control on the other solver — disabling
(isfirststage && errorfail)inNLNewton's owndo_newJWreproduces NSA's behaviour:errorfaildisabledBoth terms are needed.
errorfailalone cuts convergence failures but causes a rejection explosion (ROBER/TRBDF2nreject3763 → 39533); the retry alone leaves 128 failures. Together they land onNLNewton's count exactly.Effect
120 configurations (5 problems × 8 integrators × rtol 1e-6/1e-9/1e-12), 111 where all three solvers succeed:
nfTotal
nnonlinconvfail85768 → 337 (NLNewton: 326). Totalnjacs85879 → 5026 (NLNewton 4858).It removes a silent wrong answer. ROBER +
Kvaerno5at rtol 1e-6, over 10 one-ULP perturbations ofu0:The largest work wins are on
Trapezoid, not the configurations that motivated the investigation:ROBER/Trapezoid@1e-6was 12.4× NLNewton with 16196 convergence failures and is now 1.00× with 15;VdPstiff/Trapezoid@1e-12was 107× andMaxItersand is now 0.97× andSuccess;Bruss1D/Trapezoid@1e-123.79× → 1.00×. Mass-matrix, sparse and matrix-free paths all drop toNLNewton's convergence-failure counts.What this is not
It is a parity change, not an improvement over
NLNewton. NSA now reproducesNLNewton's step sequence, and therefore its error — which on some configurations is larger than what NSA produced before, because master was taking a different (accidentally luckier) trajectory. On ROBER/TRBDF2, pooled over 64 samples across four perturbation axes, the error ratio toNLNewtonis ≈1.00 while the ratio to master is 1.99. Every one of those errors is 2–5 orders of magnitude below the requested tolerance, so this was never an accuracy defect in either direction.I am deliberately not quoting single-point numbers for ROBER/TRBDF2:
rtol = 1e-9exactly is a lucky point forNLNewtonthere (nf 426618, against ~600–675k at 13 of 14 neighbouringrtolvalues), so improvements measured at that point do not generalize. What survives every axis isfix/NLNewton ≈ 1.00.Regressions, disclosed
NonlinearSolveNoInitCache(aSimpleNonlinearSolveinner algorithm) regresses: Bruss1DKenCarp4@1e-8nf 2003 → 4323 (2.16×),TRBDF2@1e-91.82×,KenCarp4@1e-91.52×. That path has a reusableW, so it takes the retry, but lacks the outer machinery to benefit. Worth gating on before merge — I have not.VdPstiff/FBDF@1e-9goesSuccess→Unstable.NLNewtonis alsoUnstableon that exact configuration, and over 36 perturbations the fix andNLNewtonfail on precisely the same 15 samples (McNemar p = 1.0, zero discordant). Master's NSA was accidentally more robust by holding a stalerW. This is the judgement call for review.HIRES/FBDF@1e-121.72× vs master — the only row where the fix is materially aboveNLNewton(1.281).VdPstiff/QNDF@1e-12convergence failures 4 → 9.Tests
New
nsa_stale_w_reuse_tests.jl(16 assertions), registered inruntests.jl. Negative control on unmodified master:All twelve
nsa_*.jlfiles pass on the branch: 348 assertions, zero failures. Runic clean.OrdinaryDiffEqNonlinearSolve2.10.0 → 2.11.0.Two pre-existing master failures were confirmed identical on the base branch and are untouched: a
GROUP=QAJET report aboutcompute_step!locals, and aLinear Solver TestsMethodErroronjacobian!(::NullOperator, …)withRosenbrock23+KLUFactorization.🤖 Generated with Claude Code