Skip to content

Fix construct_extension_jac for scalar and non-vector u0 - #1352

Merged
ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/1215-extension-jac-reshape
Oct 3, 2026
Merged

ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/1215-extension-jac-reshape

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Please ignore until reviewed by @ChrisRackauckas.

Summary

construct_extension_jac built the Jacobian cache against the flattened wrapper u0, so scalar states were unwrapped into DI.jacobian and matrix states were differentiated against a shaped p. This PR evaluates the Jacobian at the supplied u0 after restoring prob.u0's native shape, and recovers residual shape independently via resid_prototype (never by equal length alone). Round-1/2 review findings (ignored supplied u0; residual reshaped to state shape) are fixed. Regression tests cover scalar/matrix/vector, supplied-state ≠ prob.u0, matrix-state/vector-residual resid_prototype, plus CMINPACK / NLsolveJL with explicit ADTypes backends.

Fixes #1215

Fail-before / pass-after

Original shape bug (scalar / 2×2): unit tests error without the native-shape adaptation.

Round-1: supplied u0=[3,4] with prob.u0=[1,2] must yield diag(6,8) for initial_jacobian.

Round-2: matrix state + resid_prototype=zeros(4) failed with DimensionMismatch (residual buffer wrongly made a matrix). After the fix:

Test Summary:                                | Pass  Total  Time
construct_extension_jac scalar and matrix u0 |   10     10  17.4s
unit_exit=0

Test Summary:                     | Pass  Total  Time
CMINPACK explicit ADTypes backend |   18     18  ...
NLsolveJL ... jac_prototype       |   18     18  ...
matrix state / vector residual: CMINPACK | 6  6
matrix state / vector residual: NLsolveJL | 6  6
wrapper_shapes_exit=0

NonlinearSolveBase Core after round-2 fix: passed (extension_jac 10/10).

Commands run

julia +1.12 --project=@runic -e 'using Runic; exit(Runic.main(ARGS))' -- --check \
  lib/NonlinearSolveBase/src/wrappers.jl lib/NonlinearSolveBase/test/extension_jac.jl \
  test/Wrappers/extension_jac_shapes_tests.jl
typos <same files>

timeout 3600 julia +1.12 --compiled-modules=existing --project=scratch/repro \
  -e 'using Test; include(".../extension_jac.jl")'
timeout 3600 julia +1.12 --compiled-modules=existing --project=scratch/repro \
  -e 'using Test; include(".../extension_jac_shapes_tests.jl")'

cd lib/NonlinearSolveBase && GROUP=Core timeout 3600 julia +1.12 --compiled-modules=existing \
  --project=. -e 'using Pkg; Pkg.test(; julia_args=["--compiled-modules=existing"])'

Not verified

  • Full root GROUP=Wrappers after the round-2 follow-up (targeted shapes file + Core only).
  • Other extension wrappers (PETSc, SIAMFANL, …) end-to-end with matrix-state/vector-residual.

Risk assessment

  • Risk: low–medium
  • Blast radius: construct_extension_jac only.
  • Evidence: unit + wrapper shapes (incl. matrix/vector residual) green; Core green after round-2 fix.
  • Independent review: Codex (gpt-6-astra) rated it low, high confidence: round 3 MERGE, no findings — residual-shape (16/16 original/previous/head) and supplied-state probes pass; new resid_prototype regression fails on HEAD^ and passes; unit 10/10, CMINPACK/NLsolveJL shapes 18/18 each; GROUP=Core 545 pass and GROUP=Wrappers 135889 pass (7 unchanged broken); vector-path residual calls and allocations unchanged vs master.
  • Merge: auto-merge candidate once CI shows no regressions.

Please ignore this draft until reviewed by @ChrisRackauckas.

Harness: Cursor Agent CLI 2026.10.01-14929f9; model: auto; transcript: /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu

ChrisRackauckas and others added 5 commits October 2, 2026 02:28
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu
Reshape/unbox the caller’s state into prob.u0’s native shape instead of
substituting the stored guess, and reuse the supplied residual when its
shape is known.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu
Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu
Equal-length residuals must not be reshaped to size(prob.u0); that broke
matrix-state / vector-residual IIP problems under CMINPACK and NLsolveJL.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI 2026.10.01-14929f9
Agent-Model: auto
Agent-Session: local session, transcript at /home/crackauc/sandbox/goals/issue-backlog/ibd/NonlinearSolve.jl/jobs/1215-cursor/log.txt on amdci2.julia.csail.mit.edu
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 3, 2026 05:32
@ChrisRackauckas
ChrisRackauckas merged commit 44e6a9a into SciML:master Oct 3, 2026
93 of 100 checks passed
ChrisRackauckas referenced this pull request Oct 13, 2026
Agent-Harness: Devin CLI 3000.11.3
Agent-Model: Fusion (Claude Opus 5.5 Medium + SWE-2 Medium)
Agent-Session: local transcript ~/.local/share/devin/cli/transcripts/flash-hour.json

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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.

construct_extension_jac is broken for scalar and non-vector u0 with an explicit ADTypes backend

2 participants