Add `scaling=` to `add_piecewise_formulation`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
Start with Model.add_piecewise_formulation and the scaling handling in add_variables and add_constraints; inspect how generated constraints map to each expression pair. Define scaling behavior for the link rows and applicable domain bounds, while keeping unitless rows at factor 1. Done when callers can provide per-pair scaling without relying on generated constraint names and the behavior is covered for the supported formulations.
由索引模型根据 Issue 内容生成。
描述
This issue was drafted with AI assistance.
Describe the feature you'd like to see
Since v0.10.0, add_variables and add_constraints accept scaling=, but Model.add_piecewise_formulation does not. Callers that build scaled models must set factors after the fact on the generated constraints, found by name via PiecewiseFormulation.constraint_names. That couples downstream code to linopy's internal naming (*_link, *_delta_bound, *_fill_order, ...), which may change with the method (sos2, incremental, lp, ...).
Context: PyPSA sets scaling factors where each variable/constraint is created (per-bus unit factors, objective factor for cost curves). Piecewise formulations are the only place where this is not possible.
import linopy
from linopy import Model
m = Model()
x = m.add_variables(lower=0, upper=1000, name="x", scaling=1e-3)
y = m.add_variables(lower=0, name="y", scaling=1e-3)
pwl = m.add_piecewise_formulation((x, [0, 500, 1000]), (y, [0, 400, 1000]), name="pwl")
print(linopy.__version__) # 0.10.1
print(pwl.constraint_names) # ['pwl_delta_bound', 'pwl_fill_order', 'pwl_binary_order', 'pwl_link']
print(m.constraints["pwl_link"].scaling.values) # [1. 1.] over _pwl_var = ['x', 'y']
m.add_piecewise_formulation((x, [0, 500, 1000]), (y, [0, 400, 1000]), name="pwl2", scaling=1e-3)
# TypeError: add_piecewise_formulation() got an unexpected keyword argument 'scaling'
Note that pwl_link stacks all pairs along _pwl_var, so the rows of different expressions (e.g. MW and currency) live in one constraint and need different factors along that dimension.
Implementation idea
Accept an optional factor per pair, e.g. a third/fourth tuple element or scaling={"x": 1e-3, "y": 1e-6} keyed like _pwl_var, and apply it to the rows that carry the pair's units (the link rows and, where applicable, domain bounds). Rows that only involve unitless weights/binaries (delta_bound, fill_order, binary_order, convexity) keep factor 1. Alternatively, a default of "inherit the scaling of the expression's variables" would cover the common case without new arguments.
- 主要语言
- Python
- 星标
- 263
- 派生
- 92
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 32
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PyPSA/linopy 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
Constant LinearExpression * multi-term LinearExpression raises TypeError (mirrored product works)可能已有人在做 @anveshachuri 于 2 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug solver interface
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
相似的 Issue
-
enhancement help wanted
难度 2/5 1-3 小时 新手友好度 76/100
Git-Hospital/githealthcheck#61 ·
维护者通常 1 天内回复
-
changelog investigate
难度 2/5 1-3 小时 新手友好度 67/100
ramnes/notion-sdk-py#433 ·
-
Partial method descriptors raise on class access可能已有人在做 @Gambit-Checkmate 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 19 天内回复
-
docs pkg:core
难度 1/5 1 小时以内 新手友好度 84/100
pydantic/pydantic-ai#11929 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
intake/intake-esm#789 ·