Skip to content

Eliminate TrustRegion sparse per-step JᵀJ allocations - #1366

Open
ChrisRackauckas-Claude wants to merge 9 commits into
SciML:masterfrom
ChrisRackauckas-Claude:tr-sparse-iteration-alloc
Open

ChrisRackauckas-Claude wants to merge 9 commits into
SciML:masterfrom
ChrisRackauckas-Claude:tr-sparse-iteration-alloc

Conversation

@ChrisRackauckas-Claude

@ChrisRackauckas-Claude ChrisRackauckas-Claude commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

🚧 UNREVIEWED — awaiting review by @ChrisRackauckas. Filed by an AI agent running as @ChrisRackauckas; Chris has not seen this.

Summary

Sparse Moré TrustRegion builds a NonlinearSolveBase.normal_form_workspace(J) at initialization and refreshes the Gramian with NonlinearSolveBase.normal_form_jacobian!!. The warmed-step regression requires a Jacobian refresh and a maximum of less than 1,000 allocated bytes. The comparison base contains the merged Levenberg–Marquardt workspace change.

Moré TrustRegion on sparse Jacobians rebuilt JᵀJ every Jacobian update through MaybeInplace's CSC __mul! (C .= A * B, ~239 KB/step on a 1000-dim tridiagonal Bratu problem). This PR builds the normal-form workspace once at MoreTrustRegionDescent init and refreshes it in-place on each update, so the Gramian stays on a fixed jac_prototype and falls back to the allocating product when an in-place jac! grows the pattern.

Before / after (JULIA_NUM_THREADS=1 taskset -c 120, 1000-dim sparse Bratu, TrustRegion()):

  • warmed step! max @allocated: 239536 → 0 bytes (regression asserts < 1000 with a Jacobian refresh in the window)
  • @benchmark solve minimum: 11.60 ms / 2993176 B → 11.94 ms / 1796536 B (time within machine noise; solve memory −1.2 MB)
  • iterates / residual / stats bitwise identical on fixed-pattern problems (nsteps=38, njacs=5, nfactors=77, nsolve=114)
  • allocation regression: fails on unfixed code, passes with the fix (< 1000 byte bound)
  • growing-pattern jac! regression: unguarded fill leaves JᵀJ nnz=3 / wrong solve; guarded helper matches dense TR (maxerr=0)

Test-group tails

  • GROUP=QA NonlinearSolveBase: QA | 20 20 50.1s … Testing NonlinearSolveBase tests passed
  • GROUP=QA NonlinearSolveFirstOrder: QA | 20 20 56.5s … Testing NonlinearSolveFirstOrder tests passed
  • GROUP=Core NonlinearSolveBase: Testing NonlinearSolveBase tests passed
  • GROUP=Core NonlinearSolveFirstOrder: TrustRegion sparse normal-form | 8 8 12.6s … Testing NonlinearSolveFirstOrder tests passed

Not verified: full GROUP=All; GPU / non-CSC sparse layouts; banded/structured Jacobians on the Moré normal-form path; wall-time speedup beyond allocation (solve minima were noise-dominated on a loaded host).

Please ignore until reviewed by @ChrisRackauckas.

Risk assessment

Round-1 findings: CHANGES addressed (reuse #1363 guarded helper; growing-pattern regression; Base QA)

🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /pr-tr-sparse-alloc/log.txt; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv

Made with Cursor

Addressed findings from fix rounds

Commit fcb0adc responds to the Codex (gpt-6-astra) review and to the Devin review comment on this PR.

  • Astra P2: the PR added new ExplicitImports all_qualified_accesses_are_public ignore entries. Fixed. normal_form_workspace and normal_form_jacobian!! now live in the top-level NonlinearSolveBase module instead of Utils, and are declared public next to requires_normal_form_jacobian. Their docstrings state the extension contract, and they are listed in docs/src/devdocs/internal_interfaces.md under "Normal-Form Jacobian". The SparseArrays extension extends the public names, and both ignore entries are removed. I ran Base GROUP=QA with the ignore entries removed:

    • before the move: QA | 19 1 20, with normal_form_jacobian!! is not public in NonlinearSolveBase.Utils and the same error for normal_form_workspace;
    • after the move: QA | 20 20.
  • Devin: the new sparse path had no test of reinit! with a changed parameter. Fixed. sparsity_tests__item4.jl now runs init → solve! → reinit!(cache, u0; p = p₂) → solve! with linsolve = nothing and with KLUFactorization(). It asserts:

    • residual < 1e-8;
    • retcode and u equal (==) to a fresh solve(remake(prob; p = p₂));
    • J and JᵀJ are both still SparseMatrixCSC;
    • JᵀJ == transpose(J) * J.

    This is new coverage, not a bug fix: these tests also pass with the MoreTrustRegionDescent change reverted.

  • Devin: merge order. No code change. This branch still carries Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363's commit (3cf0c9a), and this commit changes code that Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363 introduced. Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363 itself still has the two ignore entries. The options are: merge Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363 first and then merge master into this branch (this commit then removes the entries on top of it), or merge this PR alone, which makes Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363 redundant.

  • Devin (non-blocking): the allocation bound was not derived from anything. The bound is tightened from < 40_000 to < 1000, the same as the sibling LM test, and the test now also asserts that cache.stats.njacs grows inside the measured window.

    • Measured per-step allocations: (144, 0, 0, 144, 0) with 2 new Jacobians on Julia 1.13.0, and (0, 0, 0, 0, 0) with 1 new Jacobian on 1.10.12.
    • With the MoreTrustRegionDescent change reverted to @bb cache.JᵀJ = transpose(J_) × J_, the test fails: Evaluated: 239536 < 1000.
  • Devin (non-blocking): the top-of-file comment in item4 was retrospective. It now describes the property under test.

  • Devin (non-blocking): the TrustRegion Bratu solves return Stalled / ShrinkThresholdExceeded with a residual of about 3e-11. Not changed. This is existing termination behaviour and also happens on the parent tree, so the new test asserts the residual rather than the retcode. It is worth a separate issue.

  • Devin (non-blocking): the PR body's nfactors/nsolve counts differ from the reviewer's. Not changed. The counts depend on the Julia version, and the bitwise-identity claim was confirmed by the reviewer.

Not breaking. The commit adds two public names to NonlinearSolveBase, so its next release needs a minor version bump rather than a patch. No existing public name changes. Following the repository's practice of separate release PRs, I did not bump the version.

Verification (for fcb0adc)

All of these ran locally with JULIA_NUM_THREADS=4.

Test groups

  • GROUP=Core NonlinearSolveBase (Julia 1.13.0): Testing NonlinearSolveBase tests passed.
  • GROUP=Core NonlinearSolveFirstOrder (Julia 1.13.0): Sparse normal-form LevenbergMarquardt | 14 14, TrustRegion sparse normal-form | 21 21 … Testing NonlinearSolveFirstOrder tests passed.
  • GROUP=QA NonlinearSolveBase: QA | 20 20 on 1.13.0, and QA | 18 18 on 1.10.12, where the public checks do not run.

Sparse test files on their own (item3 and item4)

  • Julia 1.10.12: 14 14 and 21 21.
  • Julia 1.13.0, with the MoreTrustRegionDescent change reverted: TrustRegion sparse normal-form | 18 1 19, failing at Evaluated: 239536 < 1000.

Docs and formatting

  • Docs: I built only the new "Normal-Form Jacobian" @docs section, in a minimal Documenter build with NonlinearSolveBase and SparseArrays loaded. It had no errors, both docstrings rendered, and their @ref links resolved. I did not run the full docs/make.jl, which needs Sundials, SciPy, PETSc and the MTK tutorials, plus linkcheck.
  • Runic --check on the changed .jl files: exit 0. typos on the changed files: exit 0.

Not verified: Julia pre, the full docs build, GPU paths, and downstream packages.


🤖 Posted by an AI agent — harness: Claude Code 2.1.301 · model: claude-opus-5-5
Conversation: local session ID 9ed6c56f-b474-4c6d-be68-63bf2ea757c3 (headless, no URL)

Risk assessment (independent review, codex-cli gpt-6.1-sol, reviewed head fcb0adc)


🤖 Posted by an AI agent — harness: codex-cli · model: gpt-6.1-sol (independent reviewer; appended by Claude Code 2.1.301 · claude-opus-5-5)
Conversation: https://claude.ai/code/session_01VZjwf7Ux9YtTzwHGHMqnsq

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.164.0 gpt-6.1-sol (head 04f7da1)

Merged upstream master at d254af933dd48eeb9b21b4a55f643e92a0840ff6 normally, incorporating the existing Julia 1.10 polyalgorithm return-code inference fix. Both requested LTS jobs fail the same unchanged inference test; both pass in the latest default-branch CI run.

Resolved the stacked sparse-workspace conflicts while retaining the public NonlinearSolveBase.normal_form_workspace / normal_form_jacobian!! interfaces, their extension methods, and all TrustRegion tests. The merge does not introduce duplicate helpers in Utils or restore their ExplicitImports exclusions. No test assertions were weakened or disabled.

Verification

Commands used Julia threads = 4, OpenBLAS threads = 1, automatic package precompilation disabled, and timeout 3600. Machine-specific directory prefixes below are redacted as <unfixed-tree> and $QA_ENV. The root LTS environment developed the local solver sublibraries together; the fresh Julia 1.13 QA environment developed local NonlinearSolveBase and SciMLJacobianOperators.

Before, archived unchanged PR head fcb0adc3844ba098a211dd28d173ee5b0d6e0f4a, Julia 1.10.12; exit 1:

timeout 3600 julia +1.10 --startup-file=no --project=<unfixed-tree> -e 'using Test; include("<unfixed-tree>/test/Core/core_tests__item3.jl")'
Test Summary:     | Pass  Total   Time
solve() inference |    8      8  12.0s
solve!() inference: Error During Test
Test Summary:      | Error  Total  Time
solve!() inference |     1      1  4.3s

The error is the same return-type mismatch as CI: the concrete solution ends in SciMLBase.ReturnCode.T, while the inferred solution leaves that parameter unspecified. Before and after LTS environments resolve SciMLBase 3.58.0 and LinearSolve 5.18.3.

After, full root Core group, Julia 1.10.12; exit 0:

GROUP=Core timeout 3600 julia +1.10 --startup-file=no --project -e 'using Pkg; Pkg.test()'
PolyAlgorithm Type Inference |   16     16  32.3s
FastShortcutHomotopyPolyalg + homotopy initialization_alg |   12     12  19.3s
     Testing NonlinearSolve tests passed

Full root QA, Julia 1.10.12; exit 0:

GROUP=QA timeout 3600 julia +1.10 --startup-file=no --project -e 'using Pkg; Pkg.test()'
QA            |   26     26  5m12.1s
     Testing NonlinearSolve tests passed

Full first-order Core, Julia 1.10.12; exit 0:

GROUP=Core timeout 3600 julia +1.10 --startup-file=no --project -e 'using Pkg; Pkg.test("NonlinearSolveFirstOrder")'
Sparse normal-form LevenbergMarquardt |   14     14  4.2s
TrustRegion sparse normal-form |   21     21  8.0s
SciMLOperator Jacobians |   14     14  7.1s
     Testing NonlinearSolveFirstOrder tests passed

Base QA including public-access checks, Julia 1.13.3, isolated environment; exit 0:

GROUP=QA timeout 3600 julia +1 --startup-file=no --project="$QA_ENV" -e 'using Pkg; Pkg.test("NonlinearSolveBase")'
QA            |   20     20  45.5s
     Testing NonlinearSolveBase tests passed

Formatting and spelling, exit 0; no diagnostics:

git diff --cached --name-only -- '*.jl' | xargs -r julia +1 --project=@runic -m Runic --inplace
git diff --cached --no-ext-diff | sed -n '/^+[^+]/s/^+//p' | typos -
git diff --cached --check

Runic covered all 26 Julia files changed by the merge and produced no additional changes. An initial Base QA invocation using the LTS manifest failed in Pkg source-path setup before tests started; the isolated Julia 1.13 environment above avoids that environment mismatch.

Not verified locally: macOS, GPU, downstream packages, remaining sublibrary groups, full documentation build, or wall-time benchmarks. The default branch's CUDA warning failure is unrelated and was left unchanged. No separate fresh-session review of this merged 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__NonlinearSolve.jl__1366 (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Muse CLI Code muse-wonder-full-1.0 (head 5ecbf98)

The two base-green failures (lib/NonlinearSolveHomotopyContinuation Core and QA on Julia 1) are a TaylorDiff precompilation failure, not a TrustRegion regression: TaylorDiff 0.3.5 traces derivative rules at load time by evaluating a ChainRules frule on a symbolic variable, which errors with TypeError: non-boolean (Symbolics.Num) used in boolean context under Symbolics 7.48.0. TaylorDiff 0.3.6 derives those expressions from DiffRules instead and loads cleanly.

Changes:

  • Merged upstream master (one commit, BracketingNonlinearSolve verbosity presets) normally, no conflicts.
  • Raised the TaylorDiff compat floor in lib/NonlinearSolveHomotopyContinuation/Project.toml from 0.3.1 to 0.3.6, so no resolution (including downgrade CI) can select the broken releases. No test was skipped, loosened, or silenced.

Failing before / passing after, from local runs (Julia 1.13.2, JULIA_NUM_THREADS=4, timeout 3600):

  • Clean upstream master checkout, HomotopyContinuation Core with TaylorDiff pinned to the CI-resolved 0.3.5 (GROUP=Core julia --project=lib/NonlinearSolveHomotopyContinuation -e 'using Pkg; Pkg.test()'): exit 1, Failed to precompile TaylorDiff, Some tests did not pass: 0 passed, 0 failed, 1 errored. The same error also reproduces in an environment containing only TaylorDiff 0.3.5, Symbolics 7.48.0, and ChainRules 1.74.12, with no NonlinearSolve code involved; TaylorDiff 0.3.6 in the same setup loads with LOAD_OK. This failure is therefore pre-existing ecosystem drift (the default branch's Sublibrary CI did not run the HomotopyContinuation jobs in its latest run, and its Documentation and downgrade-sublibraries runs fail with the same signature).
  • This branch after the fix, HomotopyContinuation Core: exit 0 — AllRoots | 116 116, Single Root | 35 35, Taylor Polynomialize | 40 40, Testing NonlinearSolveHomotopyContinuation tests passed (resolved TaylorDiff v0.3.6).
  • This branch after the fix, HomotopyContinuation QA (GROUP=QA): exit 0 — QA | 19 1 20 (the 1 broken is the pre-existing aqua_broken = (:persistent_tasks,) entry), Testing NonlinearSolveHomotopyContinuation tests passed.
  • This branch after the fix, BracketingNonlinearSolve Core (covers the merged upstream commit): exit 0 — verbose presets for every method | 103 103, Testing BracketingNonlinearSolve tests passed.
  • Root GROUP=QA (GROUP=QA julia --project=. -e 'using Pkg; Pkg.test()'): exit 0 — QA | 28 28, Testing NonlinearSolve tests passed. A first local attempt errored in shared-depot precompilation (Precompiled image ... not available with flags for RuntimeGeneratedFunctions, via SymbolicIndexingInterface) before any test ran; the identical rerun passed, and the HomotopyContinuation QA run above loaded the same packages without that error.
  • typos over the full diff against the previous PR head: exit 0, no diagnostics. Runic --inplace on the three Julia files changed by the merge (the compat change touches only a Project.toml): exit 0, no changes.

Not verified locally: the full All/Everything suites, FirstOrder Core (unchanged by this fix and green in the PR's CI at the previous head), GPU, macOS, and the downgrade-sublibraries lane (the raised floor is what that lane resolves to, but the lane itself was not run locally).

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__NonlinearSolve.jl__1366 (no session URL)

🤖 Automated review section from an AI agent running as Chris Rackauckas's account — not written or reviewed by Chris.

Fix by Codex CLI 0.169.0 gpt-6.2-sol (head 0cae4c0)

Changes

  • Brought the current upstream master into the PR branch with a merge commit.
  • Restored the TaylorDiff 0.3.1 compat floor. The HomotopyContinuation project file is absent from the PR diff against upstream/master.
  • The growth fixture checks sparse and dense solver success at [1, 1, 1], an independently evaluated residual below 1e-10, Jacobian growth from three to five entries, and exact sparse Gramian equality with transpose(J) * J.

Updated summary

Sparse Moré TrustRegion builds a NonlinearSolveBase.normal_form_workspace(J) at initialization and refreshes the Gramian with NonlinearSolveBase.normal_form_jacobian!!. The warmed-step regression requires a Jacobian refresh and a maximum of less than 1,000 allocated bytes. The comparison base contains the merged Levenberg–Marquardt workspace change.

Local validation

Julia 1.13.2 ran with four Julia threads, one OpenBLAS thread, one precompile task, and automatic package precompilation disabled. The full test groups ran from a scratch checkout containing the same source changes as this head.

GROUP=Core timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveFirstOrder -e 'using Pkg; Pkg.instantiate(; update_registry=false); Pkg.test()'
GROUP=Core timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveHomotopyContinuation -e 'using Pkg; @assert Pkg.project().path == abspath("lib/NonlinearSolveHomotopyContinuation/Project.toml"); @assert occursin("TaylorDiff = \"0.3.1\"", read(Pkg.project().path, String)); Pkg.instantiate(; update_registry=false); Pkg.status(["TaylorDiff"]); Pkg.test()'
GROUP=QA timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.instantiate(; update_registry=false); Pkg.test()'
GROUP=QA timeout 3600 julia --startup-file=no --project -e 'using Pkg; Pkg.instantiate(; update_registry=false); Pkg.test()'
GROUP=QA timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveFirstOrder -e 'using Pkg; Pkg.test()'
GROUP=Core timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test()'
GROUP=QA timeout 3600 julia --startup-file=no --project=lib/NonlinearSolveHomotopyContinuation -e 'using Pkg; Pkg.test()'

All seven commands exited 0. FirstOrder Core passed 9,050 assertions and Base Core passed 561.

Sparse normal-form LevenbergMarquardt |   14     14  3.3s
TrustRegion sparse normal-form |   26     26  6.0s
     Testing NonlinearSolveFirstOrder tests passed
AllRoots      |  122    122  3m13.0s
Single Root   |   35     35  32.1s
Complex Roots |   89     89  34.0s
Taylor Polynomialize |   40     40  28.1s
     Testing NonlinearSolveHomotopyContinuation tests passed
  [b36ab563] TaylorDiff v0.3.6
QA            |   20     20  18.0s
     Testing NonlinearSolveBase tests passed
QA            |   28     28  1m18.1s
     Testing NonlinearSolve tests passed
QA            |   20     20  19.7s
     Testing NonlinearSolveFirstOrder tests passed
     Testing NonlinearSolveBase tests passed
QA            |   19       1     20  28.2s
     Testing NonlinearSolveHomotopyContinuation tests passed

HomotopyContinuation QA retains its existing broken Aqua persistent-tasks check.

The baseline command ran the original test file with a probe that required successful return codes and independently recomputed residuals below 1e-10.

timeout 3600 julia --startup-file=no --check-bounds=yes --project="$FIXTURE_ENV" "$PROBE_DIR/item4-before.jl"
sol.retcode = SciMLBase.ReturnCode.Stalled
residual = 0.16639190644736346
sol.retcode = SciMLBase.ReturnCode.Stalled
residual = 0.16639190644736362
Old growth fixture reaches a root |    4      4  1.1s

The baseline exited 1 on the four new assertions. The revised fixture passed in FirstOrder Core.

julia --project=@runic -m Runic --inplace lib/NonlinearSolveFirstOrder/test/sparsity_tests__item4.jl
git diff --name-only -z upstream/master -- '*.jl' | xargs -0 -r julia --project=@runic -m Runic --check
git diff --no-ext-diff upstream/master | sed '/^index /d' | typos -
git diff --check upstream/master...HEAD
git diff upstream/master...HEAD --stat

Runic, spelling, and whitespace checks exited 0 without diagnostics. The stat reported 11 files, 176 insertions, and 36 deletions.

Root Core exited 0 with 1,592 passing assertions and 91 existing broken checks.

GROUP=Core timeout 3600 julia --startup-file=no --project -e 'using Pkg; Pkg.test()'
PolyAlgorithm Type Inference |   16     16  21.0s
FastShortcutHomotopyPolyalg + homotopy initialization_alg |   12     12  11.9s
     Testing NonlinearSolve tests passed

The full Documenter build exited 0 and rendered both workspace API entries.

timeout 3600 julia --startup-file=no --project=docs -e 'using Pkg; Pkg.instantiate(; update_registry=false)'
CI=false timeout 3600 julia --startup-file=no --project=docs docs/make.jl
[ Info: Doctest: running doctests.
[ Info: RenderDocument: rendering document.
[ Info: HTMLWriter: rendering HTML pages.
[ Info: Automatic `version="4.32.0"` for inventory from ../Project.toml

Existing CI failures

Default-branch CI reproduced the SCC Core concrete-type assertion and the CUDA test failure from a GPUCompiler deprecation warning. The most recent default-branch CUDA check passed. The most recent default-branch Sublibrary CI did not include an SCC job.

Next counted review must come from a smart model in a fresh session, not this fix session.


🤖 Posted by an AI agent — harness: Codex CLI 0.169.0 · model: gpt-6.2-sol
Conversation: local session 01a21d89-8442-7df1-aaa6-69366cd14518 (no session URL)

ChrisRackauckas and others added 2 commits October 7, 2026 14:02
In the normal-form (and least-squares with normal-form damping) modes,
`transpose(J) × J` on a SparseMatrixCSC went through MaybeInplace's sparse
fallback, which materializes `copy(transpose(J))` and a fresh `spmatmul`
product every iteration (~239 KB/step for LevenbergMarquardt with
KLUFactorization on a 1000-dim tridiagonal problem).

`Utils.normal_form_jacobian!!` now writes the values into the cached JᵀJ
pattern using a transpose buffer and a dense accumulator held in the
descent cache. The accumulation order matches SparseArrays' Gustavson
spmatmul, so results are bitwise identical; a pattern mismatch falls back
to the allocating product.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Agent-Harness: Claude Code
Agent-Model: claude-opus-5-5
Agent-Session: https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv
Reuse Utils.normal_form_jacobian!! / normal_form_workspace from SciML#1363
in MoreTrustRegionDescent so sparse TrustRegion no longer rebuilds JᵀJ
via MaybeInplace's allocating CSC product each Jacobian update.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Co-authored-by: Cursor <[email protected]>
@ChrisRackauckas

Copy link
Copy Markdown
Member

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Devin CLI 3000.11.3, model fusion-claude-opus-5-5-high-sidekick-swe-2-medium): CHANGES, risk low.

Full review

VERDICT: CHANGES
RISK: low

Scope: the PR is stacked. git diff origin/master...HEAD contains two commits: 3cf0c9a (PR #1363: the normal_form_jacobian!! kernel, the LM wiring, the QA ignore-list entries, and test item3) and bd7e750 (this PR's own change: the MoreTrustRegionDescent wiring plus test item4). I reviewed both, because merging #1366 into master brings in both. The TrustRegion change is numerically sound: I got bitwise-identical results to the parent commit on every fixed-pattern case I tried, and the allocation reduction is real. The verdict is CHANGES because of one AGENTS.md test-coverage rule and the merge order. I found no wrong results.

Blocking findings

  1. AGENTS.md rule: the new sparse in-place path has no test of reinit! with a changed parameter (lib/NonlinearSolveFirstOrder/test/sparsity_tests__item4.jl).

    • The rule. AGENTS.md says: "Exercise parameter-changing reinitialization and preconditioning on these paths." The new JᵀJ_workspace is created once, in InternalAPI.init (more_trust_region.jl:1004-1011), and it is reused across reinit!. InternalAPI.reinit! (more_trust_region.jl:1081-1097) does not touch JᵀJ or the workspace. No test covers that lifecycle.
    • Confirmed by running: the behaviour is correct today. I ran scratch/probe.jl section 2: sparse Bratu (n=200), init, then solve!, then reinit!(cache, zeros(200); p = (λ = 3.0, …)), then solve!. Observed: Success, s2.u == fresh.u is true (max diff 0.0), J and JᵀJ are both still SparseMatrixCSC, and nonzeros(JᵀJ) == nonzeros(transpose(J)*J). So this is a missing test, not a bug.
    • Required change. Add to item4 a reinit!-with-new-p case on the sparse TrustRegion() path. It should assert:
      • bitwise equality with a fresh solve(remake(prob; p = p2));
      • that cache.descent_cache.JᵀJ isa SparseMatrixCSC.

    It also helps to cover an explicit square linsolve such as KLUFactorization(), which is the case where needs_square_A forces the normal form.

  2. Merge order: this PR's diff includes all of Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363.

Non-blocking findings

  • The allocation threshold is not derived from anything (sparsity_tests__item4.jl:375, maximum(allocs) < 40_000).
    • Confirmed by running: per-step allocations measured over the 5-step window are [144, 0, 0, 144, 0] on the PR head versus [144, 0, 0, 263904, 263760] on its parent. So the test does fail without the fix; the sidekick-run of item4 on the parent got Evaluated: 263904 < 40000.
    • The bound is about 280× the observed residual. A partial regression (for example a new length-n buffer per Jacobian, about 8 KB) would pass. The sibling LM test (item3) uses < 1000; the same bound fits here.
    • Only 2 of the 5 measured steps form a new Jacobian (njacs delta = 2, measured). The test's ability to catch the regression therefore depends on the Moré radius scheme's accept/reject sequence. Asserting that cache.stats.njacs increased inside the window would make it robust.
  • The growing-pattern test does exercise the fallback. Confirmed with scratch/probe_grow.jl:
    • nnz(J) goes 3 → 7 and nnz(JᵀJ) goes 3 → 9 at step 2;
    • JᵀJ stays the same object (the fallback writes in place) and matches transpose(J)*J exactly;
    • after the fallback, the next call takes the fast path with @allocated == 0.
    • I also tried a jac! that shrinks the pattern (dropzeros!), with the default linsolve and with KLU. Max diff to dense TrustRegion was 8.9e-16, the same as on the parent.
  • The item4 Bratu solve returns ReturnCode.Stalled, which the test hides by checking only norm(sol.resid) < 1e-8. Observed on both head and parent (alloctest_solve => (Stalled, 38, 5, 75, 110)), and on n=300, λ=3 Bratu with the default, UMFPACK, NLsolve and Bastin schemes (KLU and Hei return ShrinkThresholdExceeded). This is pre-existing TrustRegion termination behaviour, not caused by this PR, but it is worth an issue.
  • The PR body's stats don't match my run exactly. The body says nfactors=77, nsolve=114; I get nfactors=75, nsolve=110 on Julia 1.12.7, identically on head and parent. The body's "bitwise identical" claim holds; the exact counts are probably version-dependent.
  • The comment at the top of item4 is slightly retrospective. It says "must not rebuild sparse JᵀJ through MaybeInplace's allocating CSC product" — that is, it describes the old implementation rather than the property under test. Minor.
  • Pre-existing, unrelated: TrustRegion() on Float32 sparse Bratu (n=100) returns InternalLinearSolveFailed, identically on head and parent.
  • Sibling work: PR Reuse the init-time Jacobian on the first Newton step (stacked on #1365) #1367 (Reuse the init-time Jacobian on the first Newton step (stacked on #1365) #1367) also edits damped_newton.jl, which is Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363's file. It will conflict with Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363, not with the TrustRegion commit. No other open PR touches more_trust_region.jl, the SparseArrays extension or utils.jl.
  • Reading the kernel (NonlinearSolveBaseSparseArraysExt.jl:55-92):
    • The pattern guard is sound: per column, nfilled == length(nzrange(C,i)) and every stored row of C filled means the sets are equal.
    • On a mismatch, fill!(filled,false) resets state.
    • transpose! resizes Jᵀ storage when nnz(J) grows (I checked the SparseArrays 1.12 source).
    • Bitwise equality with transpose(J)*J is tested in item3 and held in every probe.

What I ran

All on Julia 1.12.7 (aarch64). Two environments: env_head (PR head) and env_base1363, which is the 3cf0c9a tree exported with git archive, so it is the parent of the TrustRegion commit.

  • Formatting and spelling. julia +1.12 --project=@runic -m Runic --check on all changed files: exit 0. git diff origin/master...HEAD | typos -: exit 0.

  • sparsity_tests.jl on head: Brusselator 5/5, Structured 16/16, LM normal-form 14/14, TrustRegion sparse normal-form 8/8.

  • Item4 on the parent: 7 pass, 1 fail. The allocation test reports 263904 < 40000, so it fails without the fix and passes with it.

  • scratch/probe.jl on head and parent. The outputs are identical except for allocations:

    • seven TrustRegion configurations (default, KLU, UMFPACK, KrylovJL_CG, and the Hei, NLsolve and Bastin schemes) on n=300 Bratu: bitwise-equal u hash and equal nsteps/njacs/nfactors;
    • the reinit! case;
    • a rectangular 99×50 sparse least-squares problem (matches dense QR TrustRegion to 1.3e-15);
    • the shrinking-pattern jac!;
    • Float32;
    • the per-step allocation trace. Every Jacobian-forming step allocates 263760 B on the parent and 0 B on head.
  • scratch/probe_grow.jl on head: the fallback behaviour described above.

  • Targeted existing TrustRegion tests on head, all passing:

    Test set Passed
    rootfind items 8–13 1176, 2, 2, 6, 28, 27
    rootfind item 19 12
    misc item 3 11
    misc item 9 125
    misc item 10 24
    least_squares item 6, run in its own process 138/138
    least_squares item 7 16/16
    inference item 1 no failures reported
  • One error I traced to my test setup, not the PR. The first combined run reported an error at the @inferred init check in least_squares item 6 (line 236). I traced it to Enzyme having been loaded earlier in the same session by misc item 3. With using Enzyme loaded first, scratch/probe_infer.jl is not inferred on either head or parent. Without Enzyme, it is inferred on both. In the real Core order, least_squares runs before misc.

  • GROUP=QA for NonlinearSolveBase: 20/20 passed.

  • git status in the checkout is clean afterwards, and no Julia processes are left running.

What I did not verify

  • The full GROUP=Core/All suites, and GROUP=QA for NonlinearSolveFirstOrder (I relied on the targeted files above).
  • Julia LTS (1.10) and pre-release.
  • GPU and non-SparseMatrixCSC sparse types: these take the generic nothing workspace path, which I read but did not run.
  • ForwardDiff through a sparse TrustRegion solve. My probe raised MethodError: Float64(::Dual) on both head and parent; it is probably a defect in how my probe built the problem, and I did not investigate.
  • Wall-time performance.
  • The LevenbergMarquardt half (Form sparse JᵀJ in place in DampedNewtonDescent (LM normal-form step! allocations) #1363) beyond the shared kernel and its item3 test passing.

Links


🤖 Posted by an AI agent — harness: Devin CLI 3000.11.3 (review), Claude Code 2.1.285 (posting) · model: fusion-claude-opus-5-5-high-sidekick-swe-2-medium
Conversation: local Claude session 3c311569-dda6-4687-bc9f-65febb212c33 (fleet master)

ChrisRackauckas and others added 2 commits October 16, 2026 05:32
Move `normal_form_workspace` and `normal_form_jacobian!!` from
`NonlinearSolveBase.Utils` to the top-level module, declare them public
next to the other normal-form traits, and document them in the developer
docs. The SparseArrays extension now extends the public names, so the
ExplicitImports `all_qualified_accesses_are_public` ignore entries for
them are gone.

Extend the TrustRegion sparse tests: `reinit!` with a new `p` on the
default and KLU linsolves must match a fresh solve bitwise and keep
`JᵀJ` sparse, and the warmed `step!` window must form a new Jacobian
while allocating under 1000 bytes per step.

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 9ed6c56f-b474-4c6d-be68-63bf2ea757c3 (headless claude -p, no URL)
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

Independent review (Codex CLI 0.166.0 / gpt-6.1-sol), session 01a1973e-d09a-7de1-8730-7c032b70f439, reviewed head fcb0adc

  • Verdict: MERGE
  • Risk: medium-high (MH1: main-lane performance change with a new persistent sparse workspace; retain the sealed blind rating because sparse wall-time benchmark coverage is incomplete).
  • Round / slot: 1 / 1
  • Blocking priorities: none

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: Reuses a guarded sparse normal-equation workspace in Levenberg–Marquardt and Moré TrustRegion, and adds documented public extension hooks. The allocation regressions fail on the unfixed base and pass at head, independent numerical probes pass, and no blocking defect was found.

Blast radius: SparseMatrixCSC normal-equation updates in DampedNewtonDescent normal-form and least-squares damping modes, and MoreTrustRegionDescent, including default sparse TrustRegion. The generic fallback retains the existing multiplication expression; two additive public developer interfaces have docstrings and a docs entry (ML7).

Evidence: Head: both new sparse test files pass, 35 assertions. Merge-base: the same TrustRegion file and the LM allocation regressions produce 20 passes and three expected allocation failures. Independent dense-product/workspace probes pass 672 assertions, and analytic rectangular sparse solve/reinit probes pass 12. Affected Core/QA, downstream/integration, docs, and benchmark CI pass; the three failed jobs have matching failures in default-branch logs, detailed below. G1 is supported by independent multiplication and analytic solutions; G3 by repeated pattern changes and parameter-changing reinitialization. No new GPU kernel or AD rule is introduced.

Blocking findings

None.

Non-blocking findings

None.

What I ran

All three Julia runs used Julia 1.13.2, four Julia threads, one OpenBLAS thread, a review-local temporary directory, and the supplied writable shared depot followed by the default depots. Absolute depot locations are represented by $REVIEW_DEPOT in the commands below. Dependency setup and drivers were outside the source checkout; no package suite or Pkg.test() was run.

Blind inspection and identity:

gh pr view 1366 --repo SciML/NonlinearSolve.jl --json number,url,state,isDraft,headRefOid,baseRefName,baseRefOid
git -C src fetch origin +refs/pull/1366/head:refs/remotes/pr/1366 master
git -C src rev-parse HEAD
git -C src diff --stat origin/master...HEAD
git -C src diff origin/master...HEAD
git -C src merge-base origin/master HEAD
sha256sum INITIAL.md > INITIAL.sha256

The open draft's head matches TARGET.md. The PR-reported base and diff merge-base are dd8a550b79c4c9ea72a7b95b9233a34ffdb5bd8e, recorded in Base above; the fetched current master tip is 8e21fb51a29320c57d206f71c163ff24253a1962. I read the repository instructions, changed files, surrounding cache initialization/update/reinitialization code, and SparseArrays' separate multiplication and transpose implementations before running the probes. The initial assessment was sealed before reading author context. Subsequent read-only metadata commands were:

gh pr view 1366 --repo SciML/NonlinearSolve.jl --json title,body,commits,statusCheckRollup
git -C src log -1 --no-merges --format=%B
git -C src diff --check origin/master...HEAD

Diff whitespace check exited 0. The newest non-merge commit supplies the exact author trailers used below.

Run 1, head, exit 0:

JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --project=env run-head.jl

The driver called Pkg.instantiate(; update_registry=false, allow_autoprecomp=false) in a temporary environment pointing to the head's NonlinearSolveBase, NonlinearSolveFirstOrder, and SciMLJacobianOperators, then included the two new files in separate modules. Output: bitwise sparse products 12/12; LM allocation assertions 2/2; TrustRegion allocations/residual 3/3; default and KLU reinit 6/6 each; growing-pattern sparse/dense comparison 6/6. Total 35/35.

Run 2, unfixed merge-base, exit 1 as expected:

git -C src archive dd8a550b79c4c9ea72a7b95b9233a34ffdb5bd8e | tar -x -C base-src
JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --project=env-base run-base.jl

The base environment reused the head run's resolved dependency versions, changing the three local source paths to the archived base. The driver included the head's complete lib/NonlinearSolveFirstOrder/test/sparsity_tests__item4.jl and the unchanged imports, residual function, and allocation testsets from sparsity_tests__item3.jl; the tests for newly introduced helper names were excluded on base because those names do not exist there. An outer testset allowed all included assertions to execute. Output: LM, both geodesic settings, 47632 < 1000 fails twice; TrustRegion, 239504 < 1000 fails once. Summary: 20 passed, 3 failed, 0 errored. Thus the added allocation regressions fail before and pass after from my own runs; the reinit and growing-pattern assertions also pass on base and do not demonstrate new bug fixes.

Run 3, independent head probe, exit 0:

JULIA_NUM_THREADS=4 OPENBLAS_NUM_THREADS=1 JULIA_NUM_PRECOMPILE_TASKS=1 JULIA_PKG_PRECOMPILE_AUTO=0 TMPDIR="$PWD/tmp" JULIA_DEPOT_PATH="$REVIEW_DEPOT:" timeout 3600 julia +1.13.2 --startup-file=no --project=env probe.jl

Output: Independent dense Gramian and workspace reuse | 672 672; Analytic sparse rectangular root | 12 12. The first compares against dense multiplication using small exactly representable integer-valued matrices, covering Float32/Float64/ComplexF64, Int32/Int64 indices, empty/tall/wide shapes, repeated pattern growth/shrinkage, and value updates through reused workspaces. The second uses a full-column-rank 5×3 analytic linear residual with a known root, default/KLU TrustRegion and KLU Levenberg–Marquardt, then changes the root parameter through reinit. No fourth Julia run was made.

CI inspection used gh pr checks 1366 --repo SciML/NonlinearSolve.jl, gh run view <run> --repo SciML/NonlinearSolve.jl --log-failed, and default-branch gh run list --repo SciML/NonlinearSolve.jl --branch master --event push --limit 5, supplemented by workflow-specific lists around the head's CI date. GitHub CLI log caching initially hit the read-only default cache; redirecting XDG_CACHE_HOME into the review temporary directory allowed inspection.

  • Sublibrary CI: NonlinearSolveBase and NonlinearSolveFirstOrder Core pass on Julia 1/lts/pre; NonlinearSolveBase QA passes. SCC's failure is isconcretetype(eltype(scc_sol_debug.original)) at lib/SCCNonlinearSolve/test/core_tests__item4.jl:100; the identical assertion and evaluated non-concrete solution type fail on master e903b6b.
  • Root CI: two LTS Core jobs error on solve!() inference at test/Core/core_tests__item3.jl:27. Both platforms fail that same inference test on the unfixed master base; I compared the exception text, including a matching normalized complete type signature. Other root Core, Downstream, CUDA, and Adjoint jobs pass. Current master has a different GPUCompiler-warning failure, which was not used to excuse these PR failures.
  • IntegrationTest: all eight downstream groups pass, covering ModelingToolkit, OrdinaryDiffEq, BoundaryValueDiffEq, and DiffEqCallbacks.
  • Documentation and downgrade pass.
  • Benchmark CI: both versions pass. I downloaded and inspected the Julia 1 before/after JSON artifact: dense Powell TrustRegion minimum 18,821 → 18,601 ns with 6,832 bytes unchanged, and dense LM minimum 430,661 → 428,569 ns with 272,048 bytes unchanged. The suite contains no sparse benchmark. Other timings vary, including a roughly 10% increase for bounded-default nonlinear Poisson with identical allocation counts; I did not establish causation or timing significance. The direct sparse allocation improvement is independently demonstrated by runs 1 and 2 above.

What I did not verify

I did not reproduce the author's sparse wall-time or full-solve bitwise-identity claims, run a full package/Core/QA/downstream suite locally, build docs locally, or run additional Julia versions/platforms. No local GPU, reverse-mode AD, Reactant, or MPI execution was performed; head CI's CUDA and Adjoint jobs pass, and the changed specialized kernel operates on CPU SparseMatrixCSC storage. I did not add probes for other sparse layouts, explicit operator preconditioning, or failure recovery after arithmetic exceptions. Base testing omitted the newly introduced helper-API assertions and the third probe's analytic cases; only the allocation regressions have my failing-before/passing-after evidence. Existing CI failures were compared through logs, not rerun locally.

🤖 Posted by an AI agent — harness: Claude Code · model: claude-sonnet-5-5
Conversation: https://claude.ai/code/session_01379heiiB35TtywhR7uSU74

@ChrisRackauckas-Claude
ChrisRackauckas-Claude marked this pull request as ready for review November 2, 2026 02:05
ChrisRackauckas and others added 3 commits November 7, 2026 23:33
Retain the public normal-form helper API and sparse TrustRegion coverage
when integrating the upstream sparse-workspace changes.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.164.0
Agent-Model: gpt-6.1-sol
Agent-Session: local fixer job SciML__NonlinearSolve.jl__1366 (no session URL)
…on-alloc

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Muse <[email protected]>
Agent-Harness: Muse CLI Code
Agent-Model: muse-wonder-full-1.0
Agent-Session: local fixer job SciML__NonlinearSolve.jl__1366 (no session URL)
TaylorDiff 0.3.5 fails to precompile with Symbolics 7.48: its load-time derivative tracing evaluates a ChainRules frule on a symbolic variable and hits a non-boolean Symbolics.Num in a boolean context. TaylorDiff 0.3.6 derives those expressions from DiffRules instead. Raise the compat floor so no resolution picks the broken releases.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Muse <[email protected]>
Agent-Harness: Muse CLI Code
Agent-Model: muse-wonder-full-1.0
Agent-Session: local fixer job SciML__NonlinearSolve.jl__1366 (no session URL)
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #1366

Reviewed head: 5ecbf98
Raw SHA-256: 6d6c5203a3f5b0794bc8a9e1bd3c6dccfcf6308ab00dea7bb1fb447dd8fc65f8
Source SHA-256: 78347d5e664d0caf48e1b21507489815e2c027310b320bd04bc17f34ab5de5a8
Source: standard-review-v1 (harness-log)
Reviewer session: 01a21624-54d0-78c3-bd26-014f2a6ff537
Slot: 1
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-high (MH1)
  • Verdict: CHANGES
  • Reviewed head: 5ecbf98

Review report

VERDICT: CHANGES
Round: 3
Head: 5ecbf98
Slot: 1
CI: CI unreadable; review only; merge gates unchanged
Session: 01a21624-54d0-78c3-bd26-014f2a6ff537
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

medium-high (MH1: allocation behavior changes on the default TrustRegion sparse normal-form path, with downstream validation outstanding)

Blocking findings

  • Blocking priorities: P2, P2

  • [P2] lib/NonlinearSolveFirstOrder/test/sparsity_tests__item4.jl:111 accepts two stalled solves. The test passed all six assertions on the head while both solves returned ReturnCode.Stalled. Independently evaluating f_grow at their returned iterates gave an infinity-norm residual of 0.11276536241299273 for each, against the requested 1e-10 absolute tolerance. The reference cache was a dense Matrix{Float64}, and the sparse Jacobian grew from three to seven entries. The test checks Gram matrix consistency after growth and allows both solvers to miss the root. The base produced the same stalled results.

    Implementation fix. In the same file, change f_grow, j_grow, and their in-place adapters to use a system with an accessible analytic root, such as [x + y^2 / 2 - 2, y - 1] from [0, 0], whose root is [1.5, 1]. The off-diagonal Jacobian entry is y, so the sparse prototype starts diagonal and gains an entry after the first step. Assert SciMLBase.successful_retcode for both sparse and dense solves, check the analytic root and the independently recomputed residual against an explicit absolute tolerance, and assert that the sparse Jacobian gained an entry and its cached Gram matrix equals transpose(J) * J. The scratch probe with this system passed on both revisions with the default solver and KLU.

  • [P2] lib/NonlinearSolveHomotopyContinuation/Project.toml:43 raises the TaylorDiff floor in a TrustRegion allocation change. Julia's compatibility parser admitted 0.3.1 and 0.3.5 at the base and excluded each at the head. The diff contains no homotopy implementation change that uses the higher floor. The repository's scope rule calls for a separate compat change.

    Implementation fix. Restore TaylorDiff = "0.3.1" in this patch. If the higher floor is needed, isolate it and add a minimum-version homotopy test run with TaylorDiff pinned at each proposed floor in turn. Identify the Core or QA assertion that requires 0.3.6 and show its result on both pins.

Non-blocking findings

None.

What I ran

  • git diff --name-status -M origin/master...HEAD listed 12 changed paths with no renames or H6 changes. git diff --check origin/master...HEAD exited 0. The review checkout was clean afterward.
  • On Julia 1.12.4, ran GROUP=Core julia --startup-file=no --project -e 'using Pkg; Pkg.instantiate(); Pkg.test()' in the FirstOrder and HomotopyContinuation scratch sublibraries. Both reported tests passed. The FirstOrder sparsity tests passed 56 assertions, including 21 for the new TrustRegion cases. HomotopyContinuation passed 191 assertions with TaylorDiff 0.3.6.
  • In the Base scratch sublibrary, GROUP=Core julia --startup-file=no --project -e 'using Pkg; Pkg.test()' passed, and GROUP=QA julia --startup-file=no --project -e 'using Pkg; Pkg.instantiate(); Pkg.test()' passed 20/20.
  • Included sparsity_tests__item3.jl and sparsity_tests__item4.jl with bounds checking on Julia 1.10.12 and 1.12.4. All 35 assertions passed on each. Running the head's allocation test with merge-base code and the same Julia 1.12.4 dependency versions failed at 239568 < 1000. A separate instrumented run observed 239,488 bytes on the measured step that refreshed the Jacobian at the base and zero at the head.
  • Ran the scratch pattern probe with bounds checking against both revisions. Both passed 123/123, covering Gram matrix equivalence and buffer reuse through changed patterns, 32-bit sparse indices, complex values that distinguish transpose from adjoint, and known-root solves with pattern growth and shrinkage across reinit!.
  • julia --startup-file=no --project=docs docs/make.jl initially reported that the archive lacked Git remote metadata. The retry in a scratch Git checkout exited 0 and rendered both public hooks. Documenter emitted HTML-size warnings. The focused rendering probe also passed.
  • uv run --locked python --version printed Python 3.10.12 and warned that --locked has no effect outside a project. The checkout has no Python project or lockfile, so there was no project Python interpreter to verify.

What I did not verify

CI results, the downstream suites and named dependents needed to validate the default path, and the remaining Julia and platform matrix.

AUTHOR_GRADE: {"task":"perf","score":3,"difficulty":3,"rounds":3,"author_harness":"Muse CLI Code","author_model":"muse-wonder-full-1.0","note":"The allocation regression test discriminates and the independent pattern probes pass. The growth fixture accepts stalled solves and the diff includes an unrelated TaylorDiff compatibility change."}

Head link: 5ecbf98


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a21624-54d0-78c3-bd26-014f2a6ff537 (no session URL)

ChrisRackauckas and others added 2 commits November 27, 2026 14:34
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.169.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__NonlinearSolve.jl__1366--20261127T150430Z-codex-gpt-6.2-sol
Agent-Session: local session 01a21d89-8442-7df1-aaa6-69366cd14518 (no session URL)
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Codex <[email protected]>
Agent-Harness: Codex CLI 0.169.0
Agent-Model: gpt-6.2-sol
Agent-Job: SciML__NonlinearSolve.jl__1366--20261127T150430Z-codex-gpt-6.2-sol
Agent-Session: local session 01a21d89-8442-7df1-aaa6-69366cd14518 (no session URL)
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

🤖 Automated comment from an AI agent running as @ChrisRackauckas — not written or reviewed by Chris.

PR: #1366

Reviewed head: 0cae4c0
Raw SHA-256: 9f4651330456ed98f1e390da5e23b50564fc1d04f29e413aacdd89e1b1c992a0
Source SHA-256: a8e277c1aadb41a586483b4864349996c3dd0112080e9318018fde57a81294aa
Source: standard-review-v1 (harness-log)
Reviewer session: 01a21e5e-d3ec-73e1-9507-4445c3d184d1
Slot: 2
Confidence: unknown
Own risk fixed before author rating/discussion: yes
Redaction: ran (substitutions=0)

Risk assessment

  • Risk: medium-high (MH1)
  • Verdict: CHANGES
  • Reviewed head: 0cae4c0

Review report

VERDICT: CHANGES
Round: 7
Head: 0cae4c0
Slot: 2
CI: CI unreadable; review only; merge gates unchanged
Session: 01a21e5e-d3ec-73e1-9507-4445c3d184d1
Reviewer: codex-cli 0.170.0; model: gpt-6.2-sol

Risk

medium-high (MH1: the default sparse TrustRegion path changes Gram matrix cache reuse, with downstream performance and compatibility unverified)

Blocking findings

  • Blocking priorities: P2
  • [P2] lib/NonlinearSolveBase/ext/NonlinearSolveBaseSparseArraysExt.jl:138 can silently return the wrong Gram matrix when the destination aliases the input. With J = sparse([2.0 0.0; 1.0 3.0]), the public call normal_form_jacobian!!(J, J, normal_form_workspace(J)) returned [34.0 27.0; 27.0 81.0] and overwrote J. The product computed before the call was [5.0 3.0; 3.0 9.0]. The sparse kernel writes into J before detecting the pattern mismatch, so the fallback multiplies the modified input. The public docstring gives no aliasing restriction.
    Implementation fix. Either support aliasing through an allocating path or require separate storage. I recommend separate storage so the hook has a consistent contract across dense and sparse layouts. Add “The destination must not share storage with J” to the normal_form_jacobian!! docstring in lib/NonlinearSolveBase/src/descent/common.jl:99. In the sparse method, reject nonzeros(JᵀJ) === nonzeros(J) with ArgumentError before the first write. Add the triangular example to lib/NonlinearSolveFirstOrder/test/sparsity_tests__item3.jl and assert the error and that J still equals a saved copy. The damped Newton and Moré caches already supply separate buffers.

Non-blocking findings

  • lib/NonlinearSolveFirstOrder/test/sparsity_tests__item4.jl:46 and :64 accept unsuccessful Bratu solves. On Julia 1.12.4, the 1,000-variable allocation fixture returned Stalled with residual norm 3.80e-10. In the 200-variable reinit fixture, the fresh and reused solves both returned Stalled with the default linear solver and both returned ShrinkThresholdExceeded with KLU. Their states and return codes still matched.
    Implementation fix. Give the separate convergence solve and the fresh and reused 200-variable solves abstol = 1.0e-8. Assert SciMLBase.successful_retcode for each and recompute the residual with bratu! at the returned state and the corresponding parameters, keeping the existing norm(r) < 1.0e-8 bound. With the explicit tolerance, the probe returned Success and met that bound for the 1,000-variable allocation fixture and for both 200-variable reinit configurations. Keep the warmed allocation measurement on its existing cache settings.

What I ran

  • git diff --name-status -M origin/master...HEAD listed 11 changed files and zero renames. git diff --check, Runic on the changed Julia files, and typos on added lines exited 0.
  • GROUP=Core julia --project=<sublibrary> -e 'using Pkg; Pkg.test()' passed for NonlinearSolveBase and NonlinearSolveFirstOrder on Julia 1.12.4. FirstOrder reported TrustRegion sparse normal-form | 26 26 and SciMLOperator Jacobians | 14 14. NonlinearSolveBase GROUP=QA passed 20/20.
  • Directly included lib/NonlinearSolveFirstOrder/test/sparsity_tests.jl with its resolved test dependencies on Julia 1.10.12 and 1.12.4. Each run passed 61/61.
  • Replayed the submitted Bratu allocation threshold on the base and the reviewed head with the same resolved dependencies. The measured five steps allocated [0, 0, 0, 239360, 0] bytes on the base and [0, 0, 0, 0, 0] on the head. The Jacobian counter went from 3 to 4 on both. The < 1000 assertion failed on the base and passed on the head.
  • Sparse Gram probes passed 612/612 assertions across changing patterns, matrix shapes, value types, and CSC index types. Analytic rectangular problems passed 12/12 with KLU and 12/12 with preconditioned GMRES across parameter changes. GMRES invoked the preconditioner 25 times with sparse matrices. The alias and Bratu return-code probes produced the results above.
  • julia --project=docs ran docs/make.jl with the deployment call omitted. Documenter completed doctests, cross-references, document checks, and HTML rendering with exit 0. Both new API entries appeared in the rendered developer guide.
  • uv run --locked python --version printed Python 3.13.13. The checkout has no uv.lock, and uv reported that --locked had no effect outside a project.

What I did not verify

  • Downstream integration and performance outside the measured sparse Bratu fixture.
  • Julia versions other than 1.10.12 and 1.12.4. GitHub CI remains unreadable for this review.

AUTHOR_GRADE: {"task": "perf", "score": 4, "difficulty": 3, "rounds": 7, "author_harness": "Codex CLI 0.169.0", "author_model": "gpt-6.2-sol", "note": "Independent replay established the allocation improvement and the affected suites passed. The new public helper silently returns a wrong product for the reproduced alias case."}

REVIEWER_GRADE: {"task": "perf", "score": 3, "rounds": 7, "reviewer_harness": "codex", "reviewer_model": "gpt-6.2-sol", "verdict": "missed", "note": "The allocation benchmark distinguished base from head, but the MERGE review missed a public API bug: passing J as its own destination returned 34 instead of 5 in the first Gram entry. It also missed that the Bratu tests accept unsuccessful return codes."}

Head link: 0cae4c0


🤖 Posted by an AI agent — harness: codex-cli 0.170.0 · model: gpt-6.2-sol
Conversation: local session 01a21e5e-d3ec-73e1-9507-4445c3d184d1 (no session URL)

This branch has not been deployed

No deployments
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