Skip to content

Handle despecialized parameter cotangents in solution AD - #1574

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/downstreamad-promote-type
Sep 6, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix/downstreamad-promote-type

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Ignore this PR until it has been reviewed by @ChrisRackauckas.

What changed and why

Unwrap a ChainRulesCore.Tangent{DespecializedParameters} before the observable ODESolution pullback remakes its problem. The tangent's params component is the cotangent for the original parameter object; passing the outer structural tangent into remake instead reaches ModelingToolkit initialization as if it were a primal parameter value.

This is a three-line extension fix. It adds no public API, dependency, documentation, or version change.

Root cause

ModelingToolkit commit SciML/ModelingToolkit.jl@5585668 from SciML/ModelingToolkit.jl#4919 changed generated problems from AutoSpecialize to AutoDespecialize. The exact registered boundary is ModelingToolkitBase 1.65.0 to 1.66.0, as independently established in #1545.

The observable pullback consequently receives a structural tangent around DespecializedParameters. SciMLBase's rrule passed that wrapper directly to remake, leading to:

MethodError: no method matching promote_type_with_nothing(
    ::Type{Float64},
    ::ChainRulesCore.Tangent{SciMLBase.DespecializedParameters,
        @NamedTuple{params::Vector{Float64}}})

The ModelingToolkit error is downstream fallout: the invalid primal value is created at the SciMLBase rrule/remake boundary, so the fix belongs here.

Failing before

On clean SciMLBase master 3d95609f7dc1c86a8fded41b9d357bcf25b83ad3, Julia 1.10.12:

GROUP=DownstreamAD julia +1.10.12 --threads=11 --project=. -e 'using Pkg; Pkg.test()'

Test Summary:   | Pass  Error  Broken  Total      Time
Autodiff Remake |    4      1       1      6  32m02.4s
ERROR: Some tests did not pass: 4 passed, 0 failed, 1 errored, 1 broken.

The hosted Julia LTS lane has the same method, argument types, and stack through ODESolution_getindex_pullback: https://github.com/SciML/SciMLBase.jl/actions/runs/33447000990/job/99668297921.

Passing after

The same owning testset passes with the fix:

Test Summary:   | Pass  Broken  Total     Time
Autodiff Remake |    7       1      8  7m14.0s

QA passes with the system Python selected to avoid a broken generated CondaPkg environment on this host:

JULIA_CONDAPKG_BACKEND=Null JULIA_PYTHONCALL_EXE=/usr/bin/python3 \
  GROUP=QA julia +1.10.12 --threads=11 --project=. -e 'using Pkg; Pkg.test()'

Test Summary: | Pass  Total     Time
QA            |  121    121  1m34.4s
Testing SciMLBase tests passed

Runic, typos, and git diff --check pass for the changed file.

Independent failures / not verified

The full local DownstreamAD group proceeds past Autodiff Remake, then fails in the pre-existing observables_autodiff.jl failures: three Mooncake _copy_output NamedTuple type assertions, plus two AutoZygote assertions that still assume the pre-AutoDespecialize parameter shape. Those failures do not execute the changed rrule path. The independent AutoZygote fixture assumptions are being handled separately.

The hosted Julia 1 job https://github.com/SciML/SciMLBase.jl/actions/runs/33447000990/job/99668297994 has only the three Mooncake errors; it does not contain this PR's promote_type_with_nothing error. This PR does not claim to fix that lane.

Docs were not built because this PR changes neither public API nor documentation. GPU paths were not run.

🤖 Generated with Claude Code
https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512

@ChrisRackauckas-Claude

ChrisRackauckas-Claude commented Sep 4, 2026 •

Copy link
Copy Markdown
Member Author

Downstream Catalyst docs result at this PR's head (2ee3d2b1e1be9ccef2631c5c1fa071b73fc9899b) against Catalyst master c01cce6d1f384ef1adad7e099ef5efaa5d60a5d9:

TMPDIR="$PWD/.tmp" JULIA_PKG_PRECOMPILE_AUTO=0 GKSwstype=100 timeout 14400 xvfb-run -a julia +1.12 --project=.validation/catalyst-docs-pr1574 --color=no --code-coverage=user docs/make.jl

Exit 1 after 2:52:04. Documenter reported 4 @example errors, all in docs/src/steady_state_functionality/nonlinear_solve.md: lines 83–86, 89–92, and 112–114 each failed directly in solve(...) because NonlinearSolveBase.JacobianCache tried to assign SciMLBase.DespecializedParameters to an MTKParameters-typed field; lines 116–118 were the resulting sol-undefined cascade. No other @example error appeared. The resolved environment used Catalyst 16.4.0, ModelingToolkitBase 1.68.2, NonlinearSolve 4.29.1, NonlinearSolveBase 2.48.0, and this SciMLBase checkout.

This is independent of this PR's solution-AD fix. Follow-up validation found that SciML/NonlinearSolve.jl#1199 fixes public cache reinitialization but not initialization's nested JacobianCache path: the reduced Catalyst/SciMLSensitivity reproducer still fails with NonlinearSolveBase 2.49.2 and current NonlinearSolve master. A focused NonlinearSolveBase fix is under separate local validation. Catalyst's registered docs environment also cannot resolve NonlinearSolveBase 2.49.x until the TimerOutputs 1 compatibility changes in pogudingleb/RationalFunctionFields.jl#61 and sumiya11/Groebner.jl#226 are released.

Catalyst source: SciML/Catalyst.jl@c01cce6

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 6, 2026 10:26
@ChrisRackauckas
ChrisRackauckas merged commit e27c605 into SciML:master Sep 6, 2026
67 of 69 checks passed
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