Repository navigation
NonlinearSolveCache: define Base.resize! and guard firstcall write - #3799
Merged
ChrisRackauckas merged 2 commits intoJun 29, 2026
Merged
Conversation
singhharsh1708
force-pushed
the
fix/nonlinearsolvecache-resize
branch
from
June 29, 2026 09:28
d63b5c4 to
ab0fbd3
Compare
singhharsh1708
force-pushed
the
fix/nonlinearsolvecache-resize
branch
from
June 29, 2026 09:39
ab0fbd3 to
2f65d5a
Compare
Member
|
Needs a test. Use NonlinearSolveAlg in the cache growing event tests as a good test case for this. |
This was referenced Jun 29, 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.
resize!(integrator, N)on an integrator usingNonlinearSolveAlgblows up two ways before reaching the actual nlsolver work:resize!(nlsolver.cache, nlsolver, integrator, i)falls through to the default atutils.jl:740, which callsBase.resize!(cache::NonlinearSolveCache, i::Int)— undefined, so MethodError.resize_nlsolver!doesnlsolver.cache.firstcall = trueunconditionally, butNonlinearSolveCachehas nofirstcallfield (onlyNLNewtonCache/NLNewtonConstantCachedo —NLFunctionalCacheandNLAndersonCachealso lack it).Fix
Base.resize!(::NonlinearSolveCache, ::AbstractNLSolver, integrator, i::Int)mirroring the existingNLNewtonCacheresize: resize the buffer fields that are populated (ustep,k,atmp,du1,jac_config,J/Wviaresize_J_W!), thenSciMLBase.reinit!(nlcache.cache, zero(nlcache.ustep))to bring the inner NonlinearSolve cache'su/fu/Jto the new size.firstcallwrite inresize_nlsolver!withisnewton(nlsolver) && (...), matching the same pattern already inpostamble!atnlsolve.jl:197.The
===nothingguards on each field handle both IIP (fields populated) and OOP (most fieldsnothing).Note: the
firstcallguard line overlaps with PR #3794 — same one-line change to the same site. Settles cleanly on merge regardless of order.