Repository navigation
Set ForwardDiff event-time partials by the implicit function theorem - #4697
ChrisRackauckas-Claude wants to merge 6 commits into
Conversation
`find_root` ran ModAB at zero tolerance directly on Dual endpoints, so the partials of the returned root came out of the bracketing iteration rather than the implicit function theorem and were only accurate to ~1e-9 (1e-5 through a Vern9 interpolant). The ForwardDiff extension now locates the root on the primal values, which keeps the Left/RightRootFind bracket semantics, and sets the partials to -(dg/dp)/(dg/dt) at the root. Fixes SciML#4388 Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Agent-Harness: Claude Code Agent-Model: claude-opus-5-5[1m] Agent-Session: https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Devin <noreply@cognition.ai> Agent-Harness: Devin CLI 3000.11.3 (conflict resolution), Claude Code 2.1.285 (orchestration) Agent-Model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium Agent-Session: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master); Devin log /Users/chrisrackauckas/sandbox/master/fusion-fixes/SciML_OrdinaryDiffEq.jl-4697/log.txt
Merged the default branch into this PR (clean merge, no conflicts; head 8f4ef4e) so CI runs on current master. Its earlier failures in SciMLSensitivity Core1 and the downgrade jobs were fixed on master after this PR's last CI run. 🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (merge), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium |
Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a19811-7faf-76f1-85b9-8541567dccb3, reviewed head c3a1364
Review written by the reviewer named above in a session other than the PR author's, and copied here by the posting agent without change to its findings. The posting agent did not re-run the reviewer's commands. Summary: The PR computes ForwardDiff event-time partials using the implicit function theorem after locating the primal root. Its analytic regressions fail on the base and pass on the head; one internal zero-partial Dual compatibility edge remains non-blocking. Blast radius: DiffEqBase.find_root with homogeneous Dual brackets whose value type is AbstractFloat; scalar and vector continuous callbacks using these brackets. Ordinary floating-point brackets and nested Dual value types retain the generic implementation. Evidence: Blind risk assessment sealed before author context. On Julia 1.13.2, the added root-partial tests pass 24/24 on the head versus 12 passes and 12 failures on the merge-base; the added downstream event-time file passes 28/28 on the head versus 15 passes and 13 failures on the merge-base. Independent reverse-time vector-callback and cubic-condition ODE probes pass. Relevant DiffEqBase CI is green; the one failed integration job has the identical failure on a recent completed master run. Blocking findingsNone. Non-blocking findings
What I ranRead-only repository and GitHub inspection: gh pr view 4697 --repo SciML/OrdinaryDiffEq.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid
git -C src status --short
git -C src rev-parse HEAD origin/master
git -C src fetch origin '+refs/pull/4697/head:refs/remotes/pr/4697' master
git -C src fetch origin '+refs/heads/master:refs/remotes/origin/master'
git -C src merge-base origin/master HEAD
git -C src diff --stat origin/master...HEAD
git -C src diff origin/master...HEAD
gh pr view 4697 --repo SciML/OrdinaryDiffEq.jl --json title,body,commits,statusCheckRollup
gh issue view 4388 --repo SciML/OrdinaryDiffEq.jl --json title,body
git -C src log -1 --format=%B d9cc8985e2418dbc732bae7c44c85be21dd76141
gh pr checks 4697 --repo SciML/OrdinaryDiffEq.jl
gh run list --repo SciML/OrdinaryDiffEq.jl --branch master --event push --limit 5 --json databaseId,conclusion,headSha,url,workflowName
gh run list --repo SciML/OrdinaryDiffEq.jl --branch master --event push --workflow IntegrationTest --status completed --limit 5 --json databaseId,conclusion,headSha,url,workflowName
XDG_CACHE_HOME="$PWD/tmp/cache" gh run view 38859045811 --repo SciML/OrdinaryDiffEq.jl --log-failed
XDG_CACHE_HOME="$PWD/tmp/cache" gh run view 41318549672 --repo SciML/OrdinaryDiffEq.jl --log-failed
git -C src archive 59ba40e4b5bbae713d8df7b792f6ea62f033ff78 | tar -x -C tmpRepository inspection, fetch, and archive commands exited 0. The initial failed-log retrieval could not write the default cache; setting the writable cache directory above succeeded. GitHub reported the PR open and draft, with the target head unchanged. The reviewed base is the merge-base, also the baseRefOid returned by the PR metadata query. No upstream writes were made. Exactly three Julia processes ran, serially, using Julia 1.13.2 on aarch64. The shared-depot value is represented below by JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env run_regressions.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env-base run_base.jl
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$SHARED_DEPOT:" JULIA_PKG_PRECOMPILE_AUTO=0 timeout 3600 julia +1.13.2 --startup-file=no --compiled-modules=existing --project=env adversarial.jlHead regression run: exit 0. Output: Base regression run: exit 1, as expected. Package source paths printed by the runners confirmed loading the head checkout and the archived base, respectively. The base environment reused the dependency manifest with local source paths changed to the base archive; Pkg emitted a manifest-resolution warning. Output: The derivative oracles are analytic: inverse-function derivatives for the scalar roots, T=q for unit-speed motion, and T=log(2)/p for exponential growth. The exact primal-equality assertion supplements these independent references. Adversarial run: exit 1, reporting four probe exceptions. One establishes the non-blocking zero-partial root regression above; one repeats the existing empty-gradient norm failure; two are reviewer harness constructor errors described below. The independently specified ODE probes passed: The reverse-time in-place VectorContinuousCallback probe integrates u'=1 backward from u(10)=10 and terminates at the first of thresholds [3.1,7.3], giving the independent reference T=7.3 and gradient [0,1]. These runs exercise the changed ForwardDiff path and satisfy G2; the added analytic regressions provide G1 evidence. The implementation introduces no new shared state requiring a G3 test. CI inspection found 132 successful checks, three skipped checks, and one failure. DiffEqBase Core, Downstream, and Downstream2 succeeded. The failed SciMLSensitivity Core4 job reports What I did not verifyThe direct repeated-root and extreme derivative-scaling probes did not reach the implementation: my probe code incorrectly called a fully parameterized Dual constructor with two scalar arguments instead of a Partials argument. I did not rerun them after exhausting the three-run allowance. The passing cubic-condition ODE probe does not establish general repeated-root behavior. The attempted public empty-parameter ODE gradient fails in the existing norm on both revisions, so the zero-partial finding is limited to direct root-helper compatibility. I did not run whole-package suites, additional solver families, GPU/MPI execution, other AD backends, nested-Dual Hessians, other Julia versions/platforms, allocation benchmarks, or full downstream suites locally; CI status is distinguished above from my own runs. 🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5 |
Bring in upstream Enzyme integration compatibility updates. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4697 (no session URL)
Return the primal root in the bracket Dual type when there are no partials. Test both root sides and integration directions. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Codex <noreply@openai.com> Agent-Harness: Codex CLI 0.164.0 Agent-Model: gpt-6.1-sol Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4697 (no session URL)
…d-root Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Muse <noreply@meta.com> Agent-Harness: Muse CLI Code Agent-Model: muse-wonder-full-1.0 Agent-Session: local fixer job SciML__OrdinaryDiffEq.jl__4697 (no session URL)
Please ignore until reviewed by @ChrisRackauckas.
DiffEqBase.find_rootran ModAB atabstol = reltol = 0directly onDualendpoints, so the partials of an event time came out of the bracketing iteration rather than the implicit function theorem: the value was exact butdT/dqwas off by ~1e-9 in the root finder and ~1e-5 once amplified through a Vern9 interpolant (reported by @andreapasquale94, root-caused tofind_rootby @singhharsh1708 in the issue). The ForwardDiff extension now adds afind_rootmethod forDual{T,V<:AbstractFloat,N}brackets that locates the root on the primal values (same ModAB call, so the Left/RightRootFind bracket side is decided exactly as before) and sets the partials to-(∂g/∂p)/(∂g/∂t)at the root.Details a reviewer should check:
∂g/∂tis obtained by re-evaluating the condition with one partial oftseeded (difference of partials, rescaled once to avoid cancellation), not by nesting a new tag, because in-place callbacks interpolate into buffers of the exactDual{T,V,N}type.get_conditionreturns the storedu/uprevwhentequalsintegrator.t/tprev, which drops thetdependence. If the primal root equals an original bracket endpoint, the derivative is evaluated at the other side of the final one-ulp bracket instead; if both sides are original endpoints, or∂g/∂tis zero/non-finite, or the condition does not return aDual{T}withNpartials, it falls back to the previous generic method.V <: Dual) are not covered and still use the generic method.Tests
lib/DiffEqBase/test/callbacks.jl(Core):find_rootonsin(t) - q,t^3 - q,exp(t) - q - 1with a 2-partialq, both rootfind sides; checks the value equals the primal ModAB root and the partials match the analyticdt/dqtortol = 16eps.lib/DiffEqBase/test/downstream/forwarddiff_event_time.jl(Downstream2): the issue MWE (u' = 1, terminate atu = q,dT/dq = 1) for Tsit5/Vern9,q ∈ (3.0, 1.7, 5.3), oop and iip, withrtol = 1e-10; andu' = p u, terminate atu = 2,dT/dp = -log(2)/p^2,rtol = 1e-9. The 1e-10 bound comes from the discrete event time havingdT/dq = 1/û'(T)for the dense outputû: a Float64 solve with the same settings gives1/û'(T) - 1 = 1.6e-12for Vern9 atq = 3.0, and the fixed ForwardDiff result is1.53e-12there.Fails before (master src + new tests;
lib/DiffEqBasefrom a cleanmasterworktree)Passes after
Verification (Julia 1.12.7, local)
GROUP=Core julia --project -e 'using Pkg; Pkg.test()'inlib/DiffEqBase:Callbacks | 59 59, all testsets pass,Testing DiffEqBase tests passed.GROUP=QAinlib/DiffEqBase:Aqua | 9 9, exit 0.GROUP=Downstream2inlib/DiffEqBase:ForwardDiff Event Time | 28 28,Community Callback Tests | 16 16, all pass, exit 0.GROUP=Integrators_I: all pass (Events Tests 58,Alg Events Tests 177,Event Detection Tests 23,Event Repetition Detection Tests 6,Multi-VCC Mask Tests 28, ...),Testing OrdinaryDiffEq tests passed.GROUP=Integrators_II: all pass (Reverse Directioned Event Tests 170,Cache Tests 214 + 4 broken, ...), exit 0.GROUP=AD:AD Tests 28299,Autodiff Events Tests 5 pass + 1 pre-existing @test_broken,Discrete Adjoint Tests 12, exit 0.--checkandtyposon the four changed files: clean.Not verified
VectorContinuousCallbackwith ForwardDiff specifically (it sharesfind_root, but no new test targets it).Fixes #4388
Risk assessment
ContinuousCallback/VectorContinuousCallbackroot find wheretis aForwardDiff.Dualwith a float value type, i.e. ForwardDiff through any solve with a continuous callback (tspan is promoted to Dual in that case). Event time values/bracket sides are computed by the same primal ModAB call; only the partials change. No public API change; the new method lives inDiffEqBaseForwardDiffExt. Per event it costs one primal ModAB solve plus three condition evaluations (a second primal solve when the root lands on an original bracket endpoint).🤖 Generated with Claude Code (model: claude-opus-5-5[1m])
https://claude.ai/code/session_01AXwyJDRaMKgnYMG9M1Ut49
Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 958995c)
Handle the review's zero-partial
ForwardDiff.Dualfinding: after locating the primal root, return it in the bracket's Dual type whenN == 0. The regression checks both integration directions and both root sides, including the analytic root, bracket-side equality, result type, and empty partials. The fix adds one implementation line and 14 test lines. Current master was merged normally, preserving the existing commits and including upstream Enzyme integration compatibility changes.Verification
Julia 1.12.7; four Julia threads, one BLAS thread, automatic precompilation disabled, at most three concurrent Julia processes. Full Core group, before the guard on the original PR head and after the guard with current master merged:
GROUP=Core timeout 7200 julia +1.12.7 --compiled-modules=existing --project=lib/DiffEqBase -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'Before, exit 1:
After, exit 0; all 16 new assertions pass:
Original event-time integration file, in an isolated environment with local sources for OrdinaryDiffEq, DiffEqBase, and their in-repository dependencies plus ForwardDiff (
EVENT_ENVidentifies that environment):Exit 0; the printed source location confirmed this checkout:
Formatting and spelling, exit 0 with no output:
timeout 3600 julia +1.12.7 --project=@runic -m Runic --inplace lib/DiffEqBase/ext/DiffEqBaseForwardDiffExt.jl lib/DiffEqBase/test/callbacks.jl git diff upstream/master --name-only -z | xargs -0 typos git diff --checkQA was run without suppressions:
GROUP=QA timeout 7200 julia +1.12.7 --compiled-modules=existing --project=lib/DiffEqBase -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'Exit 1:
The same four imports fail the same QA check with 18 passes and one error in the default-branch push run at
e335541198. A separate investigator also reproduced the identical 18-pass/one-error result locally on a clean archive of current master at6a6d63e642, with Julia 1.12.7 and the same dependency manifest. This is a baseline failure; the separate baseline investigation does not change this PR's scope.Original failing Core4 check
Independently compared the actual failed PR log with the master push run at
d727918100: both use Julia 1.13.2, Enzyme 0.13.216, EnzymeCore 0.8.23, GPUCompiler 1.23.0, LLVM 9.13.2, Enzyme_jll 0.0.303+0, SciMLSensitivity 7.119.13, and OrdinaryDiffEqCore 4.19.0. Both reportAssertionError: mi2 !== nothinginthreadsfor_commonatparallelrules.jl:233, reached from the threaded ensemble atensembles.jl:19, with 15 passes, one error, and two broken tests. This matches the existing RecursiveArrayTools PR 685 baseline investigation; it was not repeated. Latest master Core4 passes, 16 passes and two broken tests, with Enzyme 0.13.217 on Julia 1.13.3. No test or dependency constraint was weakened in this PR.CI was checked once after pushing: the PR head is
958995c36e, with 34 checks in progress and 46 queued. CI completion, full Downstream2/Core4 suites, other root-package groups, documentation, GPU paths, and other Julia versions were not verified locally.Overall PR risk remains medium-high due to the event-time sensitivity implementation. This fix only handles zero-partial brackets. No independent review of this new head is claimed.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
Links
🤖 Posted by an AI agent — harness: Codex CLI 0.164.0 · model: gpt-6.1-sol
Conversation: local fixer job SciML__OrdinaryDiffEq.jl__4697 (no session URL)
Fix by Muse CLI Code muse-wonder-full-1.0 (head ee83eb1)
Merged current upstream master (
6343f5a0b7) into this branch (clean merge, no conflicts; merge commitee83eb1748). No code changes of my own: the PR diff against master is unchanged (the four DiffEqBase files).Failure classification on the previous head (
958995c36e), fromrack ci compare --no-recordagainst the default branch:autodiff_events.jl:117, ReverseDiff tape error), GPU, and SciMLSensitivity Core2 (same tape error).TypeError: non-boolean (Symbolics.Num)in TaylorDiff precompilation): hit Documentation, the OrdinaryDiffEqTaylorSeries and OrdinaryDiffEqTaylorSeriesImplicit downgrade jobs, and ProbNumDiffEq downstream. Upstream commit760d930622("Raise TaylorDiff compat floors to 0.3.6") fixes the compat floor; it is now merged into this branch.Validation (Julia 1.12.4, JULIA_NUM_THREADS=4)
GROUP=Core timeout 3600 julia --project=lib/DiffEqBase -e 'using Pkg; Pkg.test()'Full Core group passes, ending with:
timeout 1800 julia --project=lib/OrdinaryDiffEqTaylorSeries -e 'using Pkg; Pkg.instantiate(); using OrdinaryDiffEqTaylorSeries; println("TAYLOR_LOAD_OK")'Exit 0,
TAYLOR_LOAD_OKprinted (OrdinaryDiffEqTaylorSeries precompiles and loads with the merged TaylorDiff 0.3.6 floor).julia --project=@runic -m Runic --inplace lib/DiffEqBase/ext/DiffEqBaseForwardDiffExt.jl lib/DiffEqBase/test/callbacks.jl lib/DiffEqBase/test/downstream/forwarddiff_event_time.jl lib/DiffEqBase/test/runtests.jl git diff upstream/master...HEAD --name-only -z | xargs -0 typos git diff --checkAll exit 0, no changes.
GROUP=QA timeout 1700 julia --compiled-modules=existing --project=lib/DiffEqBase -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'Exit 1 with the pre-existing failure only (an earlier plain run timed out in shared-depot precompilation-lock contention before running tests; the retry above completed):
This matches the default-branch QA failure signature from
rack ci compare(same test file location and 18-passed/1-errored summary), so it is pre-existing and unchanged by this merge.Not verified locally: Documentation build, downgrade jobs, Downstream/Downstream2, AD, GPU, SciMLSensitivity and ProbNumDiffEq downstream suites, and other Julia versions. These rerun in CI on the new head; the QA, AD-lts, GPU and Core2 failures are pre-existing on master per the compare evidence above.
Next counted review must come from a smart model in a fresh session, not this fix session (risk.md § Independent reviews).
🤖 Posted by an AI agent — harness: Muse CLI Code · model: muse-wonder-full-1.0
Conversation: local fixer job SciML__OrdinaryDiffEq.jl__4697 (no session URL)