Skip to content

Skip FWW wrapping in promote_f when already wrapped#3335

Closed
ChrisRackauckas-Claude wants to merge 3 commits intoSciML:masterfrom
ChrisRackauckas-Claude:skip-double-wrap
Closed

Skip FWW wrapping in promote_f when already wrapped#3335
ChrisRackauckas-Claude wants to merge 3 commits intoSciML:masterfrom
ChrisRackauckas-Claude:skip-double-wrap

Conversation

@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor

Summary

  • Guard promote_f against double-wrapping when f.f is already a FunctionWrappersWrapper
  • Moves the !(f.f isa FWW) check to the top of the condition, applying to both AutoSpecialize and FunctionWrapperSpecialize paths
  • Both the ForwardDiff-aware path (Val{true}) and simple path (Val{false}) are guarded
  • Bump DiffEqBase: 6.214.1 → 6.215.0

Context

SciML/ModelingToolkit.jl#4426 will pre-wrap ODEFunction.f with FWW at construction time (when all types are known), rather than deferring to solve time. Without this guard, promote_f would wrap the already-wrapped FWW in another FWW.

Test plan

  • CI passes — existing behavior is unchanged since f.f is never a FWW before promote_f today
  • No regressions when MTK pre-wraps

🤖 Generated with Claude Code

ChrisRackauckas-Claude pushed a commit to ChrisRackauckas-Claude/ModelingToolkit.jl that referenced this pull request Apr 3, 2026
When AutoSpecialize is active and u0/p/t are available, wrap f with
DiffEqBase.wrapfun_iip at ODEFunction construction time. This erases
the GeneratedFunctionWrapper type early, before DiffEqBase.promote_f
runs at solve time.

Requires DiffEqBase >= 6.215.0 (SciML/OrdinaryDiffEq.jl#3335) which
guards promote_f against double-wrapping already-wrapped functions.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
ChrisRackauckas and others added 2 commits April 4, 2026 07:36
When MTK pre-wraps ODEFunction.f with FunctionWrappersWrapper at
construction time, promote_f should not double-wrap. Move the
already-wrapped check to the top of the condition so it applies
to both AutoSpecialize and FunctionWrapperSpecialize paths.

Also bump DiffEqBase: 6.214.1 → 6.215.0

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
The BrownFullBasicInit DAE initialization was passing OrdinaryDiffEqTag
to NonlinearSolve via `NewtonRaphson(autodiff=alg_autodiff(...))`, but
NonlinearSolveBase's AutoSpecialize wraps functions with NonlinearSolveTag
dual signatures. This tag mismatch caused "No matching function wrapper
was found!" errors for DAEProblem solves with DFBDF.

Fix by routing through `default_nlsolve` (which uses `_tagged_autodiff`
with no custom tag) so NonlinearSolveBase's `standardize_forwarddiff_tag`
can properly stamp the NonlinearSolveTag.

Also bump NonlinearSolveFirstOrder compat in OrdinaryDiffEqNewmark to
allow v2.x, and bump OrdinaryDiffEqNonlinearSolve to v1.26.0.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude
Copy link
Copy Markdown
Contributor Author

Rebased and updated

Rebased on master (TaylorSeries merge already included). Added fixes:

Fix DAE initialization tag mismatch (pre-existing bug): BrownFullBasicInit for DAEProblems was passing OrdinaryDiffEqTag directly to NewtonRaphson, but NonlinearSolveBase's AutoSpecialize wraps functions with NonlinearSolveTag dual signatures. This caused "No matching function wrapper was found!" errors for solve(DAEProblem(...), DFBDF()).

Fix routes through default_nlsolve (which uses _tagged_autodiff with no custom tag), letting standardize_forwarddiff_tag stamp the correct NonlinearSolveTag.

Compat updates:

  • OrdinaryDiffEqNonlinearSolve: 1.25.0 → 1.26.0
  • NonlinearSolveFirstOrder compat in OrdinaryDiffEqNewmark: "1.9.0""1.9.0, 2"

Verified locally: DAE solve with DFBDF (IIP + OOP), ODE solves with Tsit5/Rosenbrock23/FBDF all pass.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.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.

2 participants