Repository navigation
fix: a constraint row without a nonzero term reaches the solver - #1183
Draft
FabianHofmann wants to merge 4 commits into
Draft
FabianHofmann wants to merge 4 commits into
FabianHofmann wants to merge 4 commits into
Conversation
linopy dropped a labelled row whose terms were all zero or absent, so 0 * x >= 5 solved "optimal". The matrices, ncons and duals now keep every row with a label, and the LP writer gives such a row the single term +0.0 times the first variable. solve and to_file warn once about such rows whose right-hand side cannot hold. The fix also corrects Xpress IIS row names on the LP path, a persistent update of a row without a stored term, and dualize of an empty row.
Merging this PR will not alter performance
Comparing Footnotes
|
…sible GLPK writes INTEGER EMPTY or INFEASIBLE (FINAL) for a proven infeasible problem. linopy did not map these, so the status was unknown, the solution was parsed anyway and the status became ok. An empty row that cannot hold skips GLPK's presolve and exposed this.
Only the LP writer adds the 0 * first-variable term to a row without a term. The public Constraint.to_polars returns the same frame as on master. solve warns after sanitize_zeros, so it also names rows that become empty. The solver-grid test runs on a dense model; one HiGHS case covers sparse.
This was referenced Nov 18, 2026
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 #1170.
Supersedes #1175.
Changes proposed in this Pull Request
Note
The following content was generated by AI.
Rule: linopy never silently drops a present (labelled) constraint row. A row without a nonzero term goes to the solver as
0 sign rhs, so0 * x >= 5is infeasible instead of "optimal".Constraint.active_row_maskis "label set". The matrices,ncons,clabels, duals, persistent snapshots and restrict windows follow from it.+0.0 <first variable>. It raises a clearValueErrorif the model has no variable. The publicConstraint.to_polars()is unchanged: it returns no term for such a row, as on master.Model.solveandModel.to_filewarn once, naming the present rows without a nonzero term whose right-hand side cannot hold (capped atdisplay_max_rows).solvewarns aftersanitize_zeros, so rows that sanitizing empties are named too. It is a hint; the solver decides.Solver._build_filecallslinopy.io.to_file, so a file solve warns once, not twice.sanitize_zeros(follow-up), the restricttoldrop,linopy/spec.sanitize_missings,sanitize_infinities, restricttol) in convention §12, a migration-table row,restrict.md, release notes (bug fix plus a breaking-change line for sums over all-absent terms).The fix also corrects five more master bugs, each with a test:
ok. Its status stringsINTEGER EMPTYandINFEASIBLE (FINAL)were not mapped, so they becameunknownand the parsed solution flipped them took. A model whose rows are all empty skips GLPK's presolve and hit this.IndexError(highs, gurobi, xpress).dualizekept such rows while the primal dropped them: primal "optimal", dual "unbounded".Validation and reviewer notes
--doctest-modules linopy test, GLPK 5.0 installed (aptglpk-utils, as CI): 8095 passed, 94 skipped.ruff check .,ruff format --check .(0.16.10): clean.mypy .as CI ([dev,spec]): 6 errors intest/test_spec_api.py, identical on master (from feat(spec): dim_order sets the axis order of a spec build #1179).'ok' == 'warning',ncons 1 == 2,optimal == infeasible,IndexError, missing LP rows, no warning), except the expected passes: restrict "outside"/"dropped", indicator LP, IIS except Xpress LP, the no-warning test, and theto_polarstest that pins master's output. The infeasible-MILP test fails on master for GLPK only.0*x>=5,[0,1]*x>=5,LinearExpression(12)==13andx.where(mask).sum('j')>=5over every licensed solver × (lp, lp-polars, mps, direct) × explicit names, plus one sparse-model case on HiGHS direct; an infeasible MILP over every MIP solver; a holding row keepsncons == 2and dual 0; LP section with the dummy term per slice (dense and sparse); LP/MPS files keep the row (read back with HiGHS); warning names rows once forto_file(lp, mps) andsolve(mock, lp, direct), also rows emptied bysanitize_zeros; restrict, persistent, IIS, dualize and indicator cases.sanitize_zerosTrue/False):0*x>=5,[0,1]*x>=5,12==13infeasible in 30/30 runs each; the holding row optimal in 30/30.to_file.to_filedoes not sanitize, so it names only rows that are empty as built.sanitize_missings(),sanitize_infinities(default insolve), and a restrict window, which drops a row with no term in the window that holds withintol.Checklist
AGENTS.md).doc.doc/release-notes.mdof the upcoming release is included.Generated by Claude Code