Skip to content

Initialize solved/zero_resid flags to false#1080

Open
farhadrclass wants to merge 2 commits intoJuliaSmoothOptimizers:mainfrom
Farhad-phd:minres_qlp_firstcheck
Open

Initialize solved/zero_resid flags to false#1080
farhadrclass wants to merge 2 commits intoJuliaSmoothOptimizers:mainfrom
Farhad-phd:minres_qlp_firstcheck

Conversation

@farhadrclass
Copy link
Copy Markdown
Contributor

Set solved, zero_resid, and zero_resid_lim to false during initialization instead of computing them from rNorm ≤ ε. This avoids marking the problem as solved at startup (and potential use of rNorm before it's set), ensuring stopping flags are only updated after the residual is computed.

Set solved, zero_resid, and zero_resid_lim to false during initialization instead of computing them from rNorm ≤ ε. This avoids marking the problem as solved at startup (and potential use of rNorm before it's set), ensuring stopping flags are only updated after the residual is computed.
Copilot AI review requested due to automatic review settings April 8, 2026 14:04
Copy link
Copy Markdown

Copilot AI left a 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 updates MINRES-QLP initialization so solved, zero_resid, and zero_resid_lim are set to false initially rather than being derived from the initial residual check (rNorm ≤ ε), with the intent to only update stopping flags after the residual has been computed.

Changes:

  • Change stopping-criterion initialization in minres_qlp! to set solved/zero_resid/zero_resid_lim to false at startup.

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

# Stopping criterion.
breakdown = false
solved = zero_resid = zero_resid_lim = rNorm ≤ ε
solved = zero_resid = zero_resid_lim = false
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

Initializing solved to false removes the pre-loop convergence check (rNorm ≤ ε). If the initial (possibly warm-start) residual already satisfies the user tolerances, the solver will now run at least one iteration and may exit with a different status (e.g., breakdown / nonpositive curvature in linesearch mode) instead of cleanly returning at iter = 0. Since rNorm and ε are already computed before this block, consider restoring the initial solved = (rNorm ≤ ε) check (or an early return when it holds) while keeping zero_resid/zero_resid_lim initialized to false if the concern is about those flags’ semantics.

Suggested change
solved = zero_resid = zero_resid_lim = false
solved = (rNorm ε)
zero_resid = zero_resid_lim = false

Copilot uses AI. Check for mistakes.
@dpo
Copy link
Copy Markdown
Member

dpo commented Apr 8, 2026

Set zero_resid = zero_resid_lim = rNorm ≤ ε, but solved = false.

@amontoison
Copy link
Copy Markdown
Member

amontoison commented Apr 8, 2026

I don't understand your modification @farhadrclass.
Why do you want to do an iteration in all cases if the residual is small enough?
It includes cases like warm-start and we want to stop if ||r_0|| = ||b - A x_0|| is already very small.

@farhadrclass
Copy link
Copy Markdown
Contributor Author

@amontoison it should be as @dpo mentioned, I made a mistake and asssign all of them

@amontoison
Copy link
Copy Markdown
Member

amontoison commented Apr 8, 2026

You now go in the while loop with your modification:
https://github.com/JuliaSmoothOptimizers/Krylov.jl/blob/main/src/minres_qlp.jl#L238

We don't want that.

@amontoison
Copy link
Copy Markdown
Member

amontoison commented Apr 8, 2026

Set solved, zero_resid, and zero_resid_lim to false during initialization instead of computing them from rNorm ≤ ε. This avoids marking the problem as solved at startup (and potential use of rNorm before it's set), ensuring stopping flags are only updated after the residual is computed.

I don't understand the goal of the PR.
You want to check rNorm == 0 or rNorm ≤ ε before the main loop in many methods.
rNorm is well-defined here before the main loop and it seems to me that we don't need any modification.

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