Skip to content

Restore weighted preconditioning and tolerances for default Krylov solves - #4391

Merged
ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/kencarp-default-preconditioner
Aug 30, 2026
Merged

ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:fix/kencarp-default-preconditioner

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

What changed and why

LinearSolve now routes matrix-free WOperators through its default Krylov solver. Two OrdinaryDiffEq setup gaps made that path regress badly on implicit SplitODEProblems:

  • when alg.linsolve === nothing, the nonlinear-solver cache supplied identity preconditioners instead of the integrator's diagonal error weights;
  • after LinearSolve selected its concrete default algorithm, the cache retained LinearSolve's sqrt(eps) relative tolerance instead of the scalar integrator tolerance.

This PR supplies the same left/right weight scaling already used by explicit iterative solver choices and forwards scalar integrator tolerances into default LinearSolve caches. The left preconditioner now uses the public LinearSolve.InvPreconditioner API requested in review, wrapping the local zero-safe weight operator; the removed local inverse wrapper no longer duplicates LinearSolve's interface. The OrdinaryDiffEqNonlinearSolve and OrdinaryDiffEqDifferentiation compat floors are LinearSolve 5.15, the first release exporting that API, and InvPreconditioner is removed from Differentiation's ExplicitImports exception list. Zero residual weights are treated as one so rejected nonfinite steps do not create singular preconditioners. Explicit user solvers, user preconditioners, direct-factorization paths, and vector tolerances keep their existing behavior.

The required LinearSolve routing, preconditioner-forwarding, and public-wrapper changes are merged in SciML/LinearSolve.jl#1255, SciML/LinearSolve.jl#1263, and SciML/LinearSolve.jl#1272. They are available in LinearSolve 5.15.0.

Ignore this PR until it has been reviewed by @ChrisRackauckas.

Failing before / passing after

The default preconditioner behavior test fails on the original parent because both sides are identity:

Test Failed
Expression: left ≈ weight
Evaluated: [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] ≈ [2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
Exit status: 1

The tolerance test fails on the original parent:

Expression: newton_cache(integrator).reltol == 1.0e-5
Evaluated: 1.4901161193847656e-8 == 1.0e-5

For the review-requested public wrapper, I added @test linsolve.Pl isa InvPreconditioner before changing production code and ran the official Core harness against LinearSolve 5.15.0. It failed on the local wrapper:

Expression: linsolve.Pl isa InvPreconditioner
Evaluated: OrdinaryDiffEqNonlinearSolve._InverseWeightPreconditioner{Vector{Float64}}(...) isa LinearSolve.InvPreconditioner
Test Summary:                       | Pass  Fail  Total
Default Krylov Preconditioner Tests |    4     1      5

With the public wrapper change applied, the same testset passes:

Test Summary:                       | Pass  Total
Default Krylov Preconditioner Tests |    5      5

The unchanged focused file also exited 0 on final rebased head 46cec0b41c in a disposable environment resolving LinearSolve 5.15.0.

Benchmark verification

I tested current SciMLBenchmarks master plus SciML/SciMLBenchmarks.jl#1672, LinearSolve 5.14.1, and the earlier behavior-fix head. I restored the original KDV low-tolerance range (abstol = 1e-8:1e-12, reltol = 1e-5:1e-9) rather than PR 1672's temporary cap. The five-point low-tolerance IMEX diagram emitted with nonempty curves for all six solvers; the chunk took 113.946 seconds on this host.

The tightest original endpoint (abstol=1e-12, reltol=1e-9, N=128) completed for every KenCarp method, and the default Krylov cache updated to 1e-9:

KenCarp3: 39.02 s wall, 1673 steps, nf=29618, nsolve=31392, t=1.0
KenCarp4: 39.35 s wall,  840 steps, nf=25646, nsolve=26550, t=1.0
KenCarp5: 38.82 s wall,  545 steps, nf=22982, nsolve=23548, t=1.0

The exact page completed all chunks and emitted all figures:

Weaved all chunks
Elapsed (wall clock) time: 17:50.32
Exit status: 0

One solve in the later cross-family low-tolerance chunk reported Instability; that unrelated chunk still emitted all three five-point curves. The KenCarp low-tolerance chunk emitted without an instability warning.

Package verification

Julia 1.11.9, with LinearSolve 5.15.0:

$ GROUP=Core julia +1.11 --project=lib/OrdinaryDiffEqNonlinearSolve -e 'using Pkg; Pkg.test()'
Default Krylov Preconditioner Tests                 | 5/5
NonlinearSolveAlg Matrix-Free WOperator Tests       | 14/14
NonlinearSolveAlg Krylov Tolerance Tests            | 13/13
NonlinearSolveAlg Preconditioning Tests             | 70/70
NonlinearSolveAlg DAEProblem Tests                  | 32/32
NonlinearSolveAlg nlstep_data Field Tests           | 11/11
Testing OrdinaryDiffEqNonlinearSolve tests passed
Exit status: 0

$ GROUP=QA julia +1.11 --project=lib/OrdinaryDiffEqNonlinearSolve -e 'using Pkg; Pkg.test()'
JET Tests | 13 pass, 33 broken, 46 total
Aqua      | 41/41
Testing OrdinaryDiffEqNonlinearSolve tests passed
Exit status: 0

$ GROUP=QA julia +1.11 --project=lib/OrdinaryDiffEqDifferentiation -e 'using Pkg; Pkg.test()'
JET Tests | 1/1
Aqua      | 19/19
Testing OrdinaryDiffEqDifferentiation tests passed
Exit status: 0

$ julia +1.12 -m Runic --check <six review-change files>
$ typos <six review-change files>
$ git diff --check
runic=0 typos=0 diff_check=0

The full NonlinearSolve Core and QA runs were on source-identical review commit ab0610b414 before the final rebase. git range-diff reports those four PR commits unchanged after rebasing onto current master 01e4cc6eac. The unchanged focused test, Runic, typos, and git diff --check were rerun successfully on rebased head 46cec0b41c. Chris then added commit 17b957c381 to floor OrdinaryDiffEqDifferentiation and remove the obsolete ExplicitImports exception; the Differentiation QA group and static checks passed on that exact final head.

Earlier validation for the tolerance path also passed OrdinaryDiffEqDifferentiation Core and QA. The ten-page SimpleHandwrittenPDE benchmark validation is recorded at SciML/SciMLBenchmarks.jl#1672 (comment).

Not verified

GPU groups were not run locally. The docs build was not run because this review change adds no OrdinaryDiffEq public API, docstring, or documentation content. The public LinearSolve API was documented and its docs build passed in SciML/LinearSolve.jl#1272.

The downstream SciMLSensitivity and StochasticDiffEq failures visible on the older PR head reproduce on their unmodified default branches and are handled separately in SciML/SciMLSensitivity.jl#1627 and #4419.

Earlier implementation session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

🤖 Generated with Codex CLI 0.151.0 (model: gpt-5.6-sol; session: local session ID 01a04fab-48db-7e03-9f47-20c69464527f)

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Rebased onto current master 492022b56c after the complete Core run. The only intervening upstream commit was the disjoint StochasticDiffEqWeak scalar-Wiener fix from #4413; git range-diff reports the KenCarp patch as unchanged. On the rebased head ab8f38d7fe, the focused default-Krylov regression test exited 0, and Runic 1.9, typos, and git diff --check all pass.

@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the fix/kencarp-default-preconditioner branch from ab8f38d to 5704cc8 Compare August 28, 2026 07:58
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Master advanced again during the first update. The branch is now rebased onto 0f3179abfb; that upstream commit touches only OrdinaryDiffEqBDF tests and OrdinaryDiffEqDifferentiation derivative utilities. git range-diff again reports the KenCarp patch unchanged. Focused regression test, Runic 1.9, typos, and git diff --check all pass on final head 5704cc8431.

@ChrisRackauckas

Copy link
Copy Markdown
Member

This supplies the same weight-based left/right scaling directly to LinearSolve.init when the default linear solver is requested. The inverse-weight wrapper is local and uses the public LinearAlgebra interface instead of adding a dependency on LinearSolve's non-public InvPreconditioner. Explicit user linear solvers and user preconditioners keep the existing path.

Just make InvPreconditioner public.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Release-stack follow-up: I reran the reduced default KenCarp4 SplitODEProblem with registered LinearSolve 5.14.1 (which contains SciML/LinearSolve.jl#1263), registered SciMLOperators 1.30.0 (which contains SciML/SciMLOperators.jl#427), and this PR at 5704cc8431add2b99f8d9b80406c519c473c1378.

LinearSolve=5.14.1
mode=default elapsed=21.796816345 retcode=Success accepted=24 nf=446 nsolve=467
# exit 0

The Julia process took 3m44.93s wall because switching from the path checkout rebuilt 11 dependencies for 196 seconds; the measured solve itself was 21.80 seconds.

https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The original full-size regression case now passes with this PR plus the merged LinearSolve routing/forwarding fixes.

Exact case:

N = 128 Kuramoto–Sivashinsky SplitODEProblem
algorithm = KenCarp4() (default linsolve)
abstol = 1e-10
reltol = 1e-7

Observed on Julia 1.10.11:

mode=default elapsed=19.914211229 retcode=Success accepted=153 nf=3525 nsolve=3694

The same default case before the combined fix exceeded the 3,600-second external timeout inside Krylov.gmres!. The reduced 8-state MWE also completed in 15.66 seconds with 24 accepted steps, nf=446, and nsolve=467, matching the explicit-GMRES work counts.

This is direct evidence that SciML/LinearSolve.jl#1255, SciML/LinearSolve.jl#1263, and the weighted-default-preconditioner change here fix the benchmark regression. The exact kdv_fdm_wpd.jmd page is still running separately; this comment is specifically the previously timing-out tight KS case.

@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the fix/kencarp-default-preconditioner branch from 5704cc8 to d93a327 Compare August 28, 2026 19:55
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title Restore weighted preconditioning for default Krylov solves Restore weighted preconditioning and tolerances for default Krylov solves Aug 28, 2026
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The failing Runic check is a clean-master failure unrelated to this PR's diff. Exact current master 0542c1019a8a passes Runic 1.9.0 but fails newly released Runic 1.10.0 on two comprehensions in test/multirate/mreef_tests.jl, last changed by a2c092a14654f6dd10ef92ce8cb9b84edb86ab34.

The separate mechanical repair is #4423. It passes the full Runic 1.10.0 check over all 1,091 tracked Julia files, Multirate Core (70/70), root QA (106/106), typos, and git diff --check locally.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Three failed checks currently shown here are clean-master failures unrelated to this PR changed paths:

The checks affected by the KenCarp fix in Differentiation, QA, FIRK, and the completed nonlinear-solver checks remain green; the remaining matrix is still running.

Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The downstream validation now covers the entire ten-page SimpleHandwrittenPDE folder with every original tolerance range restored, not only kdv_fdm_wpd.jmd.

All ten pages returned exit 0, built markdown, and contained no embedded Julia exception. Wall times ranged from 16:34 to 55:12; the complete per-page table and the discriminating 3,600-second fail-before result are recorded at SciML/SciMLBenchmarks.jl#1672 (comment).

This was run on Julia 1.10.11 with this exact PR head d93a3275f926b6786f355ebb76a69f54549587a7 and LinearSolve 5.14.1. The rebased benchmark update is prepared locally but intentionally not pushed until this fix is merged and released, because registry resolution would otherwise put CI back on the known hanging stack.

The unrelated clean-master Runic failure is now fixed by #4423; its hosted Runic and Runic Suggestions checks are green.

@ChrisRackauckas-Claude

ChrisRackauckas-Claude commented Aug 29, 2026 •

Copy link
Copy Markdown
Member Author

Opened SciML/LinearSolve.jl#1272 to export the already documented InvPreconditioner. The focused Base.isexported assertion fails before and passes after locally; @ChrisRackauckas removed committing that two-line assertion during review at SciML/LinearSolve.jl#1272 (comment). The full LinearSolve Core and QA groups, docs build, Runic, typos, and git diff --check passed locally on the initial head. Once that API is merged and released in the next minor LinearSolve release, I will replace the local _InverseWeightPreconditioner here and floor the dependency accordingly; I am not pushing an unreleased public-API dependency that would make the current registered-version QA red.

ChrisRackauckas and others added 4 commits August 30, 2026 00:53
Supply the nonlinear solver's diagonal weight preconditioners when LinearSolve selects the default matrix-free Krylov method.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512
Keep the weight scaling finite when a rejected nonfinite step leaves a zero residual weight.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512
Tell the shared tolerance helper when an implicit integrator requested LinearSolve default selection, so a selected Krylov solve does not retain sqrt(eps).

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Claude-Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.151.0
Agent-Model: gpt-5.6-sol
Agent-Session: local session ID 01a04fab-48db-7e03-9f47-20c69464527f
@ChrisRackauckas-Claude
ChrisRackauckas-Claude force-pushed the fix/kencarp-default-preconditioner branch from d93a327 to 46cec0b Compare August 30, 2026 04:59
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Handled the review request in final head 46cec0b41c.

  • Export InvPreconditioner LinearSolve.jl#1272 exported the already documented InvPreconditioner, and LinearSolve 5.15.0 is registered.
  • This branch now uses LinearSolve.InvPreconditioner(_WeightPreconditioner(_vec(weight))), removes the duplicated local inverse wrapper, and floors OrdinaryDiffEqNonlinearSolve's LinearSolve compat at 5.15.
  • The new public-wrapper assertion failed before the production change (4 passed, 1 failed) and passes after (5/5).
  • GROUP=Core passed completely on the source-identical review commit, including Matrix-Free WOperator 14/14, Krylov Tolerance 13/13, Preconditioning 70/70, DAEProblem 32/32, and nlstep-data 11/11.
  • GROUP=QA passed (JET 13 pass / 33 existing broken; Aqua 41/41). Runic, typos, and git diff --check passed.
  • The branch was rebased onto current master 01e4cc6eac; git range-diff reports all four PR commits unchanged. The focused test and static checks passed again on exact final head.

GPU groups were not run locally. The PR body now contains the full commands and evidence.

Agent: Codex CLI 0.151.0, model gpt-5.6-sol, local session ID 01a04fab-48db-7e03-9f47-20c69464527f.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Follow-up on the branch update: @ChrisRackauckas added 17b957c381 to raise OrdinaryDiffEqDifferentiation's LinearSolve floor to 5.15 and remove InvPreconditioner from its ExplicitImports exception list. I preserved that commit and validated the exact resulting head locally:

$ GROUP=QA julia +1.11 --project=lib/OrdinaryDiffEqDifferentiation -e 'using Pkg; Pkg.test()'
JET Tests | 1/1
Aqua      | 19/19
Testing OrdinaryDiffEqDifferentiation tests passed
Exit status: 0

$ julia +1.12 -m Runic --check <the two added files>
$ typos <the two added files>
$ git diff --check
runic=0 typos=0 diff_check=0

The hosted matrix restarted for final head 17b957c381; it is being monitored separately. The PR body now reflects all six review-change files and the final-head validation.

Agent: Codex CLI 0.151.0, model gpt-5.6-sol, local session ID 01a04fab-48db-7e03-9f47-20c69464527f.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 30, 2026 09:00
@ChrisRackauckas
ChrisRackauckas merged commit 4660c53 into SciML:master Aug 30, 2026
185 of 186 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Fix StochasticDiffEqImplicit import ordering (#4408)
- Fix TauLeaping JumpProblem initialization (#4409)
- Fix dense output for the explicit multirate methods (#4233)
- Let reinit! keep the step-size controller history (#4400)
- Mark an operator Jacobian as updated when calc_W! moves it (#4354)
- Restore weighted preconditioning and tolerances for default Krylov solves (#4391)



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