Handle despecialized parameter cotangents in solution AD - #1574
Draft
ChrisRackauckas-Claude wants to merge 1 commit into
Draft
Handle despecialized parameter cotangents in solution AD#1574ChrisRackauckas-Claude wants to merge 1 commit into
ChrisRackauckas-Claude wants to merge 1 commit into
Conversation
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://chatgpt.com/codex/tasks/01a03a17-ad6f-7131-82fc-d0fd57ea6512
This was referenced Sep 1, 2026
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.
Ignore this PR until it has been reviewed by @ChrisRackauckas.
What changed and why
Unwrap a
ChainRulesCore.Tangent{DespecializedParameters}before the observableODESolutionpullback remakes its problem. The tangent'sparamscomponent is the cotangent for the original parameter object; passing the outer structural tangent intoremakeinstead 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
AutoSpecializetoAutoDespecialize. 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 toremake, leading to: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: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:
QA passes with the system Python selected to avoid a broken generated CondaPkg environment on this host:
Runic, typos, and
git diff --checkpass for the changed file.Independent failures / not verified
The full local DownstreamAD group proceeds past
Autodiff Remake, then fails in the pre-existingobservables_autodiff.jlfailures: three Mooncake_copy_outputNamedTuple 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_nothingerror. 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