Repository navigation
Raise Gurobi's own error message when it fails before finding a solution - #3574
Merged
Merged
Conversation
When gurobipy raises a GurobiError during optimize() (for example a size-limited license refusing the model), both GUROBI interfaces caught it together with every other exception and returned a SOLVER_ERROR, so users only saw the generic "Solver 'GUROBI' failed" message. Re-raise it as a SolverError carrying Gurobi's message when no solution was found. If Gurobi had found a solution before the error, keep the existing behaviour.
Contributor
|
Benchmarks that have stayed the same:
|
Transurgeon
approved these changes
Oct 26, 2026
4 of 9 tasks
4 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
gurobipyraises aGurobiErrorinsideoptimize(), both GUROBI interfaces (gurobi_qpif.pyandgurobi_conif.py) catch it together with every other exception and returnSOLVER_ERROR. The user then only sees the generic message:The most common case is a size-limited license (the pip
gurobipyone). Gurobi's own message says exactly what is wrong, but it gets lost:With this PR, both interfaces re-raise the
GurobiErroras aSolverErrorwith Gurobi's message, chained withfrom e, when no solution was found:If Gurobi found a solution before the error (
SolCount > 0), the current behaviour is kept. The HiGHS and OSQP interfaces already follow the sameraise SolverError(e)pattern.Tests:
test_gurobi_error_messageintest_qp_solvers.py(LP path) and inTestGUROBIintest_conic_solvers.py(SOCP path). Both patchgurobipy.Model.optimizeto raise the license error, so they don't depend on the installed license. Both fail on master and pass with this change. I also checked the snippet above against a real restricted license, through both the QP and the conic path.Issue link (if applicable): addresses part of #1548, the Gurobi case reported in this comment. The issue is broader than that: unpacking solver metadata before raising. CPLEX and COPT swallow errors around the solve call in the same way, and SCIP only logs a warning. These could be follow-ups.
Type of change
Contribution checklist