Repository navigation
Fix DI prep type-mismatch fallbacks for hess/hv/fg/fgh/lag_h - #1408
ChrisRackauckas-Claude wants to merge 3 commits into
Conversation
Extend the existing `_prep_valid` gate beyond grad!/cons_j! so second-order and combined DI operators fall back to prep-free calls when θ/p eltypes or array types differ from construction, avoiding PreparationMismatchError. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-prep/log.txt on amdci2
Share Type-param helper closures (incl. grad!/cons_j!/lag_h!), drop duplicated NullParameters branches, use value_gradient_and_hessian(!) for fgh!, and gate hv! on the tangent type. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-prep/log.txt on amdci2
Named _iip/_oop_ad_cons_jac_clos match the other Type-param factories, build hv prep tangents from zero(x) so SVector v hits the prepared path, and cover IIP packed-vector plus OOP lag_h foreign types. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Cursor Agent <noreply@cursor.com> Agent-Harness: Cursor Agent 2026.10.01-14929f9 Agent-Model: unknown (Cursor auto) Agent-Session: local session, transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-prep/log.txt on amdci2
Independent review (Devin CLI 3000.11.3, model fusion-claude-opus-5-5-high-sidekick-swe-2-medium): MERGE, risk medium. Full reviewVERDICT: MERGE The change sits on the hot path of every DI-backed Blocking findingsNone. What I confirmed by running (details under "What I ran"):
Non-blocking findings
What I ranAll runs used Julia 1.11 with DI 0.7.21, ForwardDiff 1.4.6, ReverseDiff 1.18.5, FiniteDiff 2.33.0, Enzyme 0.13.216 and SciMLBase 3.57.0. I used two scratch envs that differ only in the OptimizationBase source: PR head, or an
What I did not verify
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 |
Summary
Collapses the DI prep-validity fallbacks in
OptimizationDIExt.jlonto shared Type-parameter helper closures (includinggrad!/cons_j!/lag_h!/_ad_cons_jac), fixing the duplicatedNullParametersbranches. Also switches AD-generatedfgh!from DI's scalarvalue_derivative_and_second_derivative(!)tovalue_gradient_and_hessian(!)so the matching-type fast path works, gateshv!on the tangentvtype (built fromzero(x)soSVectortangents hit the prepared path), and adds foreign-type coverage for IIP packed-vector and OOPlag_h.Out of scope (still broken, not addressed here): Dual
pwith second-order ops raisesDualMismatchError(ForwardDiff tag nesting, even with a fresh Dual-pprep); OOPSVectorsolves through OptimJL/Optimisers remain wrapper bugs beyond the unit-levelinstantiate_functionfallback.Verification
Regression (dual_tolerant_tests.jl):
matching-type fgh!→MethodErroronvalue_derivative_and_second_derivative!Matching-type path unchanged (n=10, min ns, master vs PR; identical allocations):
Test groups (Julia 1,
OPTIMIZATION_TEST_GROUP):Probes: Float32/BigFloat/SVector/hv-with-mismatched-
vand matchingfgh!match fresh-prep results; Dual-psecond-order stillDualMismatchError(out of scope).Not verified
a4_generic.jlOptim/Optimisers SVector solve matrix (unit-level covered; wrapper bugs out of scope).OptimizationDISparseExtsecond-order gates (still only cons_j-style).Reviewer pushback
psecond-order / Optim SVector wrappers should be in-scope follow-ups.Please ignore until reviewed by @ChrisRackauckas.
Risk assessment
Independent review: Claude Code (claude-opus-5-5), 3 rounds; round 3 MERGE, risk low (confidence medium-high): matching-type path identical to master (prepared calls, allocations, timings), 46 foreign-type probe cases match a fresh prep, AD 1045/1045 and QA pass; remaining CI failures are known on master (MTK downstream, Reactant downgrade, Manopt Core) or Python-setup infrastructure (PyCMA, SciPy).
🤖 Generated with Cursor Agent 2026.10.01-14929f9 (model: unknown (Cursor auto)), transcript /home/crackauc/sandbox/goals/performance/jobs/opt/opt-prep/log.txt on amdci2; orchestrated by Claude Code (claude-opus-5-5[1m]) https://claude.ai/code/session_01LPHREnnonfLg1VcE1EJovv