Repository navigation
Fix getproperty(::NonlinearProblem) rrule to emit full-width cotangents - #1382
Merged
ChrisRackauckas merged 2 commits intoJun 11, 2026
Conversation
…rrule
The rrule returned a single-field NamedTuple like (p = dp,) as the problem
cotangent. Zygote.accum cannot combine such partial NamedTuples with
full-width cotangents for the same problem produced by other pullbacks
(or with partials for a different field), throwing
'ArgumentError: ... keys must be a subset of ... keys'.
This broke test/downstream/remake_autodiff.jl ('split = false') once
ModelingToolkitBase 1.42.0 changed 'initializeprobmap' (SciML/ModelingToolkit.jl
commit 5236ce3d7), making the trivial-initialization NonlinearProblem receive
cotangents from two pullback paths in SciMLBase.get_initial_values.
Returning a Tangent{typeof(x)} instead lets Zygote canonicalize it to a
full-width NamedTuple over all problem fields, which accumulates cleanly
in any order. A der === nothing / AbstractZero cotangent now returns
ZeroTangent() instead of zero_tangent(x), since a MutableTangent also
cannot be accumulated with NamedTuple cotangents.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]>
Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Chris Rackauckas <[email protected]>
ChrisRackauckas
marked this pull request as ready for review
June 11, 2026 08:33
ChrisRackauckas
approved these changes
Jun 11, 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.
Important
This PR should be ignored until reviewed by @ChrisRackauckas.
Fixes the
test/downstream/remake_autodiff.jl("split = false") failure currently on master (also visible as the red Downstream CI on master):Root cause
The
getproperty(::NonlinearProblem)rrule inSciMLBaseChainRulesCoreExtreturned a single-field NamedTuple like(p = dp,)as the problem cotangent.Zygote.accumcannot combine such partial NamedTuples with full-width cotangents for the same problem produced by other pullbacks (or with a partial for a different field) — it requires one side's keys to be a subset of the other's and throws theArgumentErrorabove otherwise.This was latent until ModelingToolkitBase 1.42.0 changed
initializeprobmap(SciML/ModelingToolkit.jl commit 5236ce3d7), after which the trivial-initializationNonlinearProblemreceives cotangents from two pullback paths inSciMLBase.get_initial_valuesduring Zygote differentiation ofremaked MTKODEProblems — i.e. the failure is exposed by a dependency update, not by a SciMLBase commit (the same SciMLBase v3.17.0 source fails with current deps, verified).Fix
Return a
Tangent{typeof(x)}instead: Zygote canonicalizesTangents to full-width NamedTuples over all struct fields, which accumulate cleanly in any order. Ader === nothing/AbstractZerocotangent now returnsZeroTangent()instead ofzero_tangent(x), since aMutableTangentalso cannot be accumulated with NamedTuple cotangents.How this was pinned down
aced3e87b(Jul 2025, v2.103.1) but stayed latent.lb/ubremake changes (v3.17.0 source + current Manifest fails identically).continue_on_error = true, and the Julia "1"/"pre" jobs skip this testset (VERSION < v"1.12"gate — only the LTS job runs it).Verification
remake+BacksolveAdjoint(autojacvec=ZygoteVJP())via DIAutoZygote, extracted from the failing testset): fails on unmodified master, succeeds with this fix.test/nonlinearproblem_zygote.jl) covering cotangent shape and multi-field/multi-remake accumulation: pass on Julia 1.10, 1.11, and 1.12.remake_autodiff.jl"split = false" downstream testset passes with the fix (see CI / verification log).Related: #1381 (ensemble Zygote adjoint fixes) documents encountering this same failure on master while validating that PR; the two PRs are independent.
Side note for maintainers: the same partial-cotangent hazard would apply to
NonlinearLeastSquaresProblemif it ever gains a similargetpropertyrrule (it currently has none).🤖 Generated with Claude Code