Skip to content

fix(gurobi): return empty Solution when SolCount == 0 - #1165

Open
boomesh11 wants to merge 2 commits into
PyPSA:masterfrom
boomesh11:fix/gurobi-solcount-zero
Open

boomesh11 wants to merge 2 commits into
PyPSA:masterfrom
boomesh11:fix/gurobi-solcount-zero

Conversation

@boomesh11

Copy link
Copy Markdown

Summary

  • Fixes Gurobi raises GurobiError when a MIP stops at a limit without an incumbent #1134
  • When Gurobi stops at a limit (e.g. TIME_LIMIT) before finding a feasible incumbent (m.SolCount == 0), get_solver_solution() previously accessed m.ObjVal and m.getAttr('X', vars_) unconditionally, raising GurobiError: Unable to retrieve attribute 'X'.
  • Guard get_solver_solution() with if getattr(m, 'SolCount', 1) == 0: return Solution(), matching the HiGHS value_valid guard.

Testing

  • Added test/test_gurobi_no_incumbent.py covering both SolCount == 0 on TIME_LIMIT and SolCount == 1 with an incumbent.
  • Verified pytest test/test_gurobi_no_incumbent.py (2/2 passed).

@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 181 untouched benchmarks
⏩ 181 skipped benchmarks1


Comparing boomesh11:fix/gurobi-solcount-zero (c0a2614) with master (bda47bc)

Open in CodSpeed

Footnotes

  1. 181 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gurobi raises GurobiError when a MIP stops at a limit without an incumbent

1 participant