Skip to content

Let the caller set the iteration budget on the three doubling solvers #300 - #349

Open
nleonh wants to merge 2 commits into
kmolan:mainfrom
nleonh:issue_300
Open

Let the caller set the iteration budget on the three doubling solvers #300#349
nleonh wants to merge 2 commits into
kmolan:mainfrom
nleonh:issue_300

Conversation

@nleonh

@nleonh nleonh commented Sep 7, 2026

Copy link
Copy Markdown

What & why

Fixes issue #300.

Allow users to specify a budget (number of passes/sweeps) when using solve_discrete_riccati, solve_discrete_lyapunov, symmetric_eigendecomposition. In order to not break any existing project using this API, I have added functions solve_discrete_riccati_with_budget, solve_discrete_lyapunov_with_budget, symmetric_eigendecomposition_with_budget. The old functions just invoke these with the default value (64, 64, 60). I have added sample code (doctests) that demonstrate how the outcome depends on the budget.

I haven't changed the doctests of the functions without _with_budget to verify that they're still working.

If there's anything wrong, please let me now - I'd be happy to improve the changes.

Checklist

  • cargo test + cargo clippy --all-targets clean locally
  • New public APIs have a doc example
  • No unwrap/expect/panic on library paths (typed errors instead)

… (issue 300)

Add solve_discrete_riccati_with_budget to specify a custom budget

Add doctest for solve_discrete_riccati_with_budget

Add solve_discrete_lyapunov_with_budget to allow overwriting the default budget

* solve_discrete_lyapunov just invokes solve_discrete_lyapunov_with_budget with the default budget
* Added doctest

add budget option to eigendecomposition

Add new doctest to symmetric_eigendecomposition_with_budget

* Test how the maximum number of sweeps ("budget") affects the accuracy of the resulting eigenvalues
* Use a diferent matrix than symmetric_eigendecomposition

improve documentation of solve_discrete_lyapunov and solve_discrete_lyapunov_with_budget

fixed clippy warnings

(unnecessary returns in one-line functions)
@nleonh
nleonh requested a review from kmolan as a code owner September 7, 2026 08:58

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the first PR! 🎉 You'll get a first review within 48 h. CI runs the 5-target matrix — a budget-gate failure isn't your fault, see ci/README.md.

/// assert!((worse_values[1] - correct_eigvalds[1]).abs() > 1e-9);
/// assert!((worse_values[2] - correct_eigvalds[2]).abs() > 1e-9);
/// ```
pub fn symmetric_eigendecomposition_with_budget(

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

unlike the _with_budget() counterparts of the other two, this one does not cleanly exit upon non-convergence. It runs for _ in 0..max_sweeps, then unconditionally reads the diagonal as the eigenvalues. There's no DidNotConverge on that path at all. With 60 sweeps hardcoded that never mattered, but now it does.

@kmolan kmolan left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

  1. Please also add tests for the newly added functions
  2. lib.rs re-exports solve_discrete_lyapunov, solve_discrete_riccati at the crate root, but the new _with_budget variants weren't added there

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