Skip to content

Bind NonlinearSolveAlg's inner Krylov tolerance to the integrator tolerance - #4268

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nsa-krytol
Aug 15, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:nsa-krytol

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Follow-up to #4207. Measurements and rationale are in my comment there.

NonlinearSolveAlg zeroes its inner nonlinear tolerances so the integrator owns convergence. That also starves the descent's linear solve, so it restores one through linsolve_kwargs with

_inner_lintol(::Type{T}) where {T} = eps(real(one(T)))^(4 // 5)   # ~3e-13 for Float64

fixed, regardless of reltol. A Krylov descent therefore runs to ~1e-13 no matter how loose the integrator is — at reltol = 1e-3 that is ten orders tighter than the step can use, and it is paid in Jacobian-vector products.

This applies #4192's set_linear_reltol! to NSA's inner linear cache, the way dolinsolve already does for NLNewton. Direct solvers are unaffected: set_linear_reltol! skips anything with needs_concrete_A.

It also removes an inconsistency that exists today

For NSA the smoothed error estimate's linear cache is the same LinearCache object as the inner Newton descent (they are aliased through get_linear_cache). So #4192's set_linear_reltol! already reaches NSA's inner solve — but only on the integrators that use a smoothed estimate:

alg        inner reltol@init   after 1 step
FBDF       3.000e-13           3.000e-13     (unchanged)
TRBDF2     3.000e-13           1.000e-03     (leaked)
KenCarp4   3.000e-13           1.000e-03     (leaked)
Kvaerno5   3.000e-13           1.000e-03     (leaked)

So half of this behaviour is already shipped, by accident, on some integrators and not others. This makes it deliberate and uniform.

Effect

2D Brusselator 16×16×2, AutoFiniteDiff, counting Jacobian-vector products. Measured with SciML/NonlinearSolve.jl#1169 applied, because without it NSA's Krylov path is not run-to-run reproducible and these numbers would be noise:

                     Jv: before ->  after
GMRES  FBDF     1e-3     1859  ->    677    0.364x
GMRES  FBDF     1e-6     6299  ->   3433    0.545x
GMRES  FBDF     1e-9    11192  ->   9018    0.806x
GMRES  TRBDF2   1e-3     1133  ->   1126    0.994x
GMRES  TRBDF2   1e-6     5077  ->   5066    0.998x
GMRES  TRBDF2   1e-9    22609  ->  22606    1.000x
GMRES  KenCarp4 1e-3     1842  ->   1634    0.887x
GMRES  KenCarp4 1e-6     4789  ->   4655    0.972x
GMRES  KenCarp4 1e-9    20152  ->  20161    1.000x

The split is exactly the leak above: FBDF gains, the ESDIRK integrators were already getting it. All LUFactorization rows are byte-identical — same Jv, nf, naccept and u[end] — confirmed by diff.

A broader 80-configuration sweep (Brusselator 8/16/32 + Allen-Cahn 64/256 × FBDF/TRBDF2/KenCarp4/Kvaerno5 × rtol 1e-3…1e-12) gives geometric-mean Jv 0.851, best 0.253, worst 1.036.

Why not Eisenstat-Walker

NewtonRaphson already accepts forcing = EisenstatWalkerForcing2(). At library defaults it is much worse here (geometric-mean Jv 1.277, worst 6.86, +10902 nnonlinconvfail) because of an upstream ordering bug: post_step_forcing! runs before evaluate_f!, so the forcing term is computed from a two-iteration-stale residual ratio and never adapts. Filed as SciML/NonlinearSolve.jl#1170. Until that is fixed EW cannot be evaluated fairly; once it is, it is worth revisiting.

Disclosed

  • Two DAE configurations gain convergence failures: roberDAE/TRBDF2/GMRES at 1e-6 goes nnonlinconvfail 0 → 4, pdeDAE/TRBDF2/GMRES at 1e-9 goes 2 → 5. Both still solve; the "no change" claim holds only for non-DAE ODEs.
  • Achieved accuracy loses roughly 2× at the tight end (bruss32/FBDF: 7.60e-10 → 1.24e-09). This is expected loss of over-accuracy — every run still meets the requested tolerance — but it is a real change.
  • Not tested: explicit user precs. Note the default NSA Krylov path already carries an InvPreconditioner{Diagonal} from wrapprecs, so the rows above are not unpreconditioned.

Tests

New nsa_krylov_tolerance_tests.jl (13 assertions) checks the inner cache's reltol tracks the integrator's for iterative algorithms, stays at _inner_lintol for direct ones, and falls back to eps when adaptive = false. All ten nsa_*.jl files pass: 13 + 24 + 21 + 13 + 10 + 10 + 14 + 8 + 102 + 70 = 285, 0 failures. Runic clean.

OrdinaryDiffEqNonlinearSolve 2.8.0 → 2.9.0, OrdinaryDiffEqDifferentiation floor 3.6 → 3.9 (for set_linear_reltol!).

Note on stacking: #4265 also bumps this package to 2.9.0. Whichever merges second needs 2.10.0 — the changes themselves are disjoint.

🤖 Generated with Claude Code

…erance

`build_nlsolver` zeroes the inner nonlinear tolerances so the integrator owns convergence,
and restores a linear tolerance through `linsolve_kwargs` as a fixed `eps^(4//5)`. That
value is independent of `reltol`, so a Krylov descent solve runs to ~3e-13 however loose
the integrator is: at `reltol = 1e-3` it is ten orders tighter than the step can use, paid
in Jacobian-vector products.

Set it per step from the integrator instead, the way SciML#4192 made `dolinsolve` do for
`NLNewton`, reusing that PR's `set_linear_reltol!` so a solver that needs a concrete `A`
is left alone.

Co-Authored-By: Chris Rackauckas <[email protected]>
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 15, 2026 23:06
@ChrisRackauckas
ChrisRackauckas merged commit 25b7914 into SciML:master Aug 15, 2026
139 of 172 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