Skip to content

Commit

Permalink
DOCplex has removed one_letter_symbol() from VarType causing problems…
Browse files Browse the repository at this point in the history
… in Aqua optimization module (qiskit-community#1420)

* fix

* better fix

* added reno

* fix lint
  • Loading branch information
adekusar-drl authored and manoelmarques committed Nov 9, 2020
1 parent 99335c6 commit ae02e92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions qiskit/optimization/problems/quadratic_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/docplex-fix-e401d4b511ca5244.yaml
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit ae02e92

Please sign in to comment.