Skip to content

Commit

Permalink
Fix for docplex 2.20 (qiskit-community#1520)
Browse files Browse the repository at this point in the history
* Fix for docplex 2.20

* fix cvxpy not installed on unit test

Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
  • Loading branch information
t-imamichi and manoelmarques committed Feb 5, 2021
1 parent 6a26adb commit 233fa67
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions qiskit/optimization/applications/ising/docplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@

import numpy as np
from docplex.mp.constants import ComparisonType
from docplex.mp.constr import LinearConstraint, QuadraticConstraint
from docplex.mp.dvar import Var
from docplex.mp.model import Model
from qiskit.quantum_info import Pauli

Expand Down
2 changes: 1 addition & 1 deletion qiskit/optimization/problems/quadratic_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from docplex.mp.constr import (LinearConstraint as DocplexLinearConstraint,
QuadraticConstraint as DocplexQuadraticConstraint,
NotEqualConstraint)
from docplex.mp.linear import Var
from docplex.mp.dvar import Var
from docplex.mp.model import Model
from docplex.mp.model_reader import ModelReader
from docplex.mp.quad import QuadExpr
Expand Down
22 changes: 13 additions & 9 deletions test/aqua/test_qsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,19 @@ def test_matrix_psd(self):

feature_map = ZZFeatureMap(feature_dimension=feature_dim, reps=2, entanglement='linear')

with self.assertRaises(DQCPError):
# Sampling noise means that the kernel matrix will not quite be positive
# semi-definite which will cause the optimize svm to fail
backend = BasicAer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend, shots=1024, seed_simulator=seed,
seed_transpiler=seed)
kernel_matrix = QSVM.get_kernel_matrix(quantum_instance, feature_map=feature_map,
x1_vec=training_data, enforce_psd=False)
_ = optimize_svm(kernel_matrix, labels, lambda2=0)
try:
with self.assertRaises(DQCPError):
# Sampling noise means that the kernel matrix will not quite be positive
# semi-definite which will cause the optimize svm to fail
backend = BasicAer.get_backend('qasm_simulator')
quantum_instance = QuantumInstance(backend, shots=1024, seed_simulator=seed,
seed_transpiler=seed)
kernel_matrix = QSVM.get_kernel_matrix(quantum_instance, feature_map=feature_map,
x1_vec=training_data, enforce_psd=False)
_ = optimize_svm(kernel_matrix, labels, lambda2=0)
except MissingOptionalLibraryError as ex:
self.skipTest(str(ex))
return

# This time we enforce that the matrix be positive semi-definite which runs logic to
# make it so.
Expand Down
4 changes: 3 additions & 1 deletion test/chemistry/test_adapt_vqe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
# (C) Copyright IBM 2020, 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -14,6 +14,8 @@
import unittest
from test.chemistry import QiskitChemistryTestCase

import numpy as np

from qiskit.chemistry.drivers import PySCFDriver, UnitsType
from qiskit.providers.basicaer import BasicAer
from qiskit.aqua import QuantumInstance
Expand Down
4 changes: 3 additions & 1 deletion test/chemistry/test_groundstate_eigensolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
# (C) Copyright IBM 2020, 2021.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -16,6 +16,8 @@

from test.chemistry import QiskitChemistryTestCase

import numpy as np

from qiskit import BasicAer
from qiskit.aqua import QuantumInstance
from qiskit.chemistry import QiskitChemistryError
Expand Down

0 comments on commit 233fa67

Please sign in to comment.