Grouped-sum absence rules are implemented twice (CSRStore._from_scatter and CSRStore.aggregate)
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
The two grouped-sum kernels are CSRStore._from_scatter and CSRStore.aggregate in linopy/csr.py, reached through from_grouper, and CSRStore.from_coo is a third presence rule. Start by reading convention.rst §13 and comparing how each kernel derives presence and the constant. The lower-effort path is a conformance test that runs groupby().sum() through both kernels over the listed absence cases and asserts identical stores. Refactoring _from_scatter onto aggregate is design work and should be agreed with maintainers first.
由索引模型根据 Issue 内容生成。
描述
[!NOTE]
The following content was generated by AI.
CSRStore has two kernels that compute a grouped sum, and each one implements the absence rules (convention.rst §13) on its own:
CSRStore._from_scatter(linopy/csr.py, used byfrom_grouperfor dense sources) scatters the dataset's terms into cells. It drops-1/ NaN terms, then derives presence and the constant itself:const[cell_rows] = 0.0+np.add.at(...), with askipnaswitch.CSRStore.aggregate(linopy/csr.py, used byfrom_grouperfor CSR sources and byDenseStore.aggregateviaas_sparse(...).aggregate(...).to_dense()) regroups CSR rows. It derives presence from the row bounds (const[np.diff(bounds) == 0] = np.nan) and always skips NaN constants.
Today both agree on every case we probed: cells nothing lands in are absent, cells whose members are all absent are present with constant 0, and NaN constants are skipped. But the rules live in two places. A change to one won't reach the other, and dense and sparse groupby().sum() could start to diverge silently. This came up in the review of #1122, where a third copy of the presence rule (CSRStore.from_coo) had already drifted: cells reached only through masked labels came out absent instead of zero.
Possible directions
- Express
_from_scatteras "build one CSR row per member, thenaggregate", so presence and constant handling live inaggregatealone. Theskipna=Falsecase would remain a small post-step on the constant. - Or, at minimum, add a conformance test that runs
groupby().sum()through both kernels over a table of absence cases (unaddressed cell, all-masked members, NaN member constants, explicit zero coefficients, duplicates) and asserts identical stores.
Related observations, possibly separate
- §13 says "a sum of none is the zero expression", but a multi-key cartesian
groupbyandreindexgive absent cells, while@/.sum()give zero. The convention docs should say which rule applies where. - At the constraint layer, a present row with no live terms is silently dropped (
active_row_mask,constraints.py). An all-masked0 == 1therefore disappears instead of making the model infeasible, and the solver can't tell absent from zero.
Generated by Claude Code
- 主要语言
- Python
- 星标
- 263
- 派生
- 93
- 平均合并
- 1 天 10 小时
- 30 天内合并 PR
- 68
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PyPSA/linopy 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 3/5 1-2 天 新手友好度 70/100
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
enhancement math-spec
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
Zero culling forces model rebuilding可能已有人在做 @MaykThewessen 于 33 天前认领。 未关闭bug data-model performance
难度 4/5 3-5 天 新手友好度 58/100
维护者通常 1 天内回复
相似的 Issue
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 76/100
graphql-python/graphql-core#304 ·
维护者通常 1 天内回复
-
docs size:S
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
Gathin23/cleanyourtv#3464 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复