Add DEIIPFunctionWrapper structs to reduce stack trace length#1285
Open
ChrisRackauckas-Claude wants to merge 3 commits intoSciML:masterfrom
Open
Add DEIIPFunctionWrapper structs to reduce stack trace length#1285ChrisRackauckas-Claude wants to merge 3 commits intoSciML:masterfrom
ChrisRackauckas-Claude wants to merge 3 commits intoSciML:masterfrom
Conversation
44e2b75 to
9abe1d5
Compare
…ngth
Replace type aliases with actual wrapper structs that hide the verbose
FunctionWrappersWrapper type parameters from stack traces.
Before (1,077 chars for ForwardDiff wrapper):
FunctionWrappersWrappers.FunctionWrappersWrapper{Tuple{FunctionWrappers.FunctionWrapper{Nothing, Tuple{...}}, ...}, false}
After (~350 chars):
DiffEqBase.DEIIPFunctionWrapperForwardDiff{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Dual{...}}, Vector{Dual{...}}, Dual{...}}
New types (exported from DiffEqBase):
- DEIIPFunctionWrapper{duType, uType, pType, tType}: 1-wrapper struct
for solvers without ForwardDiff (e.g. Tsit5, Verner)
- DEIIPFunctionWrapperVF64{pType}: VF64-specialized alias
- DEIIPFunctionWrapperForwardDiff{T1,T2,T3,T4,dT1,dT2,dT4}: 4-wrapper
struct for ForwardDiff-aware solvers (Rosenbrock, implicit methods)
- AnyFunctionWrapper: Union type for isa checks
- wrapfun_iip_simple(ff, du, u, p, t): constructor that avoids
ForwardDiff extension backedges
ForwardDiff extension provides:
- DEIIPFunctionWrapperForwardDiffVF64{pType}: VF64-specialized alias
- ODEDualTag, ODEDualType: named aliases for ODE dual types
Addresses DifferentialEquations.jl#1128.
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
9abe1d5 to
18ff0f7
Compare
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.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
Addresses part of SciML/DifferentialEquations.jl#1128 (FunctionWrappersWrapper bloat in stack traces).
Introduces wrapper structs (not type aliases) around
FunctionWrappersWrapperto dramatically shorten type strings in stack traces:Key insight:
const Foo{T} = Bar{T}type aliases do NOT change howtypeof(x)prints in Julia — only newstructtypes reduce the printed representation.New structs (defined in DiffEqBase, exported)
DEIIPFunctionWrapper{duType, uType, pType, tType}— wraps aFunctionWrappersWrapperwith 1FunctionWrapperfor solvers that don't use ForwardDiff (e.g. Tsit5, Verner)DEIIPFunctionWrapperForwardDiff{T1, T2, T3, T4, dT1, dT2, dT4}— wraps aFunctionWrappersWrapperwith 4FunctionWrapperentries covering base/dual-state/dual-time/dual-both argument combinationsAnyFunctionWrapper—Union{FunctionWrappersWrapper, DEIIPFunctionWrapper, DEIIPFunctionWrapperForwardDiff}forisachecksDEIIPFunctionWrapperVF64{pType}— VF64-specialized alias forDEIIPFunctionWrapperwrapfun_iip_simple(ff, du, u, p, t)— constructor that always creates a 1-wrapper, avoiding ForwardDiff extension backedgesIn ForwardDiff extension (access via
Base.get_extension)DEIIPFunctionWrapperForwardDiffVF64{pType}— VF64-specialized aliasODEDualTag—ForwardDiff.Tag{OrdinaryDiffEqTag, Float64}ODEDualType—ForwardDiff.Dual{ODEDualTag, Float64, 1}Changes to existing code
solve.jl: UsesAnyFunctionWrapperinstead ofFunctionWrappersWrappers.FunctionWrappersWrapperforisachecks; useswrapfun_iip_simplefor the non-ForwardDiff pathwrapfun_iip(ff, inputs::Tuple{T1,T2,T3,T4})now returnsDEIIPFunctionWrapperForwardDiff(inner)instead of rawFunctionWrappersWrapper(f::DEIIPFunctionWrapper)(args...) = f.fw(args...)isfunctionwrapperandunwrapped_fUsage example (downstream package)
Test plan
function_wrapper_aliases.jltest file (27 tests) verifying:DEIIPFunctionWrapperstruct creation and type matchingDEIIPFunctionWrapperVF64alias with bothVector{Float64}andNullParametersODEDualTagandODEDualTypeequal the expected ForwardDiff typesDEIIPFunctionWrapperForwardDiffstruct fromwrapfun_iipDEIIPFunctionWrapperForwardDiffVF64aliasAnyFunctionWrapperunion matchingisfunctionwrapperwrapfun_iip_simplealways produces 1-wrapper even with ForwardDiff loadedPkg.test()passes (all existing tests unaffected)🤖 Generated with Claude Code