Skip to content

Handle raw Array cotangents into FlatComponentArray fdata - #421

Merged
ChrisRackauckas merged 2 commits into
SciML:mainfrom
AstitvaAggarwal:mooncake-continuous-adjoint-cotangent
Sep 11, 2026
Merged

ChrisRackauckas merged 2 commits into
SciML:mainfrom
AstitvaAggarwal:mooncake-continuous-adjoint-cotangent

Conversation

@AstitvaAggarwal

@AstitvaAggarwal AstitvaAggarwal commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

increment_and_get_rdata! only had a method for a cotangent matching fdata's own FlatComponentArray type. A ChainRulesCore rrule unaware of ComponentArrays returns a bare Array cotangent instead — this had no matching method and fell through to Mooncake's generic error:

ArgumentError: The fdata type ComponentArrays.ComponentVector{...}, rdata type Mooncake.NoRData,
and tangent type Vector{Float64} combination is not supported with @from_chainrules or @from_rrule.

Hit in practice via SciMLSensitivity's InterpolatingAdjoint/BacksolveAdjoint (SciML/SciMLSensitivity.jl#1427), whose pullback returns a plain gradient vector for a ComponentVector parameter. GaussAdjoint/QuadratureAdjoint don't hit this since their pullback already returns a compatible cotangent shape.

Adds one increment_and_get_rdata! method mirroring the existing raw-Array case for the old FData shape, generalized to the new native FlatComponentArray fdata. N is pinned to match between fdata and cotangent, so a dimensionality mismatch (e.g. a Vector cotangent for a ComponentMatrix fdata) fails to dispatch and errors loudly instead of silently broadcasting against the wrong shape.

Verified against ForwardDiff for a real neural-ODE gradient across GaussAdjoint/InterpolatingAdjoint/QuadratureAdjoint/BacksolveAdjoint (all four now agree to ~1e-8 relative error), and separately confirmed (via is_primitive plus a deliberately-wrong pullback value) that a genuine ComponentMatrix (N=2, constructed with ComponentMatrix(data, Axis(...), Axis(...))) hits this exact code path and computes the correct gradient.

Test plan

  • Added regression test exercising a bare-Array-cotangent @from_rrule round-trip for ComponentVector
  • Added regression test for a genuine ComponentMatrix (N=2), confirmed via is_primitive that it actually exercises this method (not silently bypassed by native differentiation)
  • Added regression test confirming a dimensionality mismatch errors instead of silently broadcasting
  • Verified locally against a real SciMLSensitivity neural-ODE gradient (InterpolatingAdjoint/BacksolveAdjoint) vs ForwardDiff ground truth

increment_and_get_rdata! only had a method for a cotangent matching
fdata's own FlatComponentArray type. A ChainRulesCore rrule unaware of
ComponentArrays (e.g. SciMLSensitivity's InterpolatingAdjoint /
BacksolveAdjoint) instead returns a bare Array cotangent for a
ComponentVector/ComponentMatrix parameter, which had no matching method
and fell through to the generic error.
@AstitvaAggarwal
AstitvaAggarwal marked this pull request as draft September 10, 2026 17:12
@AstitvaAggarwal AstitvaAggarwal changed the title Handle raw Array cotangents into FlatComponentArray fdata Handle raw Array cotangents into FlatComponentArray fdata Sep 10, 2026
…e-mismatch tests

increment_and_get_rdata! for a bare Array cotangent left N unconstrained,
so a dimensionality mismatch (e.g. a Vector cotangent for a ComponentMatrix
fdata) could dispatch and silently broadcast against the wrong shape
instead of erroring. N is now pinned to match between fdata and cotangent.

Also adds a genuine ComponentMatrix (N=2) regression test -- the earlier
test only exercised ComponentVector, since ComponentArray(a=<matrix>, ...)
actually produces a ComponentVector with matrix-shaped fields, not a real
ComponentMatrix -- and a test confirming a shape mismatch now errors
instead of silently computing a wrong gradient.
@AstitvaAggarwal
AstitvaAggarwal marked this pull request as ready for review September 10, 2026 18:04
@AstitvaAggarwal
AstitvaAggarwal marked this pull request as draft September 10, 2026 18:06
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review September 11, 2026 15:34
@ChrisRackauckas
ChrisRackauckas merged commit 5faabce into SciML:main Sep 11, 2026
20 of 21 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 11, 2026
- Add 32-bit Core CI lane via test_groups.toml (#415)
- Make 32-bit Core lane non-blocking (BFloat16s LLVM) (#416)
- Keep 32-bit Core lane hard-failing. (#418)
- Drop Tracker from Core tests; keep it in Autodiff (#419)
- Fix Core i686 tests: BLAS axpby ULP and Int width (#420)
- Handle raw `Array` cotangents into `FlatComponentArray` `fdata` (#421)
- Add AirspeedVelocity benchmarking CI (#422)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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