Skip to content

refactor(mprgp): extract the three moves, and document the solvers by example - #89

Merged
tschm merged 1 commit into
mainfrom
quality/mprgp-decomposition-and-doctests
Aug 15, 2026
Merged

refactor(mprgp): extract the three moves, and document the solvers by example#89
tschm merged 1 commit into
mainfrom
quality/mprgp-decomposition-and-doctests

Conversation

@tschm

@tschm tschm commented Aug 15, 2026

Copy link
Copy Markdown
Member

What

MPRGP's loop body held the conjugate-gradient, expansion and proportioning moves inline, so the proportioning switch and the stopping test were buried in the numerics of the moves themselves.

  • Each move is now its own function over an Iterate = (x, g, p) state.
  • _proportional_step makes the feasibility choice between the CG and expansion moves and reports the Hessian products it consumed.
  • _mprgp keeps only the loop, the stopping test and the switch; the per-move counters become a dict keyed by the move name the step returns.

Docs

Doctests added to ActiveSetSolver, MPRGP and the nncg.inner module, covering:

  • the operator-not-array calling convention,
  • the KKT certificate scoring the answer independently,
  • the interchangeable inner solvers,
  • MPRGP's step counts summing to iterations.

Verification

Behaviour is unchanged — 138 tests pass at 100% line coverage.

🤖 Generated with Claude Code

… example

MPRGP's loop body held the conjugate-gradient, expansion and proportioning
moves inline, so the proportioning switch and the stopping test were buried
in the numerics of the moves themselves. Each move is now its own function
over an `Iterate = (x, g, p)` state, with `_proportional_step` making the
feasibility choice between the CG and expansion moves and reporting the
Hessian products it consumed. `_mprgp` keeps only the loop, the stopping
test and the switch; the per-move counters become a dict keyed by the move
name the step returns.

Add doctests to `ActiveSetSolver`, `MPRGP` and the `nncg.inner` module: the
operator-not-array calling convention, the KKT certificate scoring the
answer independently, the interchangeable inner solvers, and MPRGP's step
counts summing to `iterations`.

Behaviour is unchanged — 138 tests pass at 100% line coverage.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 15, 2026 06:57

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 refactors the MPRGP solver implementation to make the three algorithmic “moves” (CG, expansion, proportioning) explicit functions over a shared (x, g, p) iterate state, while also adding doctest-style documentation examples to key public-facing solver entry points.

Changes:

  • Extract MPRGP’s CG / expansion / proportioning moves into dedicated helpers and simplify _mprgp to primarily own the loop, stopping test, and proportioning switch.
  • Introduce a move-keyed step counter map in MPRGP and keep Hessian product accounting explicit via the extracted step helpers.
  • Add doctest examples to ActiveSetSolver, MPRGP, and the nncg.inner module to document the operator interface, KKT certification, and solver interchangeability.

Reviewed changes

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

File Description
src/nncg/solver.py Adds doctest examples illustrating operator usage, KKT certification, fallback reporting, and inner-solver interchangeability.
src/nncg/mprgp.py Refactors the MPRGP loop by extracting the three moves and selecting CG vs expansion via _proportional_step; adds doctest examples.
src/nncg/inner.py Adds doctest examples showing how different inner solvers affect the active-set outer loop and how iteration counts behave.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tschm
tschm merged commit dd677a2 into main Aug 15, 2026
126 checks passed
@tschm
tschm deleted the quality/mprgp-decomposition-and-doctests branch August 15, 2026 07:01
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