Skip to content

Commit

Permalink
fix: more robust solver installed check (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkstrp authored Sep 27, 2024
1 parent 76ab382 commit eb845d8
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions linopy/solvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
which = "where" if os.name == "nt" else "which"

# the first available solver will be the default solver
with contextlib.suppress(ImportError):
with contextlib.suppress(ModuleNotFoundError):
import gurobipy

available_solvers.append("gurobi")
with contextlib.suppress(ImportError):
with contextlib.suppress(ModuleNotFoundError):
_new_highspy_mps_layout = None
import highspy

Expand All @@ -72,19 +72,22 @@
if sub.run([which, "cbc"], stdout=sub.DEVNULL, stderr=sub.STDOUT).returncode == 0:
available_solvers.append("cbc")

with contextlib.suppress(ImportError):
with contextlib.suppress(ModuleNotFoundError):
import pyscipopt as scip

available_solvers.append("scip")
with contextlib.suppress(ImportError):

with contextlib.suppress(ModuleNotFoundError):
import cplex

available_solvers.append("cplex")
with contextlib.suppress(ImportError):

with contextlib.suppress(ModuleNotFoundError):
import xpress

available_solvers.append("xpress")
with contextlib.suppress(ImportError):

with contextlib.suppress(ModuleNotFoundError):
import mosek

with contextlib.suppress(mosek.Error):
Expand All @@ -95,11 +98,12 @@

available_solvers.append("mosek")

with contextlib.suppress(ImportError):
with contextlib.suppress(ModuleNotFoundError):
import mindoptpy

available_solvers.append("mindopt")
with contextlib.suppress(ImportError):

with contextlib.suppress(ModuleNotFoundError):
import coptpy

with contextlib.suppress(coptpy.CoptError):
Expand Down

0 comments on commit eb845d8

Please sign in to comment.