Repository navigation
fix(spec): check a row the data empties against its constants - #1164
Open
FabianHofmann wants to merge 8 commits into
Open
FabianHofmann wants to merge 8 commits into
FabianHofmann wants to merge 8 commits into
Conversation
A row that the data empties of every variable term was dropped with a "trivially true" warning only when every variable declared a missing: number. A row emptied by a shift's stated edge, e.g. sum(shift(x, along=t, offset=1, edge=0), over=k) == load at the first t, was refused even when it read 0 == 0. Count such a row as valued when the spec states every value it can be left with: variables without where: (or with a missing: number), shifts with an edge= number, and data that is never absent. A valued row whose sides differ is now refused as one that cannot hold, naming the first comparison (e.g. 0 == 5). A row emptied by an absent term, such as a shift without edge=, a window, a lookup or a sum over no member, is still refused as before. Fixes #1147 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F4nx8L63c3o8u6QQvr6TGN
Merging this PR will not alter performance
Comparing Footnotes
|
A shift whose offset parameter can be absent, and a window, keep an emptied row refused even under edge=0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F4nx8L63c3o8u6QQvr6TGN
This reverts commit 0d1744e.
…holds" This reverts commit ba8d7a6.
Port of 1ea671d from spec/prune-unbuilt onto master. A sum of absent terms counts as 0. A row the data leaves without a variable term reads constant sense constant. It is dropped with linopy.EmptiedRowWarning where it holds and refused, quoting the row, where it cannot. A term the data scales by zero is pruned, so 0 * x >= 5 is refused instead of built. The objective is evaluated again without that pruning when it would lose every variable. 1ea671d's _variable hunk is left out: it made an objective over a fully masked variable unsolvable. The product of two terms converts one constant side only, as in 7ea5b20.
A row emptied of variable terms compared its constants exactly, so 0.1 + 0.2 == 0.3 was refused. It now holds within DROPPED_ROW_TOL, the tolerance Model.restrict uses for rows it drops. An integral constant is quoted without a fraction, e.g. 0 == 5. The refusal hint points to the data that empties the row. Tests cover a left side emptied against a right side that keeps variables, and an objective the data zeroes, also through a named expression.
A row the data leaves without a variable term is dropped with EmptiedRowWarning where it holds and refused where it cannot. The overview and the spec data guide described the old refusal. EmptiedRowWarning is listed with the other warnings.
FabianHofmann
marked this pull request as ready for review
November 18, 2026 11:12
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 #1147.
Changes proposed in this Pull Request
Note
The following content was generated by AI.
The rule is now: a sum of absent terms counts as 0, and a row the data leaves without a variable term is checked against its constants. It reads
constant sense constant. Where it holds, the row is dropped with the newlinopy.EmptiedRowWarning. Where it cannot,from_specraises and quotes the row, e.g.constraint 'r': 1 row(s) ... cannot hold, the first at t=0: 0 == 5. This replaces the earlier_statedwalk and answers the issue's open question: a shift withoutedge=behaves like one withedge=0inside a sum.spec/prune-unbuilt):_emptied/_check_emptied/_quotedinbuilder.py,Context.zeroes,_without_zeroed_termsinevaluator.py(a term the data scales by 0 is pruned, soc * x >= 5withc = 0is refused instead of built as0 x >= 5),EmptiedRowWarning, and its tests._variablehunk. It turns a fully masked variable into a constant, so an objective over it cannot be solved (No objective has been set). Without it, every test passes.unfused(),_sidesand the fused-sum machinery (da89882, eb922bb, 7238eb2). They do not exist on master. A small_forget_termshelper takesunfused()'s place: before the objective is evaluated again without pruning, it drops the terms the memo keeps. Without it, an objective that reads a named expression the data zeroes cannot be solved.DROPPED_ROW_TOL(1e-9, absolute), the valueModel.restrictuses for rows it drops. So... + 0.1 + 0.2 == 0.3holds. Imported fromlinopy.restrict.matrix, where master has it now. fix: refuse a row emptied of all terms that cannot hold #1175 moves it tolinopy/constants.py, so the import must follow.0 == 5, not0.0 == 5.0).Behaviour changes
edge=0and no-edge=shifts inside a sum, a sum over an empty dimension (<= 0), amissing: 0row such as0 <= relmax, and a row whose left side is emptied while the right side keeps variables.sum(c * x, over=k) >= 5withc = 0. On master this solved "optimal".c * x <= 5withc = 0, now emitEmptiedRowWarning. Models with many zero coefficients can see more warnings.shift(x)outside a sum still leaves its row absent, with no warning, as before.#1174 (a
sum_backwindow over absent terms is 0) works with this PR: with both merged, an all-absent window row warns and is dropped, or is refused (0 >= 5). They merge with a single conflict, two adjacent release-note lines (keep both). 585 spec tests pass on the merge. #1174's note that such rows are refused by_check_liveis stale once this lands.Validation and reviewer notes
pytest test/test_spec*.py test/test_objective.py: 608 passed, 6 skipped. Fullpytest test/: 6337 passed. The only failures aretest_quadratic_model_wo_constraint[gurobi-mps-*], which also fail on master: highspy 1.16.0 writes an MPS file that Gurobi cannot read.ruff check .,ruff format --check .(ruff 0.16.10),mypy linopy: clean.test_an_objective_the_data_zeroes_still_solves, which also passes on master. That test protects the objective re-run: itsnamedcase fails without_forget_terms.test_a_row_the_data_empties_is_checked_against_its_constantscovers the issue's two cases (edge=0,load[0]=0warns and drops;load[0]=5is refused with0 == 5), the same withoutedge=, zero coefficients, the written order, both sides emptied, and a newroundingcase for the tolerance.test_a_row_is_emptied_only_where_neither_side_holds_a_variable[left-against-a-sum]is the earlier PR's left-side-only gap,sum(shift(y, edge=0), over=k) == sum(y, over=k) - load. It is fixed here, so it needs no separate issue.test_a_dimension_with_no_members_empties_a_summed_row:<= 0now warns and drops, and>= 5is refused with0 >= 5.overview.mdandspec-data.mdnow describe the check instead of the old refusal.EmptiedRowWarningis listed indoc/api/warnings.md, and there is one release-note line. The release notes' "Limits" line now says a row raises only where it cannot hold.invalid literal for int() ... 'x'). Direct-API solves work. The guard test avoids this case.Checklist
AGENTS.md).doc.doc/release-notes.mdof the upcoming release is included.Generated by Claude Code