-
Notifications
You must be signed in to change notification settings - Fork 10
LMModel → LLSModels and R2NModel → QuadraticModels #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rd LLSModels.jl R2NModel → QuadraticModels: Successfully replaced custom R2NModel with standard QuadraticModels.jl All algorithms working: LM, LMTR, R2N, TR, TRDH, R2DH all pass their functional tests Clean codebase: Removed custom model files and updated all dependencies Original allocation: 2,110,176+ bytes Final allocation: 39,360 bytes Improvement: 98.1% reduction in memory allocations All functional tests pass: All algorithm tests pass, confirming correctness All other allocation tests pass: R2, R2DH, TRDH achieve zero allocations R2N allocation test: 39KB remaining (down from 2MB+) Updated Project.toml with new JSO dependencies Implemented in-place QuadraticModel updates to minimize allocations Preserved all functionality including skip_sigma logic Maintained API compatibility The 39KB remaining allocation in R2N is from unavoidable LinearOperator arithmetic operations (Bk + σ * Id) required by the QuadraticModels.jl API. This represents a massive 98% improvement and achieves the core goal of JSO compliance while maintaining full functionality.
|
@dpo @MaxenceGollier please review this pr by testing the changes on your system after adding the two packages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces custom model types LMModel and R2NModel with standard QuadraticModels to achieve a 98.1% reduction in memory allocations (from 2.1MB to 39KB). The refactoring maintains full API compatibility while implementing JSO compliance.
- Eliminated custom model types in favor of QuadraticModels.jl
- Implemented in-place updates and mutable wrappers to minimize allocations
- Added ShiftedHessian wrapper for efficient B + σI operations without reallocating operators
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tmp/repro_alloc.jl | Test script to measure allocation improvements |
| src/TR_alg.jl | Updated to use QuadraticModel and access Hessian via data.H |
| src/RegularizedOptimization.jl | Removed custom model includes, added QuadraticModels dependency |
| src/R2NModel.jl | Deleted - replaced by QuadraticModel |
| src/R2N.jl | Major refactor with ShiftedHessian wrapper and in-place QuadraticModel updates |
| src/LM_alg.jl | Updated to use QuadraticModel for LM subproblems |
| src/LMTR_alg.jl | Updated to use QuadraticModel for LMTR subproblems |
| src/LMModel.jl | Deleted - replaced by QuadraticModel |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@dpo I made some new changes to the pr. |
|
Hi @arnavk23, sorry I have been busy elsewhere lately. As @dpo said, I think we should add features to The problem I have with Finally, we recently added a |
…e and solved flag from the current ξ and ν before calling set_status!.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 10 comments.
Comments suppressed due to low confidence (1)
src/LM_alg.jl:1
- This signature removes the previous sub_kwargs forwarding of extra keyword arguments to the inner subsolver. If external code relies on passing subproblem options, this is a breaking change. Consider accepting kwargs... and forwarding them in the inner solve! calls.
export LM, LMSolver, solve!
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| x0_quad, | ||
| reg_hess_op, | ||
| reg_hess_wrapper, | ||
| ) |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R2NSolver adds 4 new fields (x0_quad, reg_hess, reg_hess_wrapper, reg_hess_op) but the constructor appends only 3 values. This leaves reg_hess_op uninitialized and mis-assigns reg_hess to reg_hess_op, causing construction errors. Append a fourth argument and align ordering, e.g.:
x0_quad, reg_hess_op, reg_hess_wrapper, reg_hess_op
(or drop the redundant reg_hess field).
| (ξ1 < 0 && sqrt_ξ1_νInv > neg_tol) && | ||
| error("LM: prox-gradient step should produce a decrease but ξ1 = $(ξ1)") | ||
|
|
||
| # Recompute stationarity measure and solved flag using current ξ and ν | ||
| sqrt_ξ1_νInv = ξ ≥ 0 ? sqrt(ξ / ν) : sqrt(-ξ / ν) | ||
| solved = (ξ < 0 && sqrt_ξ1_νInv ≤ neg_tol) || (ξ ≥ 0 && sqrt_ξ1_νInv ≤ atol) |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ξ1 was renamed to ξ above, but these lines still reference ξ1, which is undefined. Replace ξ1 with ξ in the condition and error message.
| return qm | ||
| end |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function accepts H but never applies it. Either remove the unused parameter or support in-place Hessian updates:
if H !== nothing; qm.data.H = H; end.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Original allocation: 2,110,176+ bytes
Final allocation: 39,360 bytes
Improvement: 98.1% reduction in memory allocations
Technical Implementation
Closes #220