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

Fix for docplex 2.20 #1520

Merged
merged 2 commits into from
Feb 4, 2021
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
2 changes: 1 addition & 1 deletion qiskit/optimization/applications/ising/docplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import numpy as np
from docplex.mp.constants import ComparisonType
from docplex.mp.constr import LinearConstraint, QuadraticConstraint
from docplex.mp.linear import Var
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 @@ -24,7 +24,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