Skip to content

Add R2N and R2NLS solvers with HSL and QRMumps support#347

Open
farhadrclass wants to merge 77 commits into
JuliaSmoothOptimizers:mainfrom
Farhad-phd:R2N_R2NLS_2026_Jan
Open

Add R2N and R2NLS solvers with HSL and QRMumps support#347
farhadrclass wants to merge 77 commits into
JuliaSmoothOptimizers:mainfrom
Farhad-phd:R2N_R2NLS_2026_Jan

Conversation

@farhadrclass

Copy link
Copy Markdown
Contributor

Introduces new second-order quadratic regularization solvers R2N and R2NLS for unconstrained and nonlinear least-squares optimization. Adds support for HSL (MA97, MA57) and QRMumps direct solvers, updates documentation and README, and extends test coverage for the new solvers. Updates dependencies and compat entries in Project.toml.

Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated
Comment thread src/R2N.jl Outdated

@dpo dpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots more comments on R2NLS.

Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated

@dpo dpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose a cleaner subsolver API.

Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
@farhadrclass

Copy link
Copy Markdown
Contributor Author

@dpo I have refactor the R2NLS,

@dpo dpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks great. Here are a few minor comments.

Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
@farhadrclass

Copy link
Copy Markdown
Contributor Author

@dpo pushed the R2NLS now,
moving to the R2N

@dpo dpo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few more comments. Starting to look great!

Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl Outdated
@farhadrclass

Copy link
Copy Markdown
Contributor Author

@dpo I didn't move x_init to x0 since by doing so, we would remove the connection between LinearOp jac relying on x to be update to update the Jacobean, I can however add a new x_op to solver structure but that would allocate a memory and at the end do the same thing,

In the constructor, I am linking x which will be updated in each iteration to jacobean

Let me know what you think

Remove stored gradient-difference state and inline quasi-Newton updates from R2NSolver/solve!. Introduce a callback_quasi_newton argument (with default) and invoke it before the main callbacks and again each iteration, so quasi-Newton models can update their Hessian approximations externally. Removed the y field, its allocations and uses, and the direct push! of s,y into QuasiNewtonModel; added set_step_status! calls when steps are accepted/rejected. This decouples quasi-Newton bookkeeping from the solver core and provides a flexible callback hook for Hessian updates.
Convert symbol-based subsolver options to concrete subsolver types across code and tests, update test names accordingly, and make related fixes. Key changes:

- Use max(T(1e-8), nextfloat(zero(T))) for R2N_ls_min_alpha to avoid denormals.
- Add an error check in R2N to require minimization problems.
- Ensure R2NLS σ is stored with correct type via T(eps(...) ).
- Replace symbol subsolver args (e.g. :qrmumps, :lsmr, :cgls, :lsqr, :shifted_lbfgs, :ma97, :ma57) with corresponding subsolver types (QRMumpsSubsolver, LSMRSubsolver, CGLSSubsolver, LSQRSubsolver, ShiftedLBFGSSolver, MA97R2NSubsolver, MA57R2NSubsolver) and adjust npc_handler naming where applicable.
- Rename several test entries to reflect the new solver identifiers (e.g. R2N_exact -> R2N_ShiftedLBFGS) and update allocation, consistency, restart, runtests, and solver test suites.
- Add callback tests for R2N and R2NLS ensuring solver.σ > 0 at an intermediate iteration.
- Use NLPModels.reset! explicitly in tests and apply minor whitespace/newline tidying.

These changes standardize subsolver usage, fix type and behaviour issues, and align tests with the new API.
Add an "Unconstrained Benchmark" section to docs/src/benchmark.md demonstrating how to benchmark unconstrained solvers (example comparing R2N vs trunk on pnames_unconstrained), including sample code to run bmark_solvers and inspect stats, plus a note about using the same pattern for R2NLS on NLS problems. Update docs/src/index.md to clarify that Krylov.jl is used by TRON, TRUNK, R2N, and R2NLS for solving Newton/regularized/trust-region subproblems, and list R2N as supported for callback_quasi_newton. Also include a minor whitespace/formatting adjustment.
@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

@farhadrclass farhadrclass marked this pull request as ready for review June 17, 2026 15:37
Copilot AI review requested due to automatic review settings June 17, 2026 15:37
@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

@farhadrclass

Copy link
Copy Markdown
Contributor Author

@dpo This is ready for review

@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds two new inexact second-order quadratic regularization solvers—R2N (unconstrained NLP) and R2NLS (unconstrained NLS)—including new subsolver backends (HSL MA97/MA57 and QRMumps/Krylov), plus associated documentation and tests.

Changes:

  • Introduces R2N / R2NLS solver implementations and shared subsolver interfaces.
  • Adds HSL and QRMumps/Krylov-based subsolvers and integrates them into the package.
  • Updates tests, README, and docs; expands solver listings and benchmarks; updates dependencies/compat.

Reviewed changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/JSOSolvers.jl Wires new solver/subsolver modules into the package entrypoint and updates imports/deps usage.
src/r2n_subsolver_common.jl Adds shared abstract interfaces/utilities for R2N/R2NLS subsolvers.
src/R2N_subsolvers.jl Implements R2N subsolvers (Krylov, Shifted-LBFGS, HSL MA97/MA57).
src/R2N.jl Implements the new R2N solver + parameter set.
src/R2NLS_subsolvers.jl Implements R2NLS subsolvers (QRMumps + Krylov-based).
src/R2NLS.jl Implements the new R2NLS solver + parameter set.
Project.toml Adds new dependencies and compat bounds needed by the new solvers/subsolvers.
README.md Documents the new solvers at a high level and updates usage examples.
docs/src/index.md Updates dependency descriptions to include R2N/R2NLS usage of Krylov + callback_quasi_newton support.
docs/src/solvers.md Adds R2N/R2NLS to solver listings and categorization tables.
docs/src/benchmark.md Adds an example benchmark section for unconstrained solvers (incl. R2N).
test/runtests.jl Hooks new parameter-set tests and new HSL test file into the test runner.
test/test_solvers.jl Extends solver test matrix to cover R2N and R2NLS variants/subsolvers.
test/test_hsl_subsolver.jl Adds HSL-backed R2N solver tests gated by LIBHSL_isfunctional().
test/restart.jl Extends restart tests to cover R2N and R2NLS solver variants/subsolvers.
test/incompatible.jl Adds incompatible-problem checks for R2N and R2NLS.
test/consistency.jl Adds consistency checks for R2N and R2NLS (incl. shifted-LBFGS and QRMumps).
test/callback.jl Adds callback behavior tests for R2N and R2NLS.
test/allocs.jl Extends allocation tests to include R2N and R2NLS solver variants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/R2NLS.jl Outdated
Comment thread src/R2NLS.jl
Comment thread src/R2NLS.jl
Comment thread src/R2N.jl
Comment thread test/allocs.jl
Comment thread test/runtests.jl
Comment thread docs/src/solvers.md Outdated
Comment thread docs/src/index.md
farhadrclass and others added 2 commits June 17, 2026 18:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

@github-actions

Copy link
Copy Markdown
Contributor
Package name latest stable
FletcherPenaltySolver
JSOSuite
PartiallySeparableNLPModels
Percival

@farhadrclass farhadrclass requested a review from dpo June 19, 2026 11:45
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.

4 participants