Repository navigation
feat(csr): one read-only Model(sparse=True) key for the sparse path - #985
Merged
Merged
Conversation
…976) Model(sparse=True) turns on sparse groupby-sum, sparse @ and frozen constraints for one model; v1 only, raises under legacy and with chunk; kept by copy and netcdf. Deprecate Model(freeze_constraints=...), its setter, sum(sparse=...) and options['sparse_groupby']; @ no longer reads the option.
Build cost — v1 vs legacyv1 build peak & time relative to legacy, on this commit — not a comparison against master (that is CodSpeed).
Full table (time + peak, mean)📊 Interactive plots + CSV: download the semantics-report-v1-vs-legacy artifact from this run. Report-only · not a gate · refreshed on every push · obsolete once legacy is dropped. |
Merging this PR will not alter performance
Comparing Footnotes
|
4 of 5 tasks
This was referenced Oct 6, 2026
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 #976.
Note
The following content was generated by AI.
Changes proposed in this Pull Request
The sparse (CSR) path now has one model-level switch instead of three independent opt-ins. With
Model(sparse=True), the reproduction from #976 is sparse end to end:groupby().sum(),@and the constraint.New key
Model(sparse=True), read-only viaModel.sparse(no setter).groupby(...).sum()and@/dotagainst a constant return CSR-backed expressions. This works for expressions and variables.add_constraintsfreezes constraints by default.freeze=Falsestill gives a mutableConstraint, and so doesadd_indicator_constraints, which follows the same default.Fail fast instead of silent dense fallbacks
Model(sparse=True)raises under legacy semantics.groupby().sum(),@andread_netcdfon a sparse model raise if the semantics were switched back to legacy.Model(sparse=True, chunk=...)and settingchunkon a sparse model raise.freeze_constraintson a sparse model raises.warn_on_densify, a groupby grouper without a sparse path now emits a densify notice in a sparse model.Persistence
Model.copykeeps it.freeze_constraints, as written by 0.8.x, still load with their freeze default.Deprecations (
FutureWarning, removed with the legacy semantics)Model(freeze_constraints=...)and theModel.freeze_constraintssetter.groupby(...).sum(sparse=...).linopy.options["sparse_groupby"].These keep their current behaviour, with one exception:
@no longer readssparse_groupby, as proposed in the issue.Decisions that differ from, or go beyond, the proposal
mergeis not wired to the key. It stays sparse only when an operand is already CSR-backed, as today. Converting every densea + bin a sparse model to CSR would cost time without saving memory. In a sparse model, merges of groupby or@results stay sparse anyway.sparse. Mapping them would makeModel(freeze_constraints=True)raise for legacy users, since the key requires v1.warn_on_densifystays off by default, the objective andadd_expressionsdo not follow the key, andConstraints.add(freeze=)stays.test_csr.pystill usessum(sparse=...)to compare sparse and dense results within one model. Apyproject.tomlfilter silences the deprecation warnings in the suite until the switches are removed.pytest.warnsstill sees them.Docs updated: the release notes,
api.rst, the CSR section ofcreating-constraints.ipynband thenodal_balancebenchmark.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.