Repository navigation
perf(evaluator): cache Jacobian values so J^T w under L-BFGS reuses them - #164
Open
aarontrowbridge wants to merge 2 commits into
Open
aarontrowbridge wants to merge 2 commits into
aarontrowbridge wants to merge 2 commits into
Conversation
added 2 commits
October 24, 2026 13:11
…it-identical iterate (#163) Under compact_lbfgs MadNLP calls the transpose product every iteration (at the previous iterate), and each call re-evaluated the full constraint Jacobian. Keep a two-slot FIFO cache of (copied packed iterate, values), filled by eval_constraint_jacobian and by recomputing products; hits are exact (isequal), allocation-free, and counted in _jacobian_cache_hits. Correct the seam comment: Jᵀw is a per-iteration caller, not only restoration/robust.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Member
Author
|
Production-problem A/B (bosonic GKP |0_L⟩ prep, 30-knot ket spline, state dim 200, 6,083 variables; Modal 8 cores each, same image except DirectTrajOpt): resume from the same checkpoint, 4 MadNLP
|
aarontrowbridge
marked this pull request as ready for review
October 24, 2026 17:52
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.
Closes #163.
What
Under MadNLP's$J^\top l$ via
hessian_approximation = "compact_lbfgs", the L-BFGS update asks forMOI.eval_constraint_jacobian_transpose_producton every iteration, and the evaluator answered each request by re-evaluating the full constraint Jacobian. On spline-integrator problems that is ~45% of wall time, booked by MadNLP as "solver (w/o init./fun./lin. alg.)" rather than as function evaluations (profiled: 328 s of 714 s over 4 iterations on a 30-knot ket spline problem; 22,046 s of a 44,335 s production solve).The evaluator now keeps a two-slot FIFO cache of (exact copy of the packed iterate, Jacobian values), filled by
eval_constraint_jacobianand by any product that had to recompute.J·w/Jᵀwat a bit-identical iterate (elementwiseisequal, no tolerance) reuse the stored values with zero allocation.Why two slots: MadNLP 0.9 requests$J^\top l$ at the previous iterate ($J$ at the current one. A single same-iterate slot gets 1 hit in 15 iterations; LRU gets 2; FIFO with two slots gets 15/15.
qn.last_x) right after evaluatingCorrectness
Returned values are unchanged. A seeded 15-iteration compact_lbfgs solve on the standard test problem has a bit-identical per-iteration trace (k, obj, inf_pr, inf_du), objective, iteration count, and final iterate with the cache on vs off, with hits ≥ iterations − 1.
evaluator._jacobian_cache_enabled = falserestores the old path (used as the test baseline).Tests
7 new testitems (hit after eval for both products, zero-allocation hit path, recompute + refresh at a different iterate including a one-ulp change, in-place mutation of the caller's buffer is not a stale hit, cold cache, L-BFGS access pattern, the bit-identical MadNLP solve). Targeted local run: 48/48 pass. Full suite: this PR's CI.
Found along the way (not fixed here)
MadNLPMOI's$y_k$ may be missing $-A_\text{lin}^\top l$ . Pre-existing; will file separately once confirmed.
eval_constraint_jacobian_transpose_product(::Optimizer, …)writes theqp_data(linear-constraint) contribution intoJtvbefore calling the NLP evaluator, and our evaluator starts withfill!(y, 0), erasing it. For problems with affine MOI constraints the L-BFGS