spec: a row emptied by the data is refused even when it holds

Đang mở
#1,147 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #1164 của @FabianHofmann — đã đóng, không merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Start by reading _check_live in linopy/spec/builder.py and the test test_a_dimension_with_no_members_empties_a_summed_row, which the issue says may need to change. Reproduce with the provided Model.from_spec example, checking both load[0] = 0 and load[0] = 5. Done when the first case drops the holding row with the existing warning and the second reports that the row cannot hold.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Version Checks
  • exists on master (127a61c)
Issue Description

Model.from_spec refuses a row that the data empties of every variable term, even when the row holds (0 == 0). This happens even when the spec states the value at the edge (shift(..., edge=0)).

  • found while building PyPSA from a spec: a link with delay=1 delivers nothing to its bus in the first snapshot, so that bus's balance row is 0 == load. With load = 0 it holds; PyPSA solves it today.
  • _check_live (linopy/spec/builder.py) warns and drops a trivially true row only if every variable declares a missing: number. A plain variable can't declare one (missing: 0 needs a where:), and edge=0 doesn't count.
Reproducible Example
import pandas as pd
import xarray as xr
from linopy import Model

spec = {
    "dimensions": {"t": {"dtype": "int", "ordered": True}, "k": {"dtype": "str"}},
    "parameters": {"load": {"dims": ["t"]}},
    "variables": {"x": {"dims": ["t", "k"], "bounds": {"lower": 0}}},
    "constraints": {
        "balance": {
            "dims": ["t"],
            "expression": "sum(shift(x, along=t, offset=1, edge=0), over=k) == load",
        }
    },
    "objective": {"sense": "minimize", "expression": "sum(x, over=[t, k])"},
}
t = pd.Index([0, 1, 2], name="t")
load = xr.DataArray([0.0, 10.0, 10.0], coords=[t])
Model.from_spec(spec, {"t": t, "k": ["a"], "load": load})
# SpecDataError: constraint 'balance': 1 row(s) hold no variable term once the data
# is attached, the first at t=0. ...

Same error without edge=0, and with load[0] = 5.

Expected Behavior
  • load[0] = 0: builds; the emptied row holds, so it is dropped with the existing "trivially true" warning.
  • load[0] = 5: refused, but saying the row can't hold (0 == 5), not that it leaves the problem silently.
Open question
  • without edge=, the shifted term is absent, not zero. Should a sum of absent terms count as 0 for this check, or must the spec say so (edge=0, a where:)?
  • test_a_dimension_with_no_members_empties_a_summed_row refuses sum(x, over=t) <= 0 over an empty t on purpose, so a change here moves that test too.
Installed Versions

linopy master 127a61c, mathspec 0.0.1.dev1+gf0aaaf4, xarray 2026.9.0, pandas 3.1.1, numpy 2.5.4


Generated by Claude Code

Ngôn ngữ chính
Python
Star
264
Fork
95
Merge trung bình
11 giờ 33 phút
Pull request đã merge (30 ngày)
86

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PyPSA/linopy

Tất cả issue của PyPSA/linopy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.