Pass OrdinaryDiffEqTag to NonlinearSolve in DAE initialization#3068
Closed
ChrisRackauckas-Claude wants to merge 1 commit into
Closed
Pass OrdinaryDiffEqTag to NonlinearSolve in DAE initialization#3068ChrisRackauckas-Claude wants to merge 1 commit into
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
Instead of using bare `AutoForwardDiff()` in `default_nlsolve`, pass
`AutoForwardDiff{1}(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u)))` so
NonlinearSolve's internal ForwardDiff uses a tag matching the pre-compiled
FunctionWrapper variants. This addresses the type-instability introduced by
unwrapping in SciML#3066.
Also fixes 3 OOP `default_nlsolve` call sites that had swapped arguments
and missing `isAD` parameter, and removes `unwrapped_f` from OOP methods
where it is not needed.
Closes SciML#3067
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Feb 22, 2026
Instead of hardcoding AutoForwardDiff{1}, use the algorithm's actual
ForwardDiff chunk size from SciMLBase.forwarddiff_chunksize. Thread the
chunk size through default_nlsolve and _tagged_autodiff so NonlinearSolve
uses matching Dual types.
Also incorporates PR SciML#3068 fixes:
- Pass OrdinaryDiffEqTag to NonlinearSolve for correct ForwardDiff tag
- Fix 3 OOP default_nlsolve call sites with swapped arguments
- Remove unnecessary unwrapped_f from OOP methods
Closes SciML#3067
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
2 tasks
Contributor
Author
|
Superseded by #3069 which incorporates this PR's changes with the correct algorithm chunk size instead of hardcoding |
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Feb 22, 2026
Instead of hardcoding AutoForwardDiff{1}, use the algorithm's actual
ForwardDiff chunk size from SciMLBase.forwarddiff_chunksize. Thread the
chunk size through default_nlsolve and _tagged_autodiff so NonlinearSolve
uses matching Dual types.
Also incorporates PR SciML#3068 fixes:
- Pass OrdinaryDiffEqTag to NonlinearSolve for correct ForwardDiff tag
- Fix 3 OOP default_nlsolve call sites with swapped arguments
- Remove unnecessary unwrapped_f from OOP methods
Closes SciML#3067
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
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.
Summary
AutoForwardDiff{1}(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u)))instead of bareAutoForwardDiff()in all 6default_nlsolveoverloads, so NonlinearSolve's internal ForwardDiff uses a tag matching the pre-compiledFunctionWrappervariantsdefault_nlsolvecall sites that had swapped arguments (nlprob, u0instead ofu0, nlprob) and missingisADparameterunwrapped_ffrom 2 OOP ODEProblem methods (OOP functions don't useFunctionWrappersWrapper)unwrapped_ffor 2 IIP ODEProblem methods where FunctionWrapper type mismatches still occur during nested ADCloses #3067
Context
PR #3066 fixed
NoFunctionWrapperFoundErrorby unwrappingFunctionWrappersWrapper, which introduced type-instabilities. This PR addresses that by passing the correct ForwardDiff tag to NonlinearSolve so it matches the pre-compiled variants, reducing the need for unwrapping.The
unwrapped_fcalls remain for IIP ODEProblem methods because NonlinearSolve may evaluate the closure with types (e.g., strippedFloat64during internal line search) that don't match any pre-compiledFunctionWrappervariant, regardless of the tag. For OOP methods,FunctionWrappersWrapperis not used so unwrapping was unnecessary.Test plan
dae_rosenbrock_ad_tests.jl: 6 pass, 3 error — identical to baseline (pre-existing IIP+AutoForwardDiff failures in main solver'sjacobian!, not in DAE initialization)🤖 Generated with Claude Code