Repository navigation
Dispatch the despecialized cotangent test through a RuleConfig - #1584
ChrisRackauckas merged 2 commits into
Conversation
`test/downstream/remake_autodiff.jl` has used `ChainRulesCore` since SciML#1567, but it was never added to `test/downstream/Project.toml`. `GROUP=DownstreamAD` fails on master with Autodiff Remake: Error During Test LoadError: ArgumentError: Package ChainRulesCore not found in current path. Autodiff Remake is the group's first testset, so the error aborts the run before the rest of the group executes. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
`ChainRulesCore.rrule(getindex, sol, x, 1)` has no `RuleConfig` argument, so
it never reached the `ODESolution` rule under test and fell through to the
generic `ChainRules` `AbstractArray` rule, whose `InplaceableThunk` has no
`prob` field. Passing `Zygote.ZygoteRuleConfig()` exposes a second bug: the
non-observed branch of the pullback hands `remake` a
`Tangent{DespecializedParameters}`, so the `Tangent` unwrapping is hoisted to
cover both branches.
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam
- Dispatch the despecialized cotangent test through a RuleConfig (#1584) 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]>
|
Current-master downstream validation completed successfully on clean source I ran the native The two broken checks were pre-existing; no checks were skipped or weakened in this audit. Native A separate local-Mooncake control also passed 54 checks with the same two pre-existing broken checks. Captured actual downstream manifests contain 489 package records; excluding the host path, only Mooncake differs between the control and registry runs. This supersedes the need for the earlier local dependency candidate, rather than proposing another patch here. Scope: these results cover DownstreamAD and QA on the stated source/runtime/dependency graph, not every SciMLBase group, platform, or current CI job. No source change or release action was made by this audit. 🤖 Generated with Codex CLI 0.153.4 (model: gpt-6-astra; session: local session ID 01a0598f-11b9-72d1-91d9-b2fbb186557d). |
What changed and why
ChainRulesCore.rrule(getindex, sol, x, 1)in theDespecialized parameter cotangent remaketestset passes noRuleConfig, so it never dispatched to SciMLBase'srrule(config::RuleConfig{>:HasReverseMode}, ::typeof(getindex), ::ODESolution, sym, ::Integer)— it fell through to the genericChainRulesAbstractArraygetindexrule, whose cotangent is anInplaceableThunkwith noprobfield. The test now passesZygote.ZygoteRuleConfig()(whatSciMLBaseZygoteExtitself uses), which reaches the intended rule and exposes a second, real bug: the non-observed branch of the pullback computesdp = zero_tangent(VA.prob.p), which forDespecializedParametersis aTangent{DespecializedParameters}thatremakecannot consume. TheTangentunwrapping added in #1567 was inside the observed branch only, so it is hoisted to cover both.Fixes #1583.
Stacking
This stacks on #1582 and cannot merge before it.
test/downstream/Project.tomlis missing theChainRulesCoreentry thatremake_autodiff.jlneeds, so without #1582 the file aborts at load and none of this runs. The branch is cut from #1582's branch, so the diff here contains that commit as well.Environment
Julia 1.10.12 (LTS), pinned to the versions the failing CI job resolved: ModelingToolkit 11.41.0, ModelingToolkitBase 1.68.2, Symbolics 7.39.0, SymbolicUtils 4.46.2, ChainRules 1.73.0, ChainRulesCore 1.26.1, Zygote 0.7.13, SciMLSensitivity 7.119.2, OrdinaryDiffEq 7.8.1, SymbolicIndexingInterface 0.3.55, RecursiveArrayTools 4.5.1.
Failing before
julia +lts --project=<env> test/downstream/remake_autodiff.jlon the unmodified tree reproduces the CI error exactly (long type parameters elided with…):The test change alone is not enough
With only the test's
RuleConfigfix applied and the extension left at master, the intended rule is reached and fails for its own reason — this is the library bug this PR also fixes:Passing after
Same command, same environment, both changes applied:
Consistent gradients | Broken 1and the emptysplit = trueblock are pre-existing in the file, unchanged by this PR.No regression in the sibling AD test
test/downstream/observables_autodiff.jlexercises the same pullback. Run in the same environment with and without the extension change, its result is byte-identical — theAutoZygotegs.prob.p == gpfailure at line 119 is pre-existing on master and is not touched here:Other checks
julia +release -e 'using Runic; Runic.main(["--check", "ext/SciMLBaseChainRulesCoreExt.jl", "test/downstream/remake_autodiff.jl"])'— exit 0 (Runic 1.9.0).typos ext/SciMLBaseChainRulesCoreExt.jl test/downstream/remake_autodiff.jl— exit 0.What I did NOT verify
if VERSION < v"1.12", so this code does not execute there at all; a green 1.12 DownstreamAD run says nothing about it.GROUP=DownstreamADsuite. I ranremake_autodiff.jlandobservables_autodiff.jldirectly against a hand-pinned environment matching the CI job's resolved versions, not the whole group throughtest/downstream/Project.toml. Other files in the group were not run.split = true. That branchcontinues in the file (rruleforBroadcast.broadcastedfails when broadcasted overTuple{}JuliaDiff/ChainRules.jl#830), so onlysplit = falseexecuted, before and after.What a reviewer should push back on
cotangent.prob.p isa SciMLBase.DespecializedParametersis false under the intended rule in both branches: the pullback deliberately unwraps the despecialized container beforeremake, socotangent.prob.pcomes back as the wrapped object (Vector{Float64}here). I replaced it with what the fix actually guarantees — the cotangent is not aTangent, and it matchestypeof(SciMLBase.unwrap_parameters(sol.prob.p))— plus an explicitsol.prob.p isa DespecializedParametersprecondition so the test still fails loudly if the solution stops carrying despecialized parameters. If the intent of Handle despecialized parameter cotangents in ODE solution AD #1567 was that the cotangent problem should re-wrap intoDespecializedParameters, then this is a library behaviour question and my assertion codifies the wrong answer.Tangentunwrap changes the non-observed branch's behaviour (previously it errored, now it returns an unwrapped zero cotangent). That is a library fix riding along with a test fix; it can be split out if preferred, but the test cannot pass on thexcase without it.Zygote.ZygoteRuleConfig(), so it depends on Zygote rather than being backend-neutral.SciMLBaseZygoteExtdoes the same, so it matches real usage, but a hand-rolledRuleConfig{>:HasReverseMode}would decouple it.This PR should be ignored until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code
https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam