Preserve sparse expressions during metadata reads - #1003
Merged
FabianHofmann merged 2 commits intoOct 5, 2026
Merged
Conversation
Serve has_terms from CSR rows and drop auxiliary coordinates without materializing terms. Preserve xarray errors and existing fallback behavior for dimensions, data variables, and callable selectors. Validate with python -m pytest test -q -n 4 -o addopts= --junitxml=/tmp/linopy-sparse-full-suite.xml: 5418 passed,80 unchanged baseline failures,2234 skipped. Ten sparse regressions fail before the fix and pass after it. Ruff passes. A 168h BirdFlow model-build comparison retains exact numerical LP values, with only signed-zero RHS representation differences; raw benchmark artifacts are retained separately.
for more information, see https://pre-commit.ci
Merging this PR will not alter performance
Comparing Footnotes
|
FabianHofmann
approved these changes
Oct 5, 2026
Collaborator
|
Thanks @MaykThewessen |
FabianHofmann
marked this pull request as ready for review
October 5, 2026 09:58
This was referenced Oct 5, 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.
Note
This pull request was prepared with AI assistance.
A PyPSA network build with
Model(sparse=True)densifies CSR expressions while readinghas_termsfor nodal balance and dropping auxiliary snapshot coordinates for storage. Read term presence from CSR row counts and drop auxiliary coordinates on the coordinate grid instead. Explicit-zero terms and absent cells retain their dense-path semantics; dimension, data-variable and callable-selector operations retain the existing fallback.Related to #969 and #972. This is separate from #992's handoff, solution-readback and merge optimizations.
Ten newly exercised sparse cases fail before this change and pass afterwards. They cover grouped expressions, auxiliary coordinates, absent cells, scalar grids, missing-coordinate errors and explicit-zero coefficients.
BirdFlow screening benchmark
Three sequential fresh-process repetitions per mode on the first 168 snapshots of an existing BirdFlow network, using the same installed PyPSA and numeric dependencies. This measures core model build and matrix export only, without a solve or BirdFlow extra-functionality. The local network is not included as a public benchmark input.
The matrix, objective, bounds and signs have identical fingerprints across these builds. RHS numeric values are also exactly equal, with 19,320 signed-zero representation differences explaining a raw RHS hash difference. Whole-process RSS includes imports, input loading, export and benchmark diagnostics. Build timing differences are small and do not establish a solve speedup.
The two
has_termsdensifications disappear, as does the auxiliary-coordinate drop. A later, previously hidden fallback remains at the coordinate-dimensionmerge(..., dim='snapshot', join='outer'); this PR does not implement that merge path.Test validation and limitations
python -m pytest test -q -n 4 -o addopts='' --junitxml=/tmp/linopy-sparse-full-suite.xml: 5418 passed, 80 failed, 2234 skipped. Exact failure-set comparison found no new failures; the 80 failures also occur on unchanged master in this reused environment. They comprise 74 OETC tests missing optional cloud dependencies and six tests requiring SOS support unavailable through HiGHS.Ruff and whitespace checks pass. Mypy was not installed. Independent read-only review found no correctness blocker.
Note: AI-assisted (model identity unavailable).