Skip to content

Commit

Permalink
Fix doctest discovery when DOcplex is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Jun 17, 2023
1 parent f8d9e0e commit ead01aa
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions circuit_knitting/cutting/cutqc/mip_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@

import numpy as np

try:
from docplex.mp.model import Model
from docplex.mp.utils import DOcplexException
except ModuleNotFoundError as ex: # pragma: no cover
raise ModuleNotFoundError(
"DOcplex is not installed. For automatic cut finding to work, both "
"DOcplex and cplex must be available."
) from ex


class MIPModel(object):
"""
Expand Down Expand Up @@ -100,6 +91,14 @@ def __init__(
num_in_qubits += 1
self.vertex_weight[node] = num_in_qubits

try:
from docplex.mp.model import Model
except ModuleNotFoundError as ex: # pragma: no cover
raise ModuleNotFoundError(
"DOcplex is not installed. For automatic cut finding to work, both "
"DOcplex and cplex must be available."
) from ex

self.model = Model("docplex_cutter")
self.model.log_output = False
self._add_variables()
Expand Down Expand Up @@ -465,6 +464,8 @@ def solve(self, min_postprocessing_cost: float) -> bool:
# print('solving for %d subcircuits'%self.num_subcircuit)
# print('model has %d variables, %d linear constraints,%d quadratic constraints, %d general constraints'
# % (self.model.NumVars,self.model.NumConstrs, self.model.NumQConstrs, self.model.NumGenConstrs))
from docplex.mp.utils import DOcplexException

print(
"Exporting as a LP file to let you check the model that will be solved : ",
min_postprocessing_cost,
Expand Down

0 comments on commit ead01aa

Please sign in to comment.