Repository navigation
test: fix brittle NonlinearSolution getindex AD test (under-resolved reference) - #1389
Merged
ChrisRackauckas merged 1 commit intoJun 14, 2026
Conversation
…ndex AD test The "NonlinearSolution scalar getindex under AD" testset compared a Mooncake gradient against a ForwardDiff reference at rtol=1e-6, but both were computed through a DynamicSS solve at its default tolerance. The loss is u1 at steady state, where p1 + p2*u1 = 0, so u1 = -p1/p2 and the exact gradient is [-1/p2, p1/p2^2, 0, 0] = [0.5, 0.5, 0, 0]. At the default tolerance the ForwardDiff reference is only accurate to ~1.2e-6 — larger than the rtol=1e-6 it was being held to — so the comparison was brittle to AD-backend accuracy drift and began failing on master (7 passed / 2 failed / 2 broken) after a Mooncake update nudged the Mooncake gradient (which is itself accurate to ~3.6e-8, closer to the true value than the reference) past the threshold. Fix the underlying under-resolution rather than the assertion: set abstol = reltol = 1e-10 on all three solves so every gradient resolves to ~1e-9 of the analytic value. Verified locally with the real AutoMooncake backend — both grad_ssa and grad_def now match grad_ref within rtol=1e-6 (reference error drops from 1.2e-6 to 6.2e-10). Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
ChrisRackauckas
marked this pull request as ready for review
June 14, 2026 10:08
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
observables_autodiff.jlfailure currently red on master (Downstream group,tests / Downstream (julia 1)): testsetNonlinearSolution scalar getindex under AD (SciMLSensitivity#1446)→AutoMooncake,7 passed / 2 failed / 2 broken.Root cause — brittle, under-resolved reference (not a code bug)
The test compares a Mooncake gradient against a ForwardDiff reference at
rtol = 1e-6, but both are computed through aDynamicSSsolve at its default tolerance.The loss is
u₁at steady state, wherep₁ + p₂·u₁ = 0, sou₁ = -p₁/p₂and the exact gradient is[-1/p₂, p₁/p₂², 0, 0] = [0.5, 0.5, 0, 0].Measured locally (Julia 1.11.9), reference error from that exact gradient vs.
DynamicSSsolve tolerance:rtol = 1e-6it is held toSo at the default tolerance the reference itself is off by
1.23e-6— larger than thertolit enforces. The Mooncake value ([0.5, 0.49999996, 0, 0], error ~3.6e-8) is actually closer to the true gradient than the reference. The test passed before only because the two methods' errors happened to align within1e-6; a recent Mooncake update shifted the Mooncake gradient (toward truth) just enough to break the alignment. Confirmed not a SciMLBase code regression: the only commit between the last green master and the failing one is a one-line whitespace change (#1385).Fix — resolve the reference, don't loosen the assertion
Set
abstol = reltol = 1e-10on all three solves so every gradient resolves to ~1e-9 of the analytic value. Thertol = 1e-6assertion is unchanged.Verification (run locally with the real
AutoMooncakebackend, Julia 1.11.9)grad_ssa ≈ grad_refgrad_def ≈ grad_refReproduces the exact CI failure on the current tolerance and confirms the fix passes. Runic clean on the changed file.
🤖 Generated with Claude Code