Repository navigation
feat(restrict): window a model's flattened matrices - #1036
Open
olivier-lacroix wants to merge 2 commits into
Open
olivier-lacroix wants to merge 2 commits into
olivier-lacroix wants to merge 2 commits into
Conversation
olivier-lacroix
force-pushed
the
feat/restrict-matrix-windows
branch
2 times, most recently
from
October 20, 2026 11:23
c48108a to
366d819
Compare
olivier-lacroix
marked this pull request as ready for review
October 20, 2026 11:26
Merging this PR will not alter performance
Comparing Footnotes
|
olivier-lacroix
force-pushed
the
feat/restrict-matrix-windows
branch
3 times, most recently
from
October 20, 2026 11:40
408ba31 to
3da2fd1
Compare
Contributor
Author
|
I'll resolve typing issues Edit: done |
olivier-lacroix
force-pushed
the
feat/restrict-matrix-windows
branch
from
October 20, 2026 21:09
3da2fd1 to
4f7d8ee
Compare
olivier-lacroix
force-pushed
the
feat/restrict-matrix-windows
branch
from
October 25, 2026 03:38
44f15a9 to
eaa7222
Compare
`Model.restrict` returns a `WindowModel` backed by a slice of the parent's `A`, `b`, `c`, `lb` and `ub` instead of a rebuild of every variable and constraint. A window is a row slice plus a column range; boundary terms are folded at their actual coefficient, and containers are materialised only when their values are read. - `WindowModel.matrices` exposes the window arrays; `solution`, `dual` and `objective` read them back with column, row and objective scaling undone. - `WindowModel.solve` builds the native model from the window and moves it in place through `ModelDiff.from_windows` and the existing per-backend apply hooks. - `advance` re-slices the parent; a shape change rebuilds the solver. - A window that cuts a coupling without `fix` raises `RestrictionError`, naming the constraints. Supported: one selected dimension, dense and CSR parents, masked rows. Not supported: indicators, quadratic objectives, SOS, piecewise, several selected dimensions, subset carriers. `linopy/restrict` is at 100% statement and branch coverage. Co-Authored-By: Claude Code <noreply@anthropic.com>
… test Master removed the autouse semantics fixture with legacy semantics (PyPSA#1041). The windowing equivalence test still requested it and errored at setup on every platform. Co-Authored-By: Claude Code <noreply@anthropic.com>
olivier-lacroix
force-pushed
the
feat/restrict-matrix-windows
branch
from
October 25, 2026 03:42
eaa7222 to
f78d4ca
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #768. Interested in having rolling horizon patterns in linopy.
Note
The following content was generated by AI.
What
Model.restrictreturns aWindowModelbacked by a slice of the parent'sflattened
A,b,c,lbandub. A window is a row slice plus a columnrange; terms whose variables fall outside the window are folded into the RHS at
their actual matrix coefficient. No container is rebuilt.
window.matricesexposes the window arrays, with the parent labels of its rows and columns.window.solutionandwindow.dualareDatasets, materialised per container on access, with column, row and objective scaling undone.window.solvebuilds the native model from the window and updates it in place throughModelDiff.from_windowsand each backend's existing_apply_*hooks. A backend without in-place updates rebuilds, and logs a warning; passdisallow_rebuild=Trueto raise instead.window.advancere-slices the parent; a shape change rebuilds the solver.Semantics
fixraisesRestrictionError, naming the constraints. ANaNat a dangling label counts as missing.Limits
Model: it cannot take new constraints.Benchmark
Build plus solver assembly, optimisation excluded. 35040 steps, a 1460-step
window, 24 chunks, three variables and three constraints.
hyperfine --warmup 1 --runs 5:Windowing costs 3.4% over one full build and avoids 24 rebuilds. In-process,
excluding import overhead: 0.170, 0.938 and 0.171 s.
Benchmark script
Solver support
Only HiGHS has been exercised by hand.
test_window_solve_across_solversrunsthe same recipe on highs, gurobi, cplex, scip, xpress and mosek, skipping
solvers that are absent, file-only, or installed without a license.
solve_windowrequiresio_api="direct". A file-based backend would have towrite the window to disk on every solve, and has no in-place update.
Tests
test_restrict_matrix.pyandtest_windowing_integration.py, including a solver-parametrized run of the window recipe.linopy/restrictis at 100% statement and branch coverage.AI assistance
Drafted with Claude Code: the implementation, tests and benchmark. Reviewed by hand before opening.