Skip to content

Preserve despecialized parameters during reinit - #1199

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/despecialized-reinit-parameters
Aug 28, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/despecialized-reinit-parameters

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

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

What changed and why

Preserve AutoDespecialize's parameter wrapper when reinit! replaces a cache's parameters with a different concrete type. The public cache boundary now normalizes replacement parameters against the wrapper stored by the problem before updating nested Jacobian and linear caches. The same rule covers initialized solver caches, polyalgorithm caches, and NonlinearSolveNoInitCache without requiring callers such as OrdinaryDiffEq or ModelingToolkit to know NonlinearSolve's cache representation.

The regression reinitializes Newton, no-init, and default polyalgorithm caches with a new parameter type, verifies that the wrapper contains the current payload, and solves the updated problem. This is the generic replacement for the caller-side workaround in SciML/OrdinaryDiffEq.jl#4325.

Failing before

With the new regression test but without the source fix, the initialized cache fails before the solve:

AutoDespecialize dynamic parameters: Error During Test
MethodError: Cannot `convert` an object of type SolveOtherDynamicParameters to an object of type SciMLBase.DespecializedParameters
Stacktrace:
  NonlinearSolveBase.InternalAPI.reinit!(::NonlinearSolveBase.JacobianCache; p = ...)
  SciMLBase.reinit!(::NonlinearSolveFirstOrder.GeneralizedFirstOrderAlgorithmCache, ...)

The no-init path independently fails on the unfixed source while assigning the remade problem:

MethodError: Cannot `convert` an object of type
  NonlinearProblem{..., SolveOtherDynamicParameters, ...}
to an object of type
  NonlinearProblem{..., SciMLBase.DespecializedParameters, ...}

Passing after

$ julia +1.12 --startup-file=no --project=. -e 'include("test/Core/autodespecialize_tests__item1.jl")'
exit 0

$ NONLINEARSOLVE_TEST_GROUP=Core julia +1.12 --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
AutoDespecialize dynamic parameters | 19 pass / 19 total
PolyAlgorithm best-subalgorithm retention (reinit! retain_best) | 46 pass / 46 total
Testing NonlinearSolve tests passed

$ NONLINEARSOLVE_TEST_GROUP=QA julia +1.12 --startup-file=no --project=. -e 'using Pkg; Pkg.test()'
QA | 28 pass / 28 total
Testing NonlinearSolve tests passed

I also removed OrdinaryDiffEq's local wrapping expression in a disposable current-master checkout, path-developed this branch's NonlinearSolve and NonlinearSolveBase, and ran the ModelingToolkit Robertson FBDF + NonlinearSolveAlg reproducer:

ModelingToolkit v11.40.0
NonlinearSolve v4.28.0 <local branch>
NonlinearSolveBase v2.48.0 <local branch>
OrdinaryDiffEqBDF v2.4.5 <local current master>
OrdinaryDiffEqNonlinearSolve v2.9.1 <local current master>
GENERIC_REINIT_ROBERTSON_SUCCESS
exit 0
$ julia +1.12 --startup-file=no -m Runic --check <changed Julia files>
exit 0
$ typos --diff <changed paths>
exit 0
$ git diff --check
exit 0

Not verified

GPU, prerelease Julia, docs, and the full Everything group were not run locally. No public name, docstring, or documentation was changed.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 28, 2026 09:06
@ChrisRackauckas
ChrisRackauckas merged commit d1cd765 into SciML:master Aug 28, 2026
88 of 96 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Drop stale [compat] majors older than one year (#1198)
- Drop @fastmath from L2_NORM/Linf_NORM so isfinite guards survive (#1182)
- Release 4.28.1 (#1202)
- Release 2.48.1 (#1206)
- Align QA NLsolve compat with root project (#1205)
- Widen NonlinearSolveBase LogExpFunctions compat to 0.3.28–1 (#1203)
- Continue polyalgorithm after stalled least-squares solves (#1204)
- Align Wrappers NLsolve compat with root project (#1208)
- Release 2.48.2 (#1210)
- Preserve despecialized parameters during reinit (#1199)



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]>
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- Drop stale [compat] majors older than one year (#1198)
- Drop @fastmath from L2_NORM/Linf_NORM so isfinite guards survive (#1182)
- Release 4.28.1 (#1202)
- Release 2.48.1 (#1206)
- Align QA NLsolve compat with root project (#1205)
- Widen NonlinearSolveBase LogExpFunctions compat to 0.3.28–1 (#1203)
- Continue polyalgorithm after stalled least-squares solves (#1204)
- Align Wrappers NLsolve compat with root project (#1208)
- Release 2.48.2 (#1210)
- Preserve despecialized parameters during reinit (#1199)



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