Repository navigation
Fix DI prep type-mismatch fallbacks for hess/hv/fg/fgh/lag_h - #1408
Draft
ChrisRackauckas-Claude wants to merge 3 commits into
Draft
ChrisRackauckas-Claude wants to merge 3 commits into
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
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.
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