Skip to content

Commit

Permalink
Added tr/except clauses such that mip is an optional import.
Browse files Browse the repository at this point in the history
  • Loading branch information
tBuLi committed Sep 25, 2023
1 parent 8e46208 commit 19c263d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
6 changes: 5 additions & 1 deletion symfit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
from symfit.core.argument import Variable, Parameter
from symfit.core.support import variables, parameters, D

from symfit.symmip import MIP
try:
# MIP is an optional feature. If no solvers are installed this will raise an import error.
from symfit.symmip import MIP
except ImportError:
pass

# Expose the sympy API
from sympy import *
7 changes: 6 additions & 1 deletion symfit/symmip/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
from .gurobi import GurobiBackend
try:
# As a commercial solver, gurobi is optional.
from .gurobi import GurobiBackend
except ImportError:
pass

from .scipopt import SCIPOptBackend
10 changes: 2 additions & 8 deletions symfit/symmip/backend/gurobi.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from dataclasses import dataclass, field
import importlib
import warnings

try:
gp = importlib.import_module('gurobipy')
except ImportError as e:
warnings.warn('Install gurobipy to use this feature.')
gp = {}

import gurobipy as gp

from sympy.printing.pycode import PythonCodePrinter

Expand Down
10 changes: 2 additions & 8 deletions symfit/symmip/backend/scipopt.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
from dataclasses import dataclass, field
import importlib
import warnings

try:
scip = importlib.import_module('pyscipopt')
except ImportError as e:
warnings.warn('Install pyscipopt to use this feature.')
scip = {}

import pyscipopt as scip

from sympy.printing.pycode import PythonCodePrinter

Expand Down

0 comments on commit 19c263d

Please sign in to comment.