Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Widen the CSRConstraint fast path in Model.add_constraints

Cerrado
#970 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
performance

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
259
Forks
89
Merge medio
1 d 18 h
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PyPSA/linopy

Todos los issues de PyPSA/linopy

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.