Repository navigation
Compare solution parameter cotangents against the solution's own parameters - #1587
Merged
ChrisRackauckas merged 1 commit intoSep 7, 2026
Conversation
…meters A solution stores the concrete problem it was solved with, and MTK builds problems with `specialize = AutoDespecialize`, so `sol.prob.p` is a `DespecializedParameters` even when the problem handed to `solve` held a plain `MTKParameters`. Zygote's structural cotangent has to mirror that primal, so the parameter cotangent carries a matching `params` level; the tests compared it against a gradient taken with respect to the unwrapped object. Peel the barrier in the test instead, mirroring what the primal actually holds. 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
This was referenced Sep 7, 2026
ChrisRackauckas
marked this pull request as ready for review
September 7, 2026 11:56
ChrisRackauckas
added a commit
that referenced
this pull request
Sep 10, 2026
- Compare solution parameter cotangents against the solution's own parameters (#1587) - Make Makie timeseries recipes Observable-aware (#1589) - Add 32-bit Core CI lane via test_groups.toml (#1590) - Trim unused Makie DEIntegrator hooks after #1589 (#1591) - Keep 32-bit CI lane hard-failing. (#1593) - Avoid broadcast-based getproperties on SciML functions. (#1595) 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]>
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.
What changed and why
With #1584 merged,
test/downstream/remake_autodiff.jlno longer aborts theDownstreamADgroup on Julia LTS, and the group reachestest/downstream/observables_autodiff.jlfor the first time — where two pre-existingAutoZygotefailures are waiting (https://github.com/SciML/SciMLBase.jl/actions/runs/34075472459/job/101609529100).Both have one cause. A solution stores the concrete problem it was solved with, and MTK builds problems with
specialize = AutoDespecialize, sosol.prob.pis aSciMLBase.DespecializedParameterseven when the problem handed tosolveheld a plainMTKParameters— measured on the failing case:iprob.p::MTKParameters{…}butisol.prob.p::SciMLBase.DespecializedParameters. A Zygote structural cotangent has to mirror its primal, so the parameter cotangent carries a matchingparamslevel. The tests compared it against a gradient taken with respect to the unwrapped object, i.e. against a cotangent of a different object. A small helper peels exactly the level the primal actually has, so it is inert if the solver ever stops despecializing.With this, the whole
GROUP=DownstreamADgroup passes on Julia LTS end to end for the first time.Why this is not fixed in the library
The obvious library fix — unwrap in
ext/SciMLBaseZygoteExt.jlso the pullbacks emit an unwrapped parameter cotangent — is wrong, and I measured that rather than assuming it. Zygote discards a structural cotangent that does not mirror the primal:I ran that change through the file and it made things worse —
Autodiff Observable Functions | 20 passed, 1 failed, 2 errored, 1 broken, withgscoming back asnothingandgs isa NamedTuplefailing at line 109. The(params = …)shape SciMLBase already produces is the only shape Zygote accepts, so the extension is right and the tests' premise (sol.prob.p === prob.p) is what broke. That change is not part of this PR.Environment
Julia 1.10.12 (LTS).
test/downstreamresolved identically to the failing CI job: ModelingToolkit 11.41.0, ModelingToolkitBase 1.68.3, Symbolics 7.39.0, ChainRules 1.73.0, ChainRulesCore 1.26.1, Zygote 0.7.13, SciMLSensitivity 7.119.3, OrdinaryDiffEq 7.8.1, NonlinearSolve 4.29.1, Mooncake 0.5.53, Enzyme 0.13.201, DifferentiationInterface 0.7.21.Failing before
GROUP=DownstreamAD julia +lts --project=. -e 'using Pkg; Pkg.test()'with #1584 applied and this PR's change reverted reproduces the CI job's counts exactly:The group stops there:
Ensemble adjoint gradient correctnessnever ran, on CI or locally.Passing after
Same command, same environment, with this change:
The two remaining
Brokenentries are pre-existing@test_brokens (thesplit = trueblock inremake_autodiff.jl, the Mooncake DAE-initialization case inobservables_autodiff.jl). Nothing was skipped, disabled, or loosened.That run was on
3c8b7d4(this commit on top of #1584 before it merged); the only difference from this branch's tree is the3.53.0→3.53.1version bump from #1586.Other checks
julia +release -e 'using Runic; Runic.main(["--check", "test/downstream/observables_autodiff.jl"])'— exit 0 (Runic 1.9.0).typos test/downstream/observables_autodiff.jl— exit 0.What I did NOT verify
ZYGOTE_BACKENDS, which is empty on 1.12, so none of this executes there.DownstreamAD. QA, docs and the rest were not run; this PR touches one test file and no public API.AutoZygotebranches; the Mooncake branches were untouched and unchanged.What a reviewer should push back on
_unwrap_parameter_cotangentencodes a shape in a test. It peels aparamslevel exactly when the primalprob.pis aDespecializedParameters, so it is a no-op if the solver stops despecializing — but it is still a test acknowledging a solver-internal wrapper. If the considered position is thatsol.probshould carry the user's own parameter object rather than the despecialized concrete one, the fix belongs inNonlinearSolveBase.get_concrete_problem/_despecialize_parametersinstead and this helper should go. I did not open that upstream issue, because it turns on a design call aboutAutoDespecializeI am not in a position to make.gpis still taken w.r.t.SII.parameter_values(iprob)); only the left side is unwrapped to match it. An alternative is to takegpw.r.t.SII.parameter_values(isol)and compare wrapped-to-wrapped. Both discriminate; I preferred keeping the reference gradient on the plain parameter object.This PR should be ignored until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code
https://claude.ai/code/session_019wKpyZHy9u4QhR4ePiVmam