Repository navigation
OrdinaryDiffEqNonlinearSolve: in-repo [sources] and a central-difference Newton line-search slope - #4667
Draft
ChrisRackauckas-Claude wants to merge 6 commits into
Conversation
Sublibrary CI only develops in-repo [sources]. Without them, Core tests pull registry OrdinaryDiffEqSDIRK 2.9.6, which still restricts Trapezoid to diagonal mass matrices. Local SDIRK 2.9.8 (SciML#4631) does not. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent CLI Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/master-red-0927/log.txt on amdci2
Keep the path sources; remove the PR/issue narrative above them. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Cursor Agent <[email protected]> Agent-Harness: Cursor Agent CLI Agent-Model: auto Agent-Session: local session, transcript at /home/crackauc/sandbox/tmp_20260923_181807_1012334/jobs-root/jobs/master-red-fixes/log.txt on amdci2
This was referenced Sep 28, 2026
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Devin <[email protected]> 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-4667/log.txt
Member
Merged the default branch into this PR (clean merge, no conflicts; head b4be56f) 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 |
`relax!` estimated the initial merit slope with a forward difference at `α = sqrt(eps())`. Near convergence `z - α * dz` rounds at the resolution of `z`, so that difference is dominated by rounding and can come out positive even when the full Newton step reduces the merit. LineSearches 7.7.2 made BackTracking reject a positive initial slope, so `Trapezoid(nlsolve = NLNewton(relax = BackTracking()))` now throws "Search direction is not a direction of descent" on `prob_ode_orego` at `reltol = abstol = 1e-12` (newton_tests.jl), with either the registered or the in-repo SDIRK/Core/DiffEqBase. Use a central difference at the standard `cbrt(eps())` step. On the two test problems this removes every positive slope (orego: 6 -> 0, each of the 6 with ϕ(1) < ϕ(0)) and leaves the trajectories and `nf` unchanged where the old estimate did not throw. The new test records the slopes handed to the line search, so it catches a regression with LineSearches versions that do not check the sign. Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Agent-Harness: Claude Code 2.1.301 Agent-Model: claude-opus-5-5 Agent-Session: local session ID 008bc945-c1f4-4500-b468-244c613850d5 (headless claude -p, no URL)
Co-Authored-By: Chris Rackauckas <[email protected]> Co-Authored-By: Codex <[email protected]> Agent-Harness: Codex CLI 0.162.1 Agent-Model: gpt-6.1-sol Agent-Session: local session 01a14b4e-b068-7043-a160-3359dde41ecb (no session URL)
This branch has not been deployed
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.
Please ignore until reviewed by Chris Rackauckas.
Summary
This PR makes two changes to
lib/OrdinaryDiffEqNonlinearSolve.[sources]for the in-repo siblings (Project.toml). Sublibrary CI path-develops only the packages listed in[sources]. Without the list, this sublibrary's tests resolve registered DiffEqBase, DiffEqDevTools, OrdinaryDiffEqBDF/Core/Differentiation/FIRK/PDIRK/Rosenbrock/SDIRK, which can lag the code in this repo. Other sublibraries (e.g. OrdinaryDiffEqBDF) already use this mapping. The lag is what first exposed the problem: tests ran against a registered SDIRK that still restrictedTrapezoidto diagonal mass matrices. Registered SDIRK 2.9.7 and later include the in-repo change, so that particular error no longer reproduces either way.src/newton.jl, in-placerelax!).Trapezoid(nlsolve = NLNewton(relax = BackTracking()))onprob_ode_oregoatreltol = abstol = 1e-12throwsLineSearchException: Search direction is not a direction of descent(newton_tests.jl:14). It throws with the in-repo siblings and with the registered ones alike, so it is a current master failure and not something[sources]introduced.Cause of the Newton failure
LineSearches 7.7.2 made
BackTrackingthrow on a positive initial slope; 7.7.1 accepted it.relax!estimated that slope with a forward difference atα = sqrt(eps()). Near convergencez - α * dzrounds at the resolution ofz, so the estimate is dominated by rounding. On orego the forward estimate was positive 6 times, and in each case the full step still reduced the merit (ϕ(1) < ϕ(0)).The fix is a central difference at the standard
cbrt(eps())step, the same scheme proposed in #4593. On both test problems it gives 0 positive slopes, and it leaves the trajectories andnfunchanged wherever the old estimate did not throw. The analytic Newton-model slopedϕ0 = -ϕ0was also tried: it raised orego'snfby 967 over plain Newton and fails the existingnf <= nf_plain + 20bound.The original assertions in
newton_tests.jlare unchanged. A new block records every initial slope handed to the line search and asserts that none is positive, so it catches a regression even with LineSearches versions that do not check the sign.Verification (Julia 1.13.2 unless noted)
newton_tests.jlerrors at line 14 withLineSearchException. Same with registered siblings and no[sources].newton_tests.jl:41 Evaluated: 6 == 0(11 pass, 1 fail).newton_tests.jlpasses 12/12 on LineSearches 7.8.2 and on 7.7.1, and on Julia 1.10.12 (LTS) with LineSearches 7.8.2.GROUP=Core(Pkg.testwith--check-bounds=auto, through this PR's[sources]): every testset throughNonlinearSolveAlg Jacobian Reuse Testspasses. That includes Developer API 27/27, Newton 12/12, Linear Solver 113/113, and Mass Matrix 227 pass with 40 existing broken. The run then stops at the first pre-existing failure below. I ran the 15 files after it individually: 432 pass and 5 fail, and all 5 failures are the pre-existing ones below.GROUP=QA: Aqua 41/41; JET 13 pass with 33 broken, all marked broken inqa/jet.jlbefore this change.typos: clean.git diff --check: clean.Pre-existing Core failures (not caused by this PR; the Core CI job will still be red)
Earlier runs never reached these, because the Newton error aborted
runtests.jlfirst. Both reproduce identically with thenewton.jlchange reverted, and neither test uses a line-searchrelax. The independent reviewer also reproduced both with registered siblings and no PR change.nsa_jacobian_reuse_tests.jl:66("stale-W Newton directions are rescaled", KenCarp4 +NonlinearSolveAlg(NewtonRaphson)):sol.stats.naccept < 1.25 * ref.stats.nacceptevaluates to45869 < 44710.0.nsa_noinit_tests.jl:78("functional matrix: rober-mm iip", 4 cases):successful_retcodeis false, with retcodeMaxIters.They are not bisected and need a separate fix.
Downstream SciMLSensitivity Core4 (not caused by this PR)
AssertionError: mi2 !== nothingat Enzyme'sparallelrules.jl:233, inCore4/ensembles.jlunderEnsembleThreads()withTsit5. That path never reaches OrdinaryDiffEqNonlinearSolve. The failing PR job (https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38856263123/job/116828297619) and the passing master job (https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38561320093/job/115842815127) resolve the same Enzyme 0.13.216, EnzymeCore 0.8.23, SciMLBase 3.58.0, and path-developed DiffEqBase/Core/NonlinearSolve. They differ in Julia version, 1.13.2 vs 1.13.1, plus five unrelated leaf packages. This Enzyme-only reproducer (JULIA_NUM_THREADS=2, no SciML package) throws the same assertion on Julia 1.13.2 and returns the correct gradient on 1.13.1:It belongs upstream in Enzyme.jl and has not been filed.
Not verified
pre, and the ModelingToolkit group were not run locally.relax(NLSolver{<:NLNewton, false}with a line search) is broken before this PR and is unchanged here. On an out-of-place Lorenz problem it throwsFieldError: type NLNewtonConstantCache has no field ustep, and it also references an undefinedb. It needs its own fix and test.Review findings addressed
Round 3 fix (Codex CLI 0.162.1, gpt-6.1-sol)
G1: add an in-place Riccati problem,
u' = -10u^2,u(0) = 1, solved withTrapezoid(nlsolve = NLNewton(relax = recorder)). The recorder confirms the line-search path executes, and all 11 saved values are checked against the analytic solution1 / (1 + 10t)atrtol = 1e-7,atol = 1e-9. The solve usesreltol = 1e-12,abstol = 1e-14. Existing regression assertions are preserved. This round changes tests only.Local verification (Julia 1.12.7, LineSearches 7.8.2)
In a scratch copy, the focused runner wraps the unchanged
newton_tests.jlinclude in aTesttestset. Run withJULIA_NUM_THREADS=4 JULIA_NUM_PRECOMPILE_TASKS=4 timeout 3600 julia --startup-file=no --project=lib/OrdinaryDiffEqNonlinearSolve -e 'using Pkg; Pkg.test(; julia_args=["--check-bounds=auto"])'.With only
src/newton.jlreverted to the pre-fix parent:With the central-difference fix:
The unfixed suite aborts in the existing orego solve before reaching the analytic block. The analytic block supplies independent accuracy evidence; the existing orego case supplies fail-before/pass-after evidence for the slope bug.
test/runtests.jland ran the samePkg.testcommand withGROUP=Core: exit 1 atnsa_jacobian_reuse_tests.jl:66,Evaluated: 45869 < 44710.0(20 pass, 1 fail in that testset). Earlier testsets pass, including Newton 25/25 and Mass Matrix 227 pass, 40 existing broken. The runner stops there, so later Core files were not reached in this run.GROUP=QAwith the same official runner andPkg.testcommand: exit 0;JET Tests | 13 pass, 33 existing broken;Aqua | 41 pass;Testing OrdinaryDiffEqNonlinearSolve tests passed.julia --project=@runic -m Runic --inplace lib/OrdinaryDiffEqNonlinearSolve/test/newton_tests.jl,typoson the diff, andgit diff --check: exit 0, no formatting changes or lint findings.Failed CI checks compared with master
Read the failed logs and requested one failed-job rerun for each of the three PR workflows. All three reruns are queued at the time of this update. The completed master Sublibrary CI and Downgrade Sublibraries runs inspected do not contain a NonlinearSolve job, so they provide no matching pass/fail evidence: https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38971870312 and https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/39042337011.
nsa_jacobian_reuse_tests.jl:66:45869 < 44710.0. The older matching master job https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/38482834012/job/115632748374 fails earlier:LoadError: LineSearchException: Search direction is not a direction of descent. Step length: 0.0. It cannot establish whether the later assertion passes on master.nsa_noinit_tests.jl:78,successful_retcode(sol)forfunctional matrix: rober-mm iip. No matching LTS job appears in those master runs. This remains independently unclassified against master CI.nsa_stats_tests.jl:91:1.2823529411764707 <= 1.2619521912350598. The older matching master job https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/37978903577/job/113984167594 passesNonlinearSolveAlg Stats Tests39/39 and the complete package suite; there is no error line. This is not evidence that the PR failure is pre-existing. The failing test usesNLNewton()andNonlinearSolveAlg, with no line search; minimum-version behavior remains unverified locally and needs follow-up before a no-regressions verdict.AssertionError: mi2 !== nothingin Enzyme. This check has a matching master failure.No docs or docstrings changed, so no docs build was run. Minimum-version tests, LTS, prerelease, ModelingToolkit, GPU, and downstream tests were not rerun locally. The CI comparisons above do not certify all checks as non-regressions. A fresh independent review must come from another harness; this round supplies no self-review verdict.
Risk assessment
Risk: medium (independent rating; the author rates it low, and the higher rating stands).
Blast radius:
NLNewton(relax = <line search>)with in-place problems, which is opt-in. The defaultrelax = nothingpath and therelax::Numberpath are untouched. Each line-search call costs one more merit evaluation (3 instead of 2 at α = 0). There is no public API change and no new dependency.[sources]affects only development and CI resolution, not registered installs.Evidence: the failing-before/passing-after runs above, which the independent reviewer reproduced.
Independent review: codex-cli 0.162.1 gpt-6.1-sol rated head
034088b78medium, high confidence: "regression reproduced, original assertions preserved, and the earlier Enzyme failure reproduced independently of this PR". The review was not posted on GitHub.Merge: needs human review. Core CI stays red on the two pre-existing failures above. Fix callback normalization and solver compatibility across Julia versions #4593 carries the identical
[sources]block and the same slope scheme with different comment text, so whichever PR merges second needs a small conflict resolution innewton.jl.Next review: must come from a non-Codex harness (round fixed by Codex CLI gpt-6.1-sol at head 7c26bd6)
🤖 Posted by AI agents — harness: Cursor Agent CLI (original
[sources]change), Devin CLI 3000.11.3 (master merge), Claude Code 2.1.301 (Newton fix and this description) · model: auto, fusion-claude-opus-5-5-high-sidekick-swe-2-medium, claude-opus-5-5Conversation: Cursor: local transcript, no session URL · merge: local Claude session ID 3c311569-dda6-4687-bc9f-65febb212c33 · fix and description: local session ID 008bc945-c1f4-4500-b468-244c613850d5 (headless, no URL)
Independent review (Codex CLI 0.162.1 gpt-6.1-sol, head 034088b)
VERDICT: CHANGES
The focused regression reproduces and the central-difference fix passes, but the numerical validation does not satisfy G1. The affected lane is opt-in in-place NLNewton line searches, not the default Newton path. G2 introduces no additional requirement here: no GPU kernel or AD rule changes, and the supplied snapshot reports passing GPU and AD jobs. G3 is inapplicable: no shared-state lifetime, cache policy, threading or global-default change.
Validation confirmed by running: in a scratch archive, replace only test/runtests.jl with a Test testset including newton_tests.jl and run JULIA_NUM_THREADS=4 JULIA_NUM_PRECOMPILE_TASKS=4 timeout 3600 julia --startup-file=no --project=tmp/head/lib/OrdinaryDiffEqNonlinearSolve -e 'using Pkg; Pkg.test(; julia_args=["--check-bounds=auto"])'. Julia 1.12.7, LineSearches 7.8.2, in-repo sibling sources: head passes 12/12. Replacing only src/newton.jl with the supplied master's version, which is identical to the pre-fix parent for that file, gives 4 passes and 1 error: LineSearchException("Search direction is not a direction of descent."). Thus the run fails before the newly added recorder block on unfixed code. Logs: tmp/head-test.log and tmp/base-test.log. The supplied repo remains unmodified; git diff --check passes.
CI comparison: checks.txt lists exactly four failures. For NonlinearSolve Core Julia 1 and Core LTS, the PR body reports identical unfixed-code failures in nsa_jacobian_reuse_tests.jl:66 and nsa_noinit_tests.jl:78; those assertions exist on supplied master and do not exercise the changed line-search option. This supports the explanation but is not an independently reproduced CI diagnosis. For SciMLSensitivity Core4, the body reports an Enzyme-only threaded reproducer failing on Julia 1.13.2 and passing on 1.13.1, plus PR/master dependency comparisons; I did not reproduce it or obtain those job logs. For downgrade-sublibraries NonlinearSolve, the body explicitly says minimum-version testing was not run; there is no supplied master comparison or failure log identifying its cause. Public CI-log retrieval failed. Consequently all four failures remain independently unclassified in this review; in particular the downgrade failure cannot yet be called pre-existing. Obtain failed-job logs and matching master evidence before treating the no-regressions condition as satisfied.
Not verified: full Core and QA suites, exact new recorder assertions on unfixed code beyond the earlier exception, minimum-version resolution, CI reruns or master job logs, independent accuracy/convergence, numerical equality on previously working trajectories, runtime benchmarks, Julia LTS/pre and ModelingToolkit locally. No linked issue was supplied (closingIssuesReferences is empty and there are no issue-*.json files). The extra merit evaluation in each opted-in Newton iteration is an unbenchmarked hot-path change, setting medium under M3; the missing independent numerical evidence separately fails G1.
🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: Codex exec session 01a14b20-3263-73c0-9adf-5f516a859094 (no public URL)
Codex CLI gpt-6.1-sol rated it medium (M3) at head 034088b
🤖 Posted by an AI agent — harness: Codex CLI 0.162.1 · model: gpt-6.1-sol
Conversation: local session 01a14b4e-b068-7043-a160-3359dde41ecb (no session URL)
Risk assessment (independent review, Codex CLI 0.164.0-alpha.11.1 gpt-6-astra, slot 1, head 7c26bd6)
Review round 1, written by the reviewer named above (Codex CLI 0.164.0-alpha.11.1 / gpt-6-astra) 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 replaces a rounding-sensitive forward line-search derivative with a central difference and uses sibling source packages in its test environment. The targeted Newton tests pass, but newly reached supported-environment failures have not been separated from the dependency-resolution change.
Blast radius: In-place NLNewton with an explicitly selected line search; NonlinearSolve test dependency selection through nine sibling [sources] entries.
Evidence: Exact-head code and analytic Riccati tests inspected; CI Newton Tests 25/25 on current/LTS; 170 success, 4 failure, 1 skipped checks. Minimum-version stats, current-Julia Jacobian reuse and LTS no-init failures are not matched by inspected master logs.
Blocking findings
lib/OrdinaryDiffEqNonlinearSolve/Project.toml:96— confirmed by running in PR CI; whether these are introduced or exposed is unresolved. After switching the test graph to sibling sources, downgrade CI failsnsa_stats_tests.jl:91:excess[2] <= excess[1] + 0.25evaluates1.2823529411764707 <= 1.2619521912350598. Current-Julia Core also failsnsa_jacobian_reuse_tests.jl:66(45869 < 44710), while LTS fails successful-retcode assertions innsa_noinit_tests.jl:78for the mass-matrix Robertson cases. These are package tests in supported environments, not a clean CI result. Master aborts earlier in Newton tests, so matching its line-search exception does not prove these later failures predate this PR. Run the three affected files on base and head under the same resolved sibling/dependency graph, fix any regression, and explicitly classify any independently reproduced baseline failures before accepting this environment change.Non-blocking findings
lib/OrdinaryDiffEqNonlinearSolve/src/newton.jl:1050: A combined value/derivative request now evaluates the merit function three times instead of twice. This is an extra RHS/residual evaluation per request, not a measured end-to-end slowdown. Record representative line-search solve work and time before/after; the analytic Riccati check establishes correctness rather than cost.What I ran
The exact-head checkout was verified with
git rev-parse HEAD(exit 0, SHA in header).git diff origin/master...HEADandgit diff --check origin/master...HEADcompleted with exit 0; the latter produced no diagnostics. I inspected changed files, callers, tests, package manifests, and the absence of rootAGENTS.md/CLAUDE.md.git log -1 --format=%B,git log --no-merges -1 --format=%B, andgit log --no-merges -1 --format=%B origin/master..HEADwere inspected (exit 0); author trailers below come from the newest PR-specific non-merge commit. The header Base is fetchedorigin/master; GitHub's comparison base at review time was59ba40e4b5bbae713d8df7b792f6ea62f033ff78.I checked both
relax!and the unchanged out-of-place relaxation, the residual scratch-buffer flow, the central difference, the minimum-version dependency mappings, and the added recorder/analytic tests. The newu'=-10u^2case compares with1/(1+10t)rather than its own output, satisfying G1 for the changed optional path.Inspected current-Julia Core and LTS Core: both show
Newton Tests | 25 25before later failures. Downgrade shows the stats inequality above. QA passes. Master Sublibrary CI 41050162126 and 41058796614 instead stop in Newton Tests with the oldLineSearchException, so they do not provide a passing or failing comparison for the three later assertions. Core4 is separately compared with the known Enzyme baseline in master IntegrationTest.What I did not verify
No reviewer Julia process or benchmark ran for this PR; no local Julia version/exit code applies. I did not isolate the later CI failures under identical base/head manifests, reproduce minimum-version solving, or measure the extra line-search evaluation cost. I did not infer a new solver bug merely from those unmatched failures. Independent risk/candidates were frozen before reading the description; its earlier review identifies a different head.
🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74