Repository navigation
NonlinearSolveAlg: pipe wrapprecs into inner alg and update weight per step - #3795
Merged
ChrisRackauckas merged 6 commits intoJul 6, 2026
Merged
ChrisRackauckas merged 6 commits into
ChrisRackauckas merged 6 commits into
Conversation
Member
|
Add a test for this |
Member
Author
|
added a test — solves with NonlinearSolveAlg and checks the weight buffer is allocated and gets filled after a step |
singhharsh1708
force-pushed
the
fix/nonlinearsolvealg-precs-weight
branch
from
June 29, 2026 18:51
6b58dc4 to
474d143
Compare
| prob, | ||
| TRBDF2( | ||
| autodiff = AutoFiniteDiff(), | ||
| nlsolve = NonlinearSolveAlg(NewtonRaphson()) |
Member
There was a problem hiding this comment.
The weights are only used with default preconditioners though? So it needs a KrylovJL_GMRES() linsolve test.
Member
Author
|
Right — the weight only feeds into the default precs path via |
singhharsh1708
force-pushed
the
fix/nonlinearsolvealg-precs-weight
branch
3 times, most recently
from
July 3, 2026 19:27
4d6f94e to
d78a847
Compare
added 6 commits
July 5, 2026 09:12
singhharsh1708
force-pushed
the
fix/nonlinearsolvealg-precs-weight
branch
from
July 5, 2026 03:42
d78a847 to
de67095
Compare
This was referenced Jul 12, 2026
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.
The NonlinearSolveAlg path builds the same
weightbuffer andwrapprecs(alg.linsolve, W, weight)as the NLNewton path, but then drops both:_nlalg_with_linsolve(nlalg.alg, alg.linsolve)pipes the barealg.linsolveinto the inner NonlinearSolve, discarding thewrapprecswrapper that NLNewton uses.initialize!forNLSolver{<:NonlinearSolveAlg, true}never callscalculate_residuals!(weight, ...), so even if the precs were piped through they'd be acting on a buffer of zeros.Net effect: every NonlinearSolveAlg user loses the weight-based diagonal preconditioner that NLNewton enjoys on stiff problems — quietly worse Newton convergence with no warning.
Fix
weightfield toNonlinearSolveCache(parametrized asweightTypeso OOP can passnothing).build_nlsolver: pipewrapprecs(alg.linsolve, W, weight)into_nlalg_with_linsolve, and storeweighton the cache.build_nlsolver: passnothingfor weight, matching the existing OOP NLNewton path which also has no weight buffer.initialize!forNonlinearSolveAlg: update theweightbuffer viacalculate_residuals!, mirroringinitialize!forNLSolver{<:NLNewton, true}.After this, the precs closure built by
wrapprecs(aReturns((Pl, Pr))that captures_vec(weight)by reference) sees fresh weights every step, exactly as for NLNewton.Diff: +14/−4 across
newton.jl,type.jl,utils.jl. OOP path is untouched semantically (only theNonlinearSolveCacheconstructor call gets an extranothingarg).