Unwrap FunctionWrappersWrapper in DAE init closures#3066
Merged
ChrisRackauckas merged 1 commit intoFeb 22, 2026
Merged
Conversation
DiffEqBase SciML#1284 enabled AutoSpecialize (FunctionWrappers wrapping) for mass matrix ODEProblems. The pre-compiled FunctionWrapper variants use OrdinaryDiffEqTag with chunk size 1, coordinated with the ODE solver's ForwardDiff via prepare_ADType. However, _initialize_dae! passes f into NonlinearSolve closures where NonlinearSolve's internal ForwardDiff uses its own tag and chunk size, causing NoFunctionWrapperFoundError. Fix by unwrapping f at the top of each ODEProblem _initialize_dae! method. This is a no-op when AutoSpecialize is not active. The solver's hot path in perform_step! still uses the wrapped version from integrator.f. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Feb 22, 2026
Closed
Contributor
Author
Update: Added
|
ChrisRackauckas-Claude
pushed a commit
to ChrisRackauckas-Claude/OrdinaryDiffEq.jl
that referenced
this pull request
Feb 22, 2026
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>
2 tasks
Contributor
Author
|
Pushed two additional commits:
Depends on SciMLBase#1244 and DiffEqBase#1287. |
2 tasks
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
FunctionWrappersWrapperfromfat the top of eachODEProblem_initialize_dae!method viaSciMLBase.unwrapped_f(f)Problem
DiffEqBase #1284 (v6.208.0) enabled AutoSpecialize for mass matrix ODEProblems by removing the
f.mass_matrix isa UniformScalingguard frompromote_f. This wrapsf.fin aFunctionWrappersWrapperwith 4 pre-compiled variants coordinated with the ODE solver's ForwardDiff (tag =OrdinaryDiffEqTag, chunk size = 1).However,
_initialize_dae!(bothBrownFullBasicInitandShampineCollocationInit) passesfinto closures that NonlinearSolve differentiates through with its own ForwardDiff. NonlinearSolve's duals have a different tag and chunk size, so none of the 4 pre-compiled variants match, causingNoFunctionWrapperFoundError.This breaks the
OrdinaryDiffEqRosenbrockDAE AD tests (dae_rosenbrock_ad_tests.jl) on all Julia versions.Fix
Call
SciMLBase.unwrapped_f(f)after destructuring(; p, t, f) = integratorin the 4ODEProblemmethods of_initialize_dae!. This replaces theFunctionWrappersWrapperwith the raw function for DAE initialization only. The solver's hot path inperform_step!still uses the wrapped version fromintegrator.f.This is a no-op when AutoSpecialize is not active (i.e., when
f.fis not aFunctionWrappersWrapper).Test plan
OrdinaryDiffEqRosenbrocktests pass (specificallydae_rosenbrock_ad_tests.jlwithAutoForwardDiff)🤖 Generated with Claude Code