Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Widen the CSRConstraint fast path in Model.add_constraints

Aperta
#970 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
performance

Direzione di ricerca

Start in linopy/model.py around lines 1313-1345 and inspect the CSRConstraint handling in linopy/constraints.py:1427-1441. Trace how mask, penalty, freeze, chunking, and expression right-hand sides affect the sparse path, then define tests showing which cases retain CSR storage without changing existing soft-constraint rules. Done means the agreed cases no longer densify and the current sparse opt-ins remain compatible.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement sparse

[!NOTE]
The following content was generated by AI.

Describe the feature you'd like to see

Widen the conditions under which Model.add_constraints keeps a CSRConstraint. Child of #756.

The sparse constraint path is narrow. add_constraints keeps the sparse object only when isinstance(con, CSRConstraint) and freeze and mask is None (linopy/model.py:1333). Any mask=, any penalty=, freeze=False (the default), or a set self.chunk reconstructs the full dense rectangle at model.py:1345.

Upstream of that, csr_rhs (linopy/constraints.py:1427-1441) returns None for a non-constant right-hand side, or one carrying helper dims or dims outside the grid, so to_constraint falls back to dense. An rhs that is itself an expression is a common case and always densifies.

The result is that a build which stayed sparse through every expression operation can still densify at the last step, silently.

Implementation ideas

  • mask=: a mask is a row selection on the CSR store, the same primitive the sparse where needs. These two should probably be implemented together.
  • Expression rhs: move the rhs to the left-hand side before building the constraint, which is what the dense path effectively does, then the existing constant-rhs path applies.
  • penalty/soft constraints are deliberately incompatible with freezing today (model.py:1313); worth confirming that is a permanent rule rather than a gap.

Separately, note that the sparse route currently needs three independent opt-ins to work end to end: semantics="v1", then sparse_groupby=True or a per-call sparse=True, then freeze_constraints=True. Reducing that to one decision would be worth discussing under #756.

Lingua principale
Python
Stelle
257
Fork
87
Merge medio
1g 8h
PR unite (30g)
32

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PyPSA/linopy

Tutte le issue di PyPSA/linopy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.