Repository navigation
feat(spec)!: build spec models sparse only and keep constant rows that hold - #1198
Merged
Merged
Conversation
from_spec forwards Model keyword arguments and now sets sparse=True itself; sparse=False raises a ValueError. The builder tries the term path for every declaration outside terms.eager_only(), so terms.active no longer reads the model. Tests that ran a dense spec build compare the term path with the eager path instead.
A row the data leaves without a term of nonzero coefficient is the constant row 'lhs sense rhs'. linopy keeps such a row since #1183, so from_spec now keeps it where it holds, also in a constraint all of whose rows are constant, and raises a SpecDataError naming the row only where it does not; the warning for a row whose sides are equal goes. The term path and the eager path judge a row alike, a zero coefficient counting as no term, so the eager fallback for such a row goes too.
2 of 5 tasks
Model.from_spec builds a sparse model only, and a term without a variable is made only while it builds, so constant_term never meets a dense model.
The dense spec builds that went with sparse-only from_spec were the only ones to reach a few eager-path branches: a sum over a dimension without members, cases that leave only data, and a dimension dim_order spreads onto a term. Those tests now also build with terms.eager_only(). A new test frames a quadratic expression, which the term path leaves to the eager path, in the name order of its dims.
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.
Changes proposed in this Pull Request
Note
The following content was generated by AI.
Stacked on #1197. Two breaking changes to the unreleased
Model.from_spec, a step towards dropping the eager build path:from_specalways buildsModel(sparse=True);sparse=Falseraises aValueError. Every declaration now tries the term path, so the dense-model fallback to the eager path is gone.lhs sense rhs. It is kept where it holds (0 <= 5), as linopy keeps such rows since fix: a constraint row without a nonzero term reaches the solver #1183, and refused with aSpecDataErrornaming the row where it does not (0 >= 5). Both build paths judge a row alike, so the dead-row fallback to the eager path is gone too.Eager fallbacks over PyPSA's test suite (PyPSA#2181): 902 → 414 declarations, now only window sums (409) and products of two variables (5). The built models on 4 PyPSA networks are identical to #1197's (strict compare); build speed is unchanged within noise.
Notes
0*x >= 1used to reach the solver (infeasible on both paths); now both paths raise at build time.--linopy-dense, two dense test parameters, the dense CI jobs); a follow-up PR on top of PyPSA#2181 does that.Checklist
AGENTS.md).doc.doc/release-notes.mdof the upcoming release is included.Generated by Claude Code