Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

spec: sparse parameter data is densified at build and in model.parameters

オープン
#1,072 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
numpy, pandas, python

調査の方向性

Start with the sparse parameter attach and storage path used by Model.from_spec, then inspect how model.parameters represents dimensioned data and where constraint rows consume parameters. The issue provides a reproducible example and memory measurements; compare stored and peak memory with the expected input-sized behavior while checking that constraints still receive the needed values.

索引モデルが issue の本文から書いたものです。

説明

enhancement math-spec performance sparse

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

Found in the API review for #1068 (stacked on #958); linopy.spec is unreleased.

Describe the feature you'd like to see

Sparse parameter data is densified onto the full grid of its dimensions at attach time, and the dense array is kept in model.parameters. 50k rows on an 8760 x 2000 grid occupy about 0.8 MB as input but 140 MB as stored parameter, and the build peaks at about 500 MB traced memory.

Minimal reproducible example
import tracemalloc
import warnings

import numpy as np
import pandas as pd

import linopy

warnings.simplefilter("ignore", linopy.EvolvingAPIWarning)

SPEC = """
dimensions: {t: {dtype: int}, g: {}}
parameters: {c: {dims: [t, g], missing: absent}}
variables: {x: {dims: [g], bounds: {lower: 0, upper: 1}}}
objective: {sense: minimize, expression: "sum(x)"}
"""
T = pd.Index(range(8760), name="t")
G = pd.Index([f"g{i}" for i in range(2000)], name="g")
rng = np.random.default_rng(0)
idx = pd.MultiIndex.from_arrays([rng.integers(0, len(T), 50_000), G[rng.integers(0, len(G), 50_000)]], names=["t", "g"])
c = pd.Series(1.0, index=idx[~idx.duplicated()])
print(f"sparse input: {len(c)} rows, {c.memory_usage(deep=True) / 1e6:.1f} MB")

tracemalloc.start()
m = linopy.Model.from_spec(SPEC, {"t": T, "g": G, "c": c})
peak = tracemalloc.get_traced_memory()[1]
tracemalloc.stop()
stored = m.parameters["c"]
print(f"m.parameters['c']: shape {stored.shape}, {stored.nbytes / 1e6:.1f} MB, {int(stored.notnull().sum())} non-NaN")
print(f"peak traced during from_spec: {peak / 1e6:.0f} MB")

Output on spec-simplification:

sparse input: 49938 rows, 0.8 MB
m.parameters['c']: shape (8760, 2000), 140.2 MB, 49938 non-NaN
peak traced during from_spec: 500 MB
Expected

Memory proportional to the supplied rows, not to the product of the dimension sizes, both while building and in model.parameters.

Proposal

Keep sparse parameters sparse through attach and storage (e.g. a long-format or sparse-backed array), densifying only where a constraint row needs it.

主要言語
Python
スター
263
フォーク
92
平均マージ
1日 13時間
マージ済み PR(30日)
32

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

PyPSA/linopy のほかの issue

PyPSA/linopy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。