Gurobi raises GurobiError when a MIP stops at a limit without an incumbent
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 70/100
Hướng nghiên cứu
Start with safe_get_solution and the Gurobi get_solver_solution path in linopy/solvers.py, then compare with the HiGHS handling added in #1133. Check how Model.solve and WindowModel.solve behave when Gurobi reports SolCount == 0; done means both return the limit status without assigning a solution, while still returning an incumbent when one exists.
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
- I have confirmed this bug exists on the current
masterbranch of Linopy.
Issue Description
When Gurobi stops a MIP at a limit (time, node, solution count) before it has found an incumbent, Model.solve raises GurobiError: Unable to retrieve attribute 'X' instead of returning the ok / time_limit status with no solution.
Cause: time_limit maps to SolverStatus.ok, so safe_get_solution calls the extraction function, which reads m.ObjVal and m.getAttr("X", ...) without checking m.SolCount. HiGHS handles this case since #1133 by checking value_valid; Gurobi needs the equivalent SolCount == 0 guard. The same applies to WindowModel.solve on Gurobi.
Reproducible Example
import numpy as np
import pandas as pd
import linopy
rng = np.random.default_rng(0)
n = 400
m = linopy.Model()
x = m.add_variables(binary=True, coords=[pd.RangeIndex(n, name="item")])
for k in range(30):
m.add_constraints((rng.random(n) * x).sum() <= rng.random() * n / 4, name=f"c{k}")
m.add_objective(-(rng.random(n) * x).sum())
m.solve("gurobi", io_api="direct", TimeLimit=0.0, OutputFlag=0)
Traceback
File "linopy/model.py", line 2287, in solve
...
File "linopy/solvers.py", line 1479, in safe_get_solution
return func()
File "linopy/solvers.py", line 2668, in get_solver_solution
sol = np.array(m.getAttr("X", vars_), dtype=float)
gurobipy._exception.GurobiError: Unable to retrieve attribute 'X'
Expected Behavior
m.solve(...) returns ("ok", "time_limit") with no solution assigned, as HiGHS does for the same case. If an incumbent exists, it is returned.
Installed Versions
linopy 0.10.0.post1.dev86 (master), gurobipy 13.0.1
- Ngôn ngữ chính
- Python
- Star
- 263
- Fork
- 93
- Merge trung bình
- 1 ngày 10 giờ
- Pull request đã merge (30 ngày)
- 68
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PyPSA/linopy
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Grouped-sum absence rules are implemented twice (CSRStore._from_scatter and CSRStore.aggregate)Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement math-spec
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
PyPSA/linopy#1063 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Zero culling forces model rebuildingCó thể đã có người làm @MaykThewessen đã nhận 34 ngày trước. Đang mởbug data-model performance
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
PyPSA/linopy#925 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
pylint-dev/pylint#11791 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Rasterio granule reads never retry, so one 503 (Service Unavailable) fails the whole requestCó thể đã có người làm @chuckwondo đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
developmentseed/titiler-cmr#305 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
community enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày