Repository navigation
Return u-field tangent for structural VectorOfArray cotangents - #656
Merged
ChrisRackauckas merged 1 commit intoSep 22, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
Zygote's `literal_getproperty` adjoint for `A.u` received per-element cotangents and always rebuilt a VectorOfArray/DiffEqArray from them. When the elements are structural tangents — e.g. the per-solution NamedTuples produced when differentiating `ensemble_sol.u` — the VectorOfArray constructor fails on `ndims(::NamedTuple)`, breaking ensemble differentiation (SciML/DifferentialEquations.jl#1149). Detect non-numeric structural elements (anything that is not nothing, an AbstractZero, an AbstractArray or a Number) and return the `u`-field tangent `(; u = collect(d))` instead. Numeric cotangents keep the existing VectorOfArray/DiffEqArray behavior. Generated with [Devin](https://devin.ai) Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Agent-Harness: Devin CLI 3000.10.31 Agent-Model: SWE-2 Max Agent-Session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_d4203d25c3424828.md
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 23, 2026
Ships #656: the u-field tangent is returned for structural VectorOfArray cotangents. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude <noreply@anthropic.com> Agent-Harness: Claude Code 2.1.273 Agent-Model: claude-opus-5[1m] Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL)
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 23, 2026
Ships #656: the u-field tangent is returned for structural VectorOfArray cotangents. Agent-Harness: Claude Code 2.1.273 Agent-Model: claude-opus-5[1m] Agent-Session: 6a01e420-3436-4518-83cc-6cd853283cfb (local transcript; this harness publishes no conversation URL) Co-authored-by: Claude <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
Zygote's
literal_getpropertyadjoint forA.u(vofa_u_adjoint) received per-element cotangents and always rebuilt aVectorOfArray/DiffEqArrayfrom them. When the elements are structural tangents — e.g. the per-solutionNamedTuples produced when differentiatingensemble_sol.ufor anEnsembleSolution— theVectorOfArrayconstructor fails onndims(::NamedTuple), breaking ensemble differentiation (SciML/DifferentialEquations.jl#1149, where Zygote threwMethodErrorfromVectorOfArray(vec::Vector{Any})while ForwardDiff computed the gradient correctly).vofa_u_adjointnow detects non-numeric structural elements (anything that is notnothing, anAbstractZero, anAbstractArrayor aNumber) and returns theu-field tangent(; u = collect(d))instead. Numeric cotangents keep the existingVectorOfArray/DiffEqArraybehavior; mixed vectors withnothing/AbstractZeroholes still hit the numeric path as before.Test plan
test/AD/adjoints.jl:vofa_u_adjointonAny[(; u = ..., t = ...), nothing, (; ...)]for bothVectorOfArrayandDiffEqArraymust return aNamedTuplewith the expected.u.Fails before the fix (revert this patch and run
test/AD/adjoints.jl):Passes after:
julia --project=test/AD test/AD/adjoints.jlexits 0 (all@tests silent on success).sol.t[end]gradient in SciMLSensitivity (companion PR) matches ForwardDiff to ~1e-5 under bothEnsembleSerialandEnsembleThreads.🤖 Generated with Devin (harness: Devin CLI 3000.10.31, model: SWE-2 Max, session: local transcript /home/crackauc/.local/share/devin/cli/summaries/history_d4203d25c3424828.md)