diff --git a/qiskit/optimization/problems/quadratic_program.py b/qiskit/optimization/problems/quadratic_program.py index 8c8eb3ffda..d756487016 100644 --- a/qiskit/optimization/problems/quadratic_program.py +++ b/qiskit/optimization/problems/quadratic_program.py @@ -29,6 +29,7 @@ from docplex.mp.model import Model from docplex.mp.model_reader import ModelReader from docplex.mp.quad import QuadExpr +from docplex.mp.vartype import ContinuousVarType, BinaryVarType, IntegerVarType from qiskit.aqua import MissingOptionalLibraryError from qiskit.aqua.operators import I, OperatorBase, PauliOp, WeightedPauliOperator, SummedOp, ListOp @@ -560,11 +561,11 @@ def from_docplex(self, model: Model) -> None: # keep track of names separately, since docplex allows to have None names. var_names = {} for x in model.iter_variables(): - if x.get_vartype().one_letter_symbol() == 'C': + if isinstance(x.get_vartype(), ContinuousVarType): x_new = self.continuous_var(x.lb, x.ub, x.name) - elif x.get_vartype().one_letter_symbol() == 'B': + elif isinstance(x.get_vartype(), BinaryVarType): x_new = self.binary_var(x.name) - elif x.get_vartype().one_letter_symbol() == 'I': + elif isinstance(x.get_vartype(), IntegerVarType): x_new = self.integer_var(x.lb, x.ub, x.name) else: raise QiskitOptimizationError( diff --git a/releasenotes/notes/docplex-fix-e401d4b511ca5244.yaml b/releasenotes/notes/docplex-fix-e401d4b511ca5244.yaml new file mode 100644 index 0000000000..4294561755 --- /dev/null +++ b/releasenotes/notes/docplex-fix-e401d4b511ca5244.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + A method ``one_letter_symbol`` has been removed from the ``VarType`` in the latest + build of DOCplex making Aqua incompatible with this version. So instead of using this method + an explicit type check of variable types has been introduced in the Aqua optimization module.