Gurobi raises GurobiError when a MIP stops at a limit without an incumbent
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 70/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
[!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
- 主要言語
- Python
- スター
- 263
- フォーク
- 93
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 68
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyPSA/linopy のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Grouped-sum absence rules are implemented twice (CSRStore._from_scatter and CSRStore.aggregate)オープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
enhancement math-spec
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
PyPSA/linopy#1063 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Zero culling forces model rebuilding対応中かも @MaykThewessen が 34 日前に担当しました。 オープンbug data-model performance
難易度 4/5 3〜5日 初心者へのやさしさ 58/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
pylint-dev/pylint#11791 ·
メンテナーはふだん 1 日以内に返信
-
Rasterio granule reads never retry, so one 503 (Service Unavailable) fails the whole request対応中かも @chuckwondo が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
developmentseed/titiler-cmr#305 ·
メンテナーはふだん 1 日以内に返信
-
community enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信