Skip to content

Pass OrdinaryDiffEqTag to NonlinearSolve in DAE initialization#3068

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:pass-tag-to-nlsolve-dae-init
Closed

Pass OrdinaryDiffEqTag to NonlinearSolve in DAE initialization#3068
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:pass-tag-to-nlsolve-dae-init

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Summary

  • Pass AutoForwardDiff{1}(ForwardDiff.Tag(OrdinaryDiffEqTag(), eltype(u))) instead of bare AutoForwardDiff() in all 6 default_nlsolve overloads, so NonlinearSolve's internal ForwardDiff uses a tag matching the pre-compiled FunctionWrapper variants
  • Fix 3 OOP default_nlsolve call sites that had swapped arguments (nlprob, u0 instead of u0, nlprob) and missing isAD parameter
  • Remove unnecessary unwrapped_f from 2 OOP ODEProblem methods (OOP functions don't use FunctionWrappersWrapper)
  • Keep unwrapped_f for 2 IIP ODEProblem methods where FunctionWrapper type mismatches still occur during nested AD

Closes #3067

Context

PR #3066 fixed NoFunctionWrapperFoundError by unwrapping FunctionWrappersWrapper, 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_f calls remain for IIP ODEProblem methods because NonlinearSolve may evaluate the closure with types (e.g., stripped Float64 during internal line search) that don't match any pre-compiled FunctionWrapper variant, regardless of the tag. For OOP methods, FunctionWrappersWrapper is not used so unwrapping was unnecessary.

Test plan

  • OrdinaryDiffEqNonlinearSolve tests pass (29/29)
  • OrdinaryDiffEqRosenbrock dae_rosenbrock_ad_tests.jl: 6 pass, 3 error — identical to baseline (pre-existing IIP+AutoForwardDiff failures in main solver's jacobian!, not in DAE initialization)

🤖 Generated with Claude Code

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>
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor Author

Superseded by #3069 which incorporates this PR's changes with the correct algorithm chunk size instead of hardcoding AutoForwardDiff{1}.

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>
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.

Pass correct ForwardDiff tag to NonlinearSolve in DAE initialization instead of unwrapping

2 participants