Skip to content

Conversation

arnavk23
Copy link

@arnavk23 arnavk23 commented Oct 11, 2025

tron: support MINRES via krylov callback when radius kw not supported; add bench script and save results

  • Add run_krylov_subsolver! wrapper to enforce trust-region via Krylov callback if workspace doesn't accept radius.
  • Use wrapper inside projected_newton! so MINRES can run inside TRON trust-region loop.
  • Save benchmark results to bench/results_tron_minres_vs_cg.csv.

Closes #306

…; add bench script and save results

- Add run_krylov_subsolver! wrapper to enforce trust-region via Krylov callback if workspace doesn't accept `radius`.
- Use wrapper inside projected_newton! so MINRES can run inside TRON trust-region loop.
- Save benchmark results to bench/results_tron_minres_vs_cg.csv.
@dpo dpo requested a review from Copilot October 11, 2025 13:08
Copy link

@Copilot 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 adds support for MINRES as a subsolver in TRON by implementing a compatibility wrapper that handles workspaces that don't accept the radius keyword argument. When radius is not supported, it falls back to using a Krylov callback to enforce the trust-region constraint.

  • Simplified the subsolver parameter handling in the main tron function
  • Added run_krylov_subsolver! wrapper to handle different Krylov workspace signatures
  • Created benchmark script and saved results comparing CG vs MINRES performance

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/tron.jl Refactored subsolver handling and added compatibility wrapper for Krylov workspaces
bench/bench_tron_minres_vs_cg.jl New benchmark script comparing CG and MINRES subsolvers
bench/results_tron_minres_vs_cg.csv Saved benchmark results
bench/README.md Documentation for the benchmark

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

workspaces that don't accept the `radius` keyword (e.g. Minres). We first
attempt to call with `radius`, and on a MethodError we retry without it.
"""
function run_krylov_subsolver!(workspace, A, b; radius=nothing, rtol, atol, timemax, verbose)
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The function signature should specify default values for all keyword arguments to maintain consistency. Currently rtol, atol, timemax, and verbose lack defaults while radius has one.

Suggested change
function run_krylov_subsolver!(workspace, A, b; radius=nothing, rtol, atol, timemax, verbose)
function run_krylov_subsolver!(workspace, A, b; radius=nothing, rtol=1e-6, atol=0.0, timemax=Inf, verbose=0)

Copilot uses AI. Check for mistakes.

Comment on lines +615 to +616
# If workspace has no `x` field, don't stop via callback.
return false
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

The fallback behavior when workspace lacks an x field could lead to infinite loops or unexpected behavior since the trust-region constraint won't be enforced. Consider logging a warning or throwing an informative error instead.

Suggested change
# If workspace has no `x` field, don't stop via callback.
return false
error("Krylov workspace of type $(typeof(cb_workspace)) does not have an `x` field. Trust-region constraint cannot be enforced. Please use a compatible workspace type.")

Copilot uses AI. Check for mistakes.

Comment on lines +619 to +620
# Stop when the norm of the current solution reaches the radius.
return norm(xcur) >= radius
Copy link

Copilot AI Oct 11, 2025

Choose a reason for hiding this comment

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

Computing the full norm at every iteration could be expensive for large problems. Consider using norm(xcur)^2 >= radius^2 to avoid the square root computation.

Suggested change
# Stop when the norm of the current solution reaches the radius.
return norm(xcur) >= radius
# Stop when the squared norm of the current solution reaches the squared radius (avoids sqrt).
return norm(xcur)^2 >= radius^2

Copilot uses AI. Check for mistakes.

@dpo
Copy link
Member

dpo commented Oct 11, 2025

Thanks @arnavk23 ! I will have a look in detail.

Regarding benchmarks, I think it would be more useful to add a Project.toml inside the bench (or benchmark) folder and to run all unconstrained and bound-constrained problems in OptimizationProblems and/or CUTEst. Have a look at the SolverBenchmark.jl package.

@dpo
Copy link
Member

dpo commented Oct 11, 2025

Sorry. It turns out #306 is premature. MINRES doesn't yet have the radius keyword, which is essentiel for TRON.

@farhadrclass You added detection on nonpositive curvature to MINRES and MINRES-QLP. Would you mind adding the radius keyword and treatment of a trust-region constraint (as in CR)?

@arnavk23
Copy link
Author

arnavk23 commented Oct 15, 2025

@dpo So should I close this pr?

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.

Benchmark TRON with MINRES as subsolver vs CG

2 participants