Repository navigation
Don't re-despecialize an already concretized AutoDespecialize function - #4599
Conversation
`promote_f` widens the bounded type parameters of an `AutoDespecialize`
function (`_despecialize_auxiliary_functions`) and relies on the `@set`s of
the wrapping step to narrow them back. For a function that is already wrapped
the wrapping step is skipped, so concretizing a concretized problem returned
the widened type (`initialization_data::Union{Nothing, OverrideInitData}`).
This was masked because SciMLBase's `constructorof` reset the specialization
to the default on every `@set`, so a concretized problem was no longer
`AutoDespecialize`. Once the specialization survives (SciML/SciMLBase.jl#1606),
`despecialized_p_test.jl` catches it. Skip the auxiliary despecialization for
an `f` whose RHS is already wrapped; this works with either SciMLBase.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JNAfKDURNdkubVjmftigPP
`_is_concretized` read `f.f`, which `DynamicalODEFunction` (`f1`/`f2`) does not have, so every `AutoDespecialize` `DynamicalODEProblem` threw a `FieldError` when concretized. It also excluded `SDEFunction` outright, so an SDE wrapped by the non-ForwardDiff path was despecialized again on a second concretization, re-widening its `ID` parameter. Treat a function without an `f` field as not wrapped, and an `SDEFunction` as wrapped when both drift and diffusion are, matching the skip condition of the wrapping step. Add an idempotency testset covering a plain `AutoDespecialize` ODE (no jac/tgrad, which the existing test relies on), an SDE on the non-ForwardDiff path and a `DynamicalODEProblem`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JNAfKDURNdkubVjmftigPP
`wrapfun_oop` threw `NoRecompileArgumentError(IT)` unqualified, but the error type lives in DiffEqBase, so the unsupported-signature path raised an `UndefVarError` instead of the intended error. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01JNAfKDURNdkubVjmftigPP
| # Whether `promote_f` already wrapped `f` on an earlier concretization. The auxiliary | ||
| # despecialization widens the bounded type parameters, which only the `@set`s of the | ||
| # wrapping step narrow back, and that step is skipped for a wrapped `f`. So an `f` that | ||
| # is already wrapped must not be despecialized again, or concretizing a concretized | ||
| # problem would change its type. | ||
| # Functions without an `f` field (e.g. `DynamicalODEFunction`, which stores `f1`/`f2`) | ||
| # are never wrapped here. |
There was a problem hiding this comment.
using DiffEqBase, SciMLBase
using DiffEqBase: promote_f, _despecialize_auxiliary_functions
const AD = SciMLBase.AutoDespecialize
rhs!(du, u, p, t) = (du[1] = -p.rate * u[1]; nothing)
u0, p, t = [1.0], (; rate = 0.5), 0.0
initT(f) = fieldtype(typeof(f), :initialization_data)
f0 = ODEFunction{true, AD}(rhs!)
initT(f0) # Nothing
initT(_despecialize_auxiliary_functions(f0)) # Union{Nothing, OverrideInitData}
f1, p1 = promote_f(f0, Val(AD), u0, p, t, Val(false))
initT(f1) # Nothing: unwrapped_f rebuilds from typeof(field), narrowing it back
# Second call before this PR: it widens again, then the wrap step returns early
# because f1.f isa FunctionWrappersWrapper, so nothing narrows it back.
initT(_despecialize_auxiliary_functions(f1)) # Union{Nothing, OverrideInitData}
f2, _ = promote_f(f1, Val(AD), u0, p1, t, Val(false)) # with this PR
typeof(f2) === typeof(f1) # true(code by Claude Opus 5.5)
is the problem that wrapping undoes the widening? on the ODE/SDE wrap path an AutoDespecialize ends up with a concrete initialization_data type, which seems unwanted. is that what you are referring to?
Verdict: changes needed before merge (reviewed at This makes repeated AutoDespecialize concretization preserve its type and fixes the ForwardDiff extension's unsupported-signature exception. The main regression tests and local Core suite pass, but the separate exception fix needs a committed regression test and the unmatched SciMLSensitivity Core3 failure needs resolution before merge. Risk assessment
Local verification, Julia 1.12.7:
CI comparison (read failed job logs; default branch comparison is master 4e8d61f unless stated):
No new dependency or public name, no test deletion/skipping/tolerance relaxation, and no new cross-package production internal-API access appears in the diff. These are intended bug corrections rather than a new public API requiring a major bump. The full downstream AD suite and Julia lts were not run locally. Findings
Produced by an AI agent: Codex CLI (Mac), version unavailable; model gpt-6-astra. Conversation: local session ID Push a fix and the PR is reviewed again automatically at the new head. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-opus-5-5[1m] (fleet master); review by Codex CLI (Mac) / gpt-6-astra |
An out-of-place `FunctionWrapperSpecialize` problem with argument types that have no precompiled wrapper signature must raise `NoRecompileArgumentError`. Before the previous commit it raised an `UndefVarError`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
SciMLBase 3.56.1 (SciML/SciMLBase.jl#1616) makes `remake` keep the narrowed metadata types when a concretized `AutoDespecialize` function is replaced by a re-widened one. That hides a non-idempotent `promote_f` from the problem-level checks, so these now pass without the fix. Also compare the output of the `promote_f` call of `get_concrete_problem` on an already concretized problem directly, for the plain ODE and the SDE cases. The `DynamicalODEFunction` case is left at the problem level: there `promote_f` widens `ID` on every pass and `remake` narrows it back, so its output never matches the concretized function. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Re the automated review at 1. Regression test for the exception fix ( 2. SciMLSensitivity Core3: the push reruns it. The same signal 11 in LLVM's LoopUnrollPass at Also ( Verified locally with Julia 1.12.7 and SciMLBase
Runic Written by Claude Code (claude-opus-5-5[1m]) on behalf of Sebastian. |
* Bump DiffEqBase to 7.21.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqBDF to 2.4.12 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSDIRK to 2.9.7 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqRosenbrock to 2.7.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqLowOrderRK to 2.2.6 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqTsit5 to 2.1.5 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqVerner to 2.4.2 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json * Bump OrdinaryDiffEqSymplecticRK to 2.2.3 Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.11.3 (Mac) Agent-Model: Fusion (claude-opus-5-5 medium + swe-2 medium) Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/helpful-exception.json --------- Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
promote_fis not idempotent for an already concretizedAutoDespecializefunction:AutoDespecialize,_despecialize_auxiliary_functionsrunsSciMLBase.widen_bounded_type_params, which boxes the bounded type parameters (initialization_data,nlstep_data).@sets of the wrapping step narrow them back.FunctionWrappersWrapper, the wrapping step is skipped. So concretizing a concretized problem returns a different, widened function type.This has been masked by SciMLBase: its
ConstructionBase.constructorofresets the specialization toDEFAULT_SPECIALIZATIONon every@set. After the first concretization the problem is no longerAutoDespecialize(it isAutoSpecializewhile carryingDespecializedParameters), so the second pass never takes the despecialize branch.SciML/SciMLBase.jl#1606 makes
constructorofkeep the specialization. With it,test/despecialized_p_test.jl("AutoDespecialize uses the dynamic parameter barrier") fails ontypeof(remade) === typeof(first_prob).Change: skip the auxiliary despecialization for an
fwhose RHS is already wrapped (_is_concretized), in bothpromote_fmethods.Follow-ups found by a broader audit (a concretize-twice matrix over ODE/SDE/DAE/DDE/SDDE/Discrete/Split/Dynamical/RODE × specialization levels × {SciMLBase 3.55.0, #1606} × {DiffEqBase 7.21.2, this branch}):
_is_concretizednow handles functions without anffield. The first version threw aFieldErrorfor everyAutoDespecializeDynamicalODEProblem/SecondOrderODEProblem.SDEFunctionas wrapped when both drift and diffusion are. SDEs on the non-ForwardDiff path (e.g.EM) were not idempotent before this PR either: theIDparameter got re-widened.AutoDespecializeODE (the existing test has jac/tgrad, whose@sets hid this), an SDE on the non-ForwardDiff path, and aDynamicalODEProblem.NoRecompileArgumentErrorinDiffEqBaseForwardDiffExt. The unsupported-signature path raised anUndefVarErrorinstead of the intended error.With these,
despecialized_p_test.jlpasses completely with both SciMLBase versions, the matrix shows no non-idempotent case, and 14 related DiffEqBase test files give identical results across the combos.Verified locally (Julia 1.12.5):
despecialized_p_test.jlpasses completely with this change, with both released SciMLBase 3.55.0 and SciML/SciMLBase.jl#1606. It works with either SciMLBase version, so it can be released before #1606. The existing test already covers the case once #1606 is in.CI notes: the failing jobs are all unrelated to this change:
high_level_solve.jl:94–101, the same lines as master's DiffEqBase downgrade job: those tests expect callback erasure, which is gated to Julia ≥ 1.12.Core3/default_alg_diff.jl:21. That test uses a plainAutoSpecializeproblem, for which the new guard (despecialize && !_is_concretized(f)) is never evaluated, so the code that ran is identical to master's; master's Core3 passes. It looks like an intermittent compiler crash; a re-run should confirm it.Written by Claude Code on Sebastian's behalf.
🤖 Generated with Claude Code Opus 5.5 (1M context)
https://claude.ai/code/session_01JNAfKDURNdkubVjmftigPP