Repository navigation
perf(csr): sparse shift/roll/diff and merge(dim=...); densify notice on by default in sparse models - #1016
Open
FabianHofmann wants to merge 1 commit into
Open
perf(csr): sparse shift/roll/diff and merge(dim=...); densify notice on by default in sparse models#1016FabianHofmann wants to merge 1 commit into
FabianHofmann wants to merge 1 commit into
Conversation
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
|
FabianHofmann
force-pushed
the
perf/densify-gaps-1011
branch
from
October 6, 2026 19:51
49bb007 to
949f6ba
Compare
…on by default in a sparse model (#1011, #969) shift and roll gather rows on the grid (shifted-in cells absent), so diff stays sparse too. merge along a grid dim stacks rows in input order with the coordinates xr.concat yields on the grids alone. warn_on_densify now defaults to None: implicit densification warns in Model(sparse=True).
FabianHofmann
force-pushed
the
perf/densify-gaps-1011
branch
from
October 7, 2026 09:42
949f6ba to
bf79da4
Compare
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 #1011. Part of #969 and #972 (phase 2, PR 8). Stacked on #1014: until it merges, this PR also shows its commits; only the last commit belongs here.
Note
The following content was generated by AI.
Changes proposed in this Pull Request
shift,rollanddiff. The shift runs on the grid's row numbers with the dense (xarray) semantics, and the rows are gathered from the CSR backing. Shifted-in cells are absent, as on the dense path.rollwraps around,roll_coordsincluded; the constant and auxiliary coordinates follow.diffisself - self.shift(...)and so stays sparse too. Positional arguments work as onDataset.shift/Dataset.roll.linopy.merge(..., dim=<grid dim>). Rows are stacked in input order. The result coordinates are what the dense path'sxr.concatyields on coordinate-only grids: overlapping and duplicate labels alongdim, thejoinof the other dims (cells the join creates are absent), the v1 label check of the auto-detected join and auxiliary coordinates. Dense operands and operands in a different dim order are converted onto the template order first. The operands stay sparse.CSRLinearExpression.takennow also serves the permutation fast path ofreindexedand the dim reordering ofconcatenated.concatenatedraises if the stacked row count does not match the target grid.options["warn_on_densify"]defaults toNone: implicit fallbacks warn inModel(sparse=True), nothing warns in a dense model. Explicit conversions (CSRConstraint.mutable()/to_dense(),add_constraints(freeze=False)) warn only when the option isTrue. Internal conversions such asConstraints.set_blockscount as implicit.LinearExpression.sel/isel/[]/shift/rollshare one small_gatheredhelper.pyproject.tomlto a module-levelpytestmarkintest/test_csr.py; no other test file emits it.Behaviour changes
PerformanceWarning("Sparse (CSR) backing densified: ...") on every implicit densification. Suites that run with-W errorwill fail on these until they setlinopy.options["warn_on_densify"] = Falseor remove the fallback.options["warn_on_densify"]now defaults toNone(wasFalse).Truealso covers dense models and explicit conversions;Falsesilences it.shift,roll,diffandmerge(dim=<grid dim>)on a CSR-backed expression now return a CSR-backed expression (is_sparseisTrue).Thanks to draft PR #1005 by @MaykThewessen for the approach of letting
xr.concaton coordinate-only grids define the result coordinates, and for test scenarios.Operations that still densify (with a notice)
shiftwith afill_value.mergealong a new dimension, with extraxr.concatarguments, or over non-unique labels that need aligning.mergeof operands over different dimensions, i.e. broadcasting such asbal + swithsover a subset of the dims ofbal.sel/isel/wherethat introduce dimensions or touch MultiIndex labels;wherewith a callable condition or a non-scalarother.@edge cases (zero-dim, non-unique or MultiIndex labels, zero-size grid)..datareads, e.g. by any operation without a sparse path, andgroupby(...).sum(use_fallback=True).Timings (2000 x 720 grid, groupby with uneven group sizes, 800 terms wide; tracemalloc on)
shift(t=1)diff("t")merge([...], dim="t")"After" re-measured on the final commit. The
takenrefactor movesmerge(dim)from 58 to 61 MB peak; times are unchanged within noise.Checklist
AGENTS.md).doc.doc/release_notes.rstof the upcoming release is included.