Skip to content

test: fix brittle NonlinearSolution getindex AD test (under-resolved reference) - #1389

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:claude/fix-observables-mooncake-reference-tol
Jun 14, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:claude/fix-observables-mooncake-reference-tol

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Important

This PR should be ignored until reviewed by @ChrisRackauckas.

Fixes the observables_autodiff.jl failure currently red on master (Downstream group, tests / Downstream (julia 1)): testset NonlinearSolution 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 a DynamicSS solve at its default tolerance.

The loss is u₁ at steady state, where p₁ + p₂·u₁ = 0, so u₁ = -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. DynamicSS solve tolerance:

solve tol reference error
default 1.23e-6 ← exceeds the rtol = 1e-6 it is held to
1e-8 1.34e-8
1e-10 6.18e-10
1e-12 5.70e-12

So at the default tolerance the reference itself is off by 1.23e-6 — larger than the rtol it 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 within 1e-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-10 on all three solves so every gradient resolves to ~1e-9 of the analytic value. The rtol = 1e-6 assertion is unchanged.

Verification (run locally with the real AutoMooncake backend, Julia 1.11.9)

reference error grad_ssa ≈ grad_ref grad_def ≈ grad_ref
current (default tol) 1.23e-6 ❌ fail ❌ fail
this PR (1e-10) 6.18e-10 ✅ pass ✅ pass

Reproduces the exact CI failure on the current tolerance and confirms the fix passes. Runic clean on the changed file.

🤖 Generated with Claude Code

…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
ChrisRackauckas marked this pull request as ready for review June 14, 2026 10:08
@ChrisRackauckas
ChrisRackauckas merged commit a8301c0 into SciML:master Jun 14, 2026
23 of 48 checks passed
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