Skip to content
This repository was archived by the owner on Dec 7, 2021. It is now read-only.

DOCplex has removed one_letter_symbol() from VarType causing problems in Aqua optimization module #1420

Merged
merged 4 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.