Repository navigation
Fix NonlinearSolveAlg crash with SimpleNonlinearSolve inner solvers - #4137
Merged
Merged
Conversation
Comment on lines
+165
to
+172
| # A no-init cache is `solve!`-driven, so it must keep terminating on its own | ||
| # (nonzero, default) tolerances here exactly as on the build path: rebuilding | ||
| # it with the zeroed tolerances below would leave every complete inner solve | ||
| # returning `MaxIters`. | ||
| cache.cache = init( | ||
| new_prob, cache.cache.alg; | ||
| verbose = integrator.opts.verbose.nonlinear_verbosity | ||
| ) |
Member
There was a problem hiding this comment.
What do you actually get from this? If it's a noinit cache, there isn't anything?
Member
There was a problem hiding this comment.
oh I forgot we made a noinitcache object.
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.
NonlinearSolveAlgcrashes with every SimpleNonlinearSolve inner algorithm. Thosedefine no
__init, so NonlinearSolveBase hands back aNonlinearSolveNoInitCache,which carries only
prob, alg, args, kwargs, initializealg, retcode, verbose. Thefirst raw field read then throws:
This is the last of the #3859 bug class. #3959 routed
uandfuthroughget_u/get_fubut left the rawstatsreads, which I said I would fix when it cameup on #4112. Extracted from #3798 so the crash fix lands independently of the W-reuse
feature still under discussion there; #3798 rebases onto this once it lands.
Every guard dispatches on the cache type, not on a list of algorithm types, so a newly
exported SimpleNonlinearSolve algorithm is picked up automatically. The changes: the
stats copies in both
initialize!methods skip a cache that has no counters;compute_step!drives a no-init cache withsolve!(it has nostep!) and reads thereturned solution;
_rejected_trial_stepskips it; the builds and the post-resize!rebuild keep the solver's own tolerances instead of the zeroed ones the stepped path
uses, which would send every inner solve to
MaxIters; andinitialize!hands thecache a copy of
zrather thanzitself, sincereinit!on this cache stores thearray it is given and a later in-place
resize!ofzotherwise defeats thelength-mismatch rebuild and leaves a stale, wrongly sized Jacobian buffer behind.
Stats on this path are honest rather than invented. SimpleNonlinearSolve builds every
solution with
stats === nothing, so the residual and Jacobian work its solvers docannot be attributed to the integrator; nothing is counted for
nfandnsolve, andnjacs/nwcount only the W assemblies performed on this side of the boundary.Verified on a matrix of three problems (scalar decay, stiff in-place Van der Pol,
singular-mass-matrix Robertson) times three methods (Trapezoid, TRBDF2, FBDF): every
SimpleNonlinearSolve cell crashes on master and succeeds on this branch with worst
error 1.9e-6 at reltol 1e-8, and every already-working cell (NewtonRaphson,
TrustRegion, RobustMultiNewton, FastShortcutNonlinearPolyalg and the rest) produces
byte-for-byte identical trajectories to master.
The new
test/nsa_noinit_tests.jlpasses 102 assertions on this branch; againstmaster's source it errors out on the exact crash above. Mutation testing was run guard
by guard when this change was first assembled: deleting any of the guards leaves the
suite red, including the tolerance guards, which needed a singular-mass-matrix stage
to discriminate because an easy problem's residual can hit exact zero and terminate
SuccessunderMaxIterstolerances. The full Core group is 707 passing with noregressions.
Two upstream findings from the same investigation, filed separately rather than
patched here:
BroydenandKlementdiverge on the second solve afterreinit!because their update-rule caches never reset the stored previous residual, and
NonlinearSolveAlg(LevenbergMarquardt())on the stepped path returnsSuccesswith amaterially wrong answer on a scalar problem.
AI Disclosure
Claude assisted with this work.