Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Sparse path for the objective

Open
#967 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
52/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Read Objective.expression in linopy/objective.py:174-198 and Model.add_objective in linopy/model.py:1503, then inspect the CSRConstraint.to_polars and to_matrix_with_rhs paths. Account for the separately filed sparse sum work in #756. Done means a CSR-backed objective avoids dense materialization and reaches matrices.c and io.objective_write with its flat coefficient and variable arrays.

Written by the indexing model from the issue text.

Description

enhancement performance sparse

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

Describe the feature you'd like to see

Give the objective a sparse path. Child of #756.

There is none today. Objective.expression (linopy/objective.py:174-198) calls expr.sum() and then expr.const, both of which go through LinearExpression.data and materialise the dense rectangle, dropping any CSR backing. Model.add_objective (linopy/model.py:1503) has no CSR handling at all.

So even a model whose constraints stay sparse end to end pays a full densification for its objective. The objective is a single full contraction to a scalar-ish expression, which is the case the CSR kernel handles best.

Implementation ideas

Depends on sparse sum (filed separately). Once sum() over all dims keeps the backing, the objective setter needs to accept a CSR-backed expression and hand the flat coefficient and variable arrays to matrices.c and io.objective_write directly, in the same spirit as CSRConstraint.to_polars / to_matrix_with_rhs.

Dominant language
Python
Stars
257
Forks
87
Avg merge
1d 8h
Merged PRs (30d)
32

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PyPSA/linopy

All issues in PyPSA/linopy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.