Skip to content

Conversation

farhadrclass
Copy link
Contributor

This PR introduces the new R2NLS solver, An inexact second-order quadratic regularization method designed specifically for nonlinear least-squares problems.

The objective is to solve
min ½‖F(x)‖²
where F: ℝⁿ → ℝᵐ is a vector-valued function defining the least-squares residuals.

Copy link

codecov bot commented Jun 22, 2025

Codecov Report

Attention: Patch coverage is 71.93676% with 71 lines in your changes missing coverage. Please review.

Project coverage is 85.96%. Comparing base (52caf59) to head (77719c5).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/utilities.jl 0.00% 51 Missing ⚠️
src/R2NLS.jl 90.09% 20 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #303      +/-   ##
==========================================
- Coverage   89.00%   85.96%   -3.04%     
==========================================
  Files           7        9       +2     
  Lines        1200     1453     +253     
==========================================
+ Hits         1068     1249     +181     
- Misses        132      204      +72     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@tmigot tmigot left a comment

Choose a reason for hiding this comment

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

Thanks @farhadrclass for the PR! I made some preliminary comments.
In general, this can be your working branch, but it would be preferable to have a PR with less features so we can review the core algorithm.
For instance, you can add the QRMumps solver later. Ideally, unless strongly motivated, I would not add any new dependency in this PR.
You are also missing the parameter set like the other solvers

# Default algorithm parameter values

The tests are not passing (why?), and the test in the docstring as well.

Comment on lines 40 to 48
@testset "NLS with $mtd" for (mtd, solver) in [
("trunk", trunk),
("R2NLS", (unls; kwargs...) -> R2NLS(unls; kwargs...)),
("R2NLS_CGLS", (unls; kwargs...) -> R2NLS(unls, subsolver = :cgls; kwargs...)),
("R2NLS_LSQR", (unls; kwargs...) -> R2NLS(unls, subsolver = :lsqr; kwargs...)),
("R2NLS_CRLS", (unls; kwargs...) -> R2NLS(unls, subsolver = :lsqr; kwargs...)),
("R2NLS_LSMR", (unls; kwargs...) -> R2NLS(unls, subsolver = :lsmr; kwargs...)),
("R2NLS_QRMumps", (unls; kwargs...) -> R2NLS(unls, subsolver= :qrmumps; kwargs...)),
]
Copy link
Member

Choose a reason for hiding this comment

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

Why are you adding the strings here? I think the function was sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to test different subsolver

test/runtests.jl Outdated
("R2NLS_LSQR", (nlp; kwargs...) -> R2NLS(nlp, subsolver = :lsqr; kwargs...)),
("R2NLS_CRLS", (nlp; kwargs...) -> R2NLS(nlp, subsolver = :lsqr; kwargs...)),
("R2NLS_LSMR", (nlp; kwargs...) -> R2NLS(nlp, subsolver = :lsmr; kwargs...)),
("R2NLS_QRMumps", (nlp; kwargs...) -> R2NLS(nlp, subsolver = :qrmumps; kwargs...)),
Copy link
Member

Choose a reason for hiding this comment

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

Not in this PR

T,
V,
Op <: AbstractLinearOperator{T},
Sub <: Union{KrylovWorkspace{T, T, V}, QRMumpsSolver{T}},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Sub <: Union{KrylovWorkspace{T, T, V}, QRMumpsSolver{T}},
Sub <: KrylovWorkspace{T, T, V},

@farhadrclass
Copy link
Contributor Author

@tmigot Thanks for the review,

I see your point on QRMumps but, one of the main focus of this PR and my code is to use the QRMumps and hence I put them here (I was thinking to move them to a different location after but for now I think it is required for this PR), What do you think?

On the tests reviews, I agree, I will clean it up and update it asap and also the same with documents

Thanks for the review

@tmigot
Copy link
Member

tmigot commented Jul 6, 2025

@tmigot Thanks for the review,

I see your point on QRMumps but, one of the main focus of this PR and my code is to use the QRMumps and hence I put them here (I was thinking to move them to a different location after but for now I think it is required for this PR), What do you think?

On the tests reviews, I agree, I will clean it up and update it asap and also the same with documents

Thanks for the review

I don't really understand why. I get that the point of your code is to use the QRMumps, but we push all the code in several PR because we also need to make sure that it's correct and the best (and fastest) way to do it is by having focused PR.
The idea is to have a first PR focus on the algorithm, and then another one is QRMumps.

@tmigot tmigot marked this pull request as draft July 7, 2025 20:04
Introduces a `closed` flag and `close!` method to QRMumpsSolver for safe resource cleanup, with finalizer registration to avoid double-destroy. Integrates SparseMatrixCOO for Jacobian representation when using QRMumps, updates Jacobian value handling, and improves documentation with explicit cleanup examples.
Changed allowed npc_handler values to lowercase for consistency and updated documentation accordingly. Implemented the Armijo rule for non-positive curvature handling, including backtracking and forward tracking line search. Improved logic for step acceptance and regularization parameter updates, and added linesearch option to subsolve! call.
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.

2 participants