Skip to content

Convert Krylov Vector seeds to SVector for Enzyme VJP in SciMLJacobianOperators - #1356

Merged
ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/jo-enzyme-svector-krylov-seed
Oct 5, 2026
Merged

ChrisRackauckas merged 5 commits into
SciML:masterfrom
ChrisRackauckas-Claude:agent/jo-enzyme-svector-krylov-seed

Conversation

@ChrisRackauckas-Claude

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

Copy link
Copy Markdown
Member

Summary

Downgrade Sublibraries for lib/NonlinearSolveFirstOrder fails on TrustRegion OOP with SVector{2,Float64} when reverse AD is AutoEnzyme: KrylovJL workspaces feed dense Vector{Float64} seeds into a SciMLJacobianOperators VJP prepared on SVector state, and Enzyme's reverse thunk TypeErrors (expected SVector, got Vector). Raising Enzyme/DifferentiationInterface alone does not fix this on Julia 1.10 LTS.

Fix in SciMLJacobianOperators 0.1.20: Enzyme-only, reshape Krylov seeds into the primal container while keeping the seed eltype (so Float32 state + Float64/Dual seeds are not narrowed). ForwardDiff, Zygote, and other backends keep a plain reshape, matching master. iip Enzyme output tangents use a same-eltype typed temp and copyto! back. FirstOrder and NonlinearSolveBase compat floors are SciMLJacobianOperators = "0.1.20".

Ignore until reviewed by @ChrisRackauckas

Evidence

Fail at old floor (Julia 1.10.12, Enzyme v0.13.100, DI v0.7.3, unpatched JO):

Enzyme = 0.13.100
FAIL TypeError: in ccall argument 5, expected SVector{2, Float64}, got a value of type Vector{Float64}

Pass at new code + same floor:

Enzyme = 0.13.100
PASS retcode=Success u=[1.4142135625402792, 1.4142135625402792]

Local Core after review round 3 (b6f99a3):

Suite Result
SciMLJacobianOperators Core @ floor Static / partitioned … | 15 15, exit=0
SciMLJacobianOperators Core @ latest Static / partitioned … | 15 15, exit=0
NonlinearSolveFirstOrder Core @ floor TrustRegion | 1596 1596 61m31.8s, exit=0

JO core_tests__item7.jl: SVector OOP Enzyme, MVector iip Enzyme, ArrayPartition ForwardDiff, Vector←Vector shared reshape, plus Float32/1e40/2^-30 and ForwardDiff.jacobian(v -> sop*v, …) (reviewer mixed-precision / nested-AD reproducers).

Follow-up (out of scope here)

Pre-existing FirstOrder QA ExplicitImports failure for non-public RobustTrustRegionLinsolve is #1357.

Why non-downgrade FirstOrder CI looked green on master

On the failing SHA, normal SublibraryCI often never ran FirstOrder's LTS AutoEnzyme path: affected-only selection skipped FirstOrder unless it changed, and transitively-affected libs run Julia "1" (≥1.12) where tests drop AutoEnzyme. Downgrade always exercises FirstOrder on LTS with Enzyme.

What was not verified

  • Full Downgrade Sublibraries matrix for other lib/* packages after this change
  • Non-LTS Julia / prerelease Enzyme paths (tests skip AutoEnzyme on prerelease and Julia ≥ 1.12)
  • Whether upstream DI Enzyme tangent normalization would supersede this coerce

Risk assessment

  • Risk: Medium. Enzyme VJP/JVP seed/tangent container shaping; other backends stay on reshape-only.
  • Blast radius: Krylov / dense-Vector workspaces against static-array state with AutoEnzyme; consumers resolving JO ≥0.1.20.
  • Evidence: Fail→pass at CI floor Enzyme 0.13.100; JO unit tests including mixed eltype / nested ForwardDiff; JO Core green at floor and latest; FirstOrder Core green at floor.
  • Independent review: round 3 CHANGES (eltype narrowing) addressed
  • Merge: after @ChrisRackauckas review; Declare RobustTrustRegionLinsolve public in NonlinearSolveBase #1357 can land independently

🤖 Generated with Cursor Agent CLI (model: auto) — session: local transcript ~/sandbox/goals/ci-green/work/cig-nls-firstorder-downgrade/log.txt on amdci2

Risk assessment (independent review, head b6f99a3)

  • Risk: low
  • Blast radius: SciMLJacobianOperators JVP/VJP seed and tangent shaping, gated to AutoEnzyme / AutoSparse(AutoEnzyme). Non-Enzyme backends get the same reshape as master.
  • Evidence: Astra's round-1 blocking reproducers (Float32 SVector state with Float64 seeds of 1e40 and 1+2^-30 under ForwardDiff/Zygote, and nested ForwardDiff.jacobian through sop*v) were rerun on base, da36c42 and head. Head matches base exactly; da36c42 failed. The original Enzyme SVector/Krylov failure errors on base and passes on head, both in the unit test and end to end (TrustRegion and NewtonRaphson with KrylovJL_GMRES). Red checks: Core (lts) inference and SCCNonlinearSolve Core also fail on master 61f721b. FirstOrder QA is the RobustTrustRegionLinsolve issue fixed by Declare RobustTrustRegionLinsolve public in NonlinearSolveBase #1357. benchmark (lts) stays Unsatisfiable until SciMLJacobianOperators 0.1.20 is registered.
  • Independent review: Devin CLI (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium rated it low, high confidence: Astra's regressions are fixed and confirmed by running, and the coercion is confined to the Enzyme backend.
  • Merge: auto-merge candidate. Merge back-to-back with Declare RobustTrustRegionLinsolve public in NonlinearSolveBase #1357. Register SciMLJacobianOperators 0.1.20 before releasing NonlinearSolveBase or NonlinearSolveFirstOrder with the new floors. Non-blocking notes: the two-argument _shaped_like is a dead helper with a trivial test; the Enzyme ArrayPartition path is untested; comments are about 16% of added src lines.

🤖 Risk assessment posted by an AI agent (fleet master) — harness: Devin CLI 3000.11.3 (Mac) / fusion-claude-opus-5-5-high-sidekick-swe-2-medium (adversarial review.sh run); dispatched by Devin CLI 3000.11.3 (Mac) fleet-master caretaker
Conversation: local transcript ~/.local/share/devin/cli/transcripts/speckle-whale.json (Chris's Mac)

ChrisRackauckas and others added 3 commits October 3, 2026 18:23
KrylovJL workspaces pass dense Vector seeds into SciMLJacobianOperators
pullbacks prepared on SVector state; convert seeds to the primal type so
Enzyme reverse no longer TypeErrors under downgrade floors.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: ~/sandbox/goals/ci-green/work/cig-nls-firstorder-downgrade/log.txt (local transcript, amdci2)
Coerce AD seeds/output tangents only when the primal type differs (mutable
similar+copyto!, convert with reshape fallback) so ArrayPartition and iip
MVector paths keep working; add JO regression tests and ignore the
non-public RobustTrustRegionLinsolve import in FirstOrder QA.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: ~/sandbox/goals/ci-green/work/cig-nls-firstorder-downgrade/log.txt (local transcript, amdci2)
Remove the RobustTrustRegionLinsolve ExplicitImports ignore (pre-existing
non-public access belongs in a separate public-API PR). Replace the bare
catch in `_coerce_like` with `applicable(convert, …)`, bump SciMLJacobianOperators
to 0.1.20, and raise FirstOrder/NonlinearSolveBase compat floors so released
users cannot resolve the buggy JO.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: ~/sandbox/goals/ci-green/work/cig-nls-firstorder-downgrade/log.txt (local transcript, amdci2)
ChrisRackauckas and others added 2 commits October 4, 2026 08:52
ForwardDiff/Zygote keep a reshape so Float32 static state with Float64 or
Dual seeds is not narrowed. Enzyme still matches SVector/MVector containers
when eltypes agree. Add mixed-precision and nested-jacobian regression tests.

Co-Authored-By: Chris Rackauckas <[email protected]>
Co-Authored-By: Cursor Agent <[email protected]>
Agent-Harness: Cursor Agent CLI
Agent-Model: auto
Agent-Session: ~/sandbox/goals/ci-green/work/cig-nls-firstorder-downgrade/log.txt (local transcript, amdci2)
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[1m]
Agent-Session: https://claude.ai/code/session_011aK5Xvp9NpdkzKuEwtiMGd
@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review October 5, 2026 05:02
@ChrisRackauckas
ChrisRackauckas merged commit 0055e31 into SciML:master Oct 5, 2026
104 of 108 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.

2 participants