Skip to content

Floor the Newton direction's linear tolerance at sqrt(eps) - #4301

Closed
singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:krylov-reltol-tighten-only
Closed

singhharsh1708 wants to merge 1 commit into
SciML:masterfrom
singhharsh1708:krylov-reltol-tighten-only

Conversation

@singhharsh1708

Copy link
Copy Markdown
Member

Fixes #4293.

compute_step! for NLNewton hands integrator.opts.reltol straight to the linear solve.
A Newton correction has to be more accurate than the tolerance it is being used to reach, so
at the default reltol = 1e-3 the Krylov solve returns a direction good only to 1e-3, the
stage never converges to 1e-3, dt collapses and the step controller gives up.

test/Regression_I/newton_krylov_roundoff.jl is the thing that broke because it calls solve
with no tolerances, so the linear solve inherits the 1e-3 default. On upstream/master at
202f5fd:

retcode accepted rejected drift
Hairer4 master Unstable 3 31 n/a
Hairer42 master Unstable 5 31 n/a
Hairer4 here Success 21 1 4.44e-16
Hairer42 here Success 21 1 6.66e-16

The gate is drift < 1e-5 and that file's own comment puts a round-off reproducible run in
the 1e-15 to 1e-7 band.

The floor is sqrt(eps) because that is LinearSolve's own default, which is where this sat
before #4192 made the linear tolerance integrator-driven. It is not a constant fitted to this
reproducer. A run looser than that behaves as it did before #4192, a tighter one still gets
the tighter linear solve.

Why here and not in set_linear_reltol!

Clamping inside set_linear_reltol! also fixes the reproducer, and I measured it, but it
floors every caller including the Rosenbrock path. A Rosenbrock stage is a single linear solve
whose accuracy caps the stage directly rather than feeding an iteration, so reltol is the
right target there and flooring it is just over-solving: at reltol = 1e-3 on Robertson it
moves Rodas5P from 1.1e-3 error to 2.1e-6 while doing more work for accuracy nobody asked
for. It also fails four assertions across two files rather than one.

I also tried extending the same floor to set_inner_linear_reltol!, on the theory that
NonlinearSolveAlg's inner Krylov descent is a Newton direction too. That fails two more
assertions in nsa_krylov_tolerance_tests.jl, and that file's third testset already measures
the loose tolerance there as costing no accuracy and no nnonlinconvfail, so there is nothing
to fix on that path. Left alone.

Test change, please look at this one

lib/OrdinaryDiffEqDifferentiation/test/krylov_linear_tolerance_tests.jl asserted
newton_cache(integrator).reltol == tol for tol = 1e-6, which is the behaviour that breaks
#4293, so it had to move to min(tol, sqrt(eps(Float64))). The tol = 1e-10 case in the same
loop is unchanged and still checks that a tighter tolerance passes through. The other three
assertions in that file, and all three testsets of nsa_krylov_tolerance_tests.jl, are
untouched and pass.

Testing

Ran against this branch: krylov_linear_tolerance_tests.jl, nf_accounting_tests.jl,
warm_start_default_tests.jl, stale_w_linear_operator_tests.jl, newton_krylov_roundoff.jl,
linear_nonlinear_tests.jl, nsa_krylov_tolerance_tests.jl, nsa_residual_convergence_tests.jl,
nsa_conditioning_tests.jl, mass_matrix_tests.jl. All pass. newton_tests.jl I could not run
locally, DiffEqDevTools fails to precompile on my Julia 1.10 for unrelated reasons.

Also swept Hairer4, Hairer42, TRBDF2, KenCarp4, FBDF, QNDF, Rodas5P,
Rosenbrock23 and the NonlinearSolveAlg variants of TRBDF2 and KenCarp4 with
KrylovJL_GMRES at default tolerances over an index-1 DAE, Allen-Cahn and Robertson. Every
case that succeeded on master still succeeds, and KenCarp4 and FBDF on Robertson improve
from 2.7e-4 and 5.7e-4 error to 1.4e-6 and 3.1e-5.

One thing that sweep turned up and that this PR does not address: Rosenbrock23 with
KrylovJL_GMRES on a mass-matrix problem with a jac_prototype errors with
MethodError: no method matching jacobian!(::SciMLOperators.NullOperator, ...). That happens
on unmodified master too, so it is a separate bug. I can file it if it is not already known.

AI Disclosure

Claude assisted with this work.

Copy link
Copy Markdown
Member

I reproduced the NonlinearSolve downstream Hairer regression locally and verified this patch discriminates it.

Using the same focused Hairer regression file with NonlinearSolve 4.27, NonlinearSolveBase 2.46, and SciMLBase 3.49:

unfixed 4bb84954086103d6a3a472673cee84db18b7c816:
  Hairer4: two retcode failures; drift = 4096 (required < 1e-5)

this PR (02ac18e7d687756864b94e70a0909fd0b86ddef0):
  Hairer4  | 3/3 pass
  Hairer42 | 3/3 pass

The branch also cherry-picks cleanly onto current OrdinaryDiffEq master and git diff --check exits 0. The current Regression_I CI lanes on this PR are green.

For tracking, the failure surfaced from 4bb8495. Current master has separate inherited QA/Core failures being investigated independently; they are not caused by this focused tolerance-floor change.

@ChrisRackauckas

Copy link
Copy Markdown
Member

No just update the test to use appropriate defaults.

@ChrisRackauckas

Copy link
Copy Markdown
Member

I mean not defaults but tolerances.

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.

Hairer4/Hairer42 with KrylovJL_GMRES fail on an index-1 DAE (Regression_I)

3 participants