You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the sparse path observable and controllable. Child of #756.
Right now a user cannot tell whether their build stayed sparse. There is no .is_sparse property, no marker in the repr, and no warning when the backing is dropped. Four separate code paths fall back to dense by returning None, all silently: _sparse_matmul (linopy/expressions.py:2570), _try_csr_merge (3319), _aligned (3291) and csr_rhs (linopy/constraints.py:1427).
Combined with the fact that reading repr() or .sizes destroys the backing in place (filed separately as a bug), this makes the feature very hard to use deliberately on anything larger than a toy model.
Three parts:
Expose the state. A public .is_sparse on LinearExpression, and a marker in __repr__ — provided the repr itself stops densifying.
Explain the fallbacks. An opt-in warning, for example options["warn_on_densify"], naming the operation that dropped the backing. Off by default, so nothing changes for existing users.
Per-call control. A sparse= flag on @/dot and merge, mirroring groupby(...).sum(sparse=True). Today @ contracts sparsely but returns a dense object unless the input was already CSR-backed or the global options["sparse_groupby"] is set (expressions.py:2606-2609), which is a surprising coupling between an unrelated option and the result's representation. feat(expressions): sparse @/dot for CSR-backed expressions #961 explicitly deferred this flag.
Implementation ideas
Serving shape, sizes, coords, dims and isnull from the existing Grid is a prerequisite for a non-densifying repr, and is worth doing on its own: Grid already holds all of it.
Note
The following content was generated by AI.
Describe the feature you'd like to see
Make the sparse path observable and controllable. Child of #756.
Right now a user cannot tell whether their build stayed sparse. There is no
.is_sparseproperty, no marker in the repr, and no warning when the backing is dropped. Four separate code paths fall back to dense by returningNone, all silently:_sparse_matmul(linopy/expressions.py:2570),_try_csr_merge(3319),_aligned(3291) andcsr_rhs(linopy/constraints.py:1427).Combined with the fact that reading
repr()or.sizesdestroys the backing in place (filed separately as a bug), this makes the feature very hard to use deliberately on anything larger than a toy model.Three parts:
.is_sparseonLinearExpression, and a marker in__repr__— provided the repr itself stops densifying.options["warn_on_densify"], naming the operation that dropped the backing. Off by default, so nothing changes for existing users.sparse=flag on@/dotandmerge, mirroringgroupby(...).sum(sparse=True). Today@contracts sparsely but returns a dense object unless the input was already CSR-backed or the globaloptions["sparse_groupby"]is set (expressions.py:2606-2609), which is a surprising coupling between an unrelated option and the result's representation. feat(expressions): sparse@/dotfor CSR-backed expressions #961 explicitly deferred this flag.Implementation ideas
Serving
shape,sizes,coords,dimsandisnullfrom the existingGridis a prerequisite for a non-densifying repr, and is worth doing on its own:Gridalready holds all of it.