1
$\begingroup$

I am trying to run QSVM algorithm on the IBMQ backend devices using the API_TOKEN. Below is the snippet of the code that I am running. The code fails the validation test and throws an exception after it is submitted to the IBMQ backend.

import numpy as np
import scipy
from scipy.linalg import expm
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.decomposition import PCA
from qiskit import BasicAer
from qiskit.aqua.utils import split_dataset_to_data_and_labels, map_label_to_class_name
from qiskit.aqua.input import ClassificationInput
from qiskit.aqua import run_algorithm, QuantumInstance
from qiskit.aqua.algorithms import QSVM
from qiskit.aqua.components.feature_maps import SecondOrderExpansion
from qiskit.aqua import set_qiskit_aqua_logging

from qiskit import IBMQ
IBMQ.save_account(API_TOKEN,overwrite=True)
_ = IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
n = 24

standardScalerObject = StandardScaler().fit(X_train)
sample_train = standardScalerObject.transform(X_train)
sample_test = standardScalerObject.transform(X_test)

pca = PCA(n_components=n).fit(sample_train)
sample_train = pca.transform(sample_train)
sample_test = pca.transform(sample_test)

# Scale to range -1 to 1
samples = np.append(sample_train,sample_test,axis=0)
minmax_scale = MinMaxScaler((-1,1)).fit(samples)
sample_train = minmax_scale.transform(sample_train)
sample_test = minmax_scale.transform(sample_test)
class_labels = [1,0]
label_train, label_test = y_train, y_test
training_size = len(y_train)
test_size = len(y_test)
sample_train_positive = np.empty((len(finalDrugTargetPair_positive),24))
sample_train_negative = np.empty((len(finalDrugTargetPair_negative),24))
count_pos,count_neg = 0,0
for i in range(len(y_train)):
    if y_train[i] == 1:
        sample_train_positive[count_pos] = sample_train[i]
        count_pos += 1
    else:
        sample_train_negative[count_neg] = sample_train[i]
        count_neg += 1
sample_test_positive = np.empty((len(finalDrugTargetPair_positive),24))
sample_test_negative = np.empty((len(finalDrugTargetPair_negative),24))
count_pos,count_neg = 0,0
for i in range(len(y_test)):
    if y_test[i] == 1:
        sample_test_positive[count_pos] = sample_train[i]
        count_pos += 1
    else:
        sample_test_negative[count_neg] = sample_train[i]
        count_neg += 1
print(sample_train_positive.shape)
print(sample_train_negative.shape)
training_input = {1:sample_train_positive,0:sample_train_negative}
test_input = {1:sample_test_positive,0:sample_test_negative}
feature_map = SecondOrderExpansion(feature_dimension=24, depth=2, entanglement='linear')
qsvm = QSVM(feature_map, training_input, test_input)
backend = provider.get_backend('ibmq_qasm_simulator')
quantum_instance = QuantumInstance(backend, shots=512)
result = qsvm.run(quantum_instance)

The Exception Message

W0811 05:38:26.500134 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIIZIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.501830 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIZIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.503939 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIZIIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.505864 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIIIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.507203 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIIIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.508888 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIIIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.510094 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIIIIIIZIIIIIIIIIIIII is skipped.
W0811 05:38:26.511391 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIIIZIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.513397 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIIZIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.515936 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIZIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.517422 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIZIIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.519120 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIIIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.521319 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIIIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.522609 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIIIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.524315 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIIIIIZIIIIIIIIIIIIII is skipped.
W0811 05:38:26.525660 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIIZIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.526803 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIZIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.528323 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIZIIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.529316 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIIIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.530683 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIIIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.532210 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIIIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.533475 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIIIIZIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.535063 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIIZIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.536294 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIZIIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.538482 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIIIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.540581 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIIIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.542438 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIIIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.544407 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIIIZIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.547164 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIIZIZIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.548890 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIIZIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.551091 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIIZIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.552363 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIIZIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.554009 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIIZIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.555259 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIIZIZIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.557298 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIIZIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.558995 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIIZIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.560379 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIIZIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.561851 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IIZIZIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.563276 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIIZIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.566059 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIIZIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.568841 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, IZIZIIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.570071 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIIZIIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:38:26.571298 140084711831424 pauli_expansion.py:136] Due to the limited entangler_map, ZIZIIIIIIIIIIIIIIIIIIIII is skipped.
W0811 05:42:36.945176 140080057583360 connectionpool.py:662] Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', ConnectionResetError(104, 'Connection reset by peer'))': /quantum-computing-user-jobs/qObject-5d4faacc698fad00199197ac.json?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=a0ee7e2f33ba42d08305f6d858999743%2F20190811%2Fus-east-standard%2Fs3%2Faws4_request&X-Amz-Date=20190811T054236Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=9ab8b3610eef7344e55d7a375bafdf44454eb4aff50746c9996cf2c8cc06abf1
---------------------------------------------------------------------------
JobError                                  Traceback (most recent call last)
<ipython-input-13-265e7d718710> in <module>()
     15 quantum_instance = QuantumInstance(backend, shots=512)
     16 
---> 17 result = qsvm.run(quantum_instance)
     18 print(result)
     19 # ran_job = backend.jobs(limit=1)

7 frames
/usr/local/lib/python3.6/site-packages/qiskit/aqua/algorithms/quantum_algorithm.py in run(self, quantum_instance, **kwargs)
     62                 quantum_instance.set_config(**kwargs)
     63             self._quantum_instance = quantum_instance
---> 64         return self._run()
     65 
     66     @abstractmethod

/usr/local/lib/python3.6/site-packages/qiskit/aqua/algorithms/many_sample/qsvm/qsvm.py in _run(self)
    306 
    307     def _run(self):
--> 308         return self.instance.run()
    309 
    310     @property

/usr/local/lib/python3.6/site-packages/qiskit/aqua/algorithms/many_sample/qsvm/_qsvm_binary.py in run(self)
    127     def run(self):
    128         """Put the train, test, predict together."""
--> 129         self.train(self._qalgo.training_dataset[0], self._qalgo.training_dataset[1])
    130         if self._qalgo.test_dataset is not None:
    131             self.test(self._qalgo.test_dataset[0], self._qalgo.test_dataset[1])

/usr/local/lib/python3.6/site-packages/qiskit/aqua/algorithms/many_sample/qsvm/_qsvm_binary.py in train(self, data, labels)
     71         """
     72         scaling = 1.0 if self._qalgo.quantum_instance.is_statevector else None
---> 73         kernel_matrix = self._qalgo.construct_kernel_matrix(data)
     74         labels = labels * 2 - 1  # map label from 0 --> -1 and 1 --> 1
     75         labels = labels.astype(np.float)

/usr/local/lib/python3.6/site-packages/qiskit/aqua/algorithms/many_sample/qsvm/qsvm.py in construct_kernel_matrix(self, x1_vec, x2_vec, quantum_instance)
    243                                     num_processes=aqua_globals.num_processes)
    244 
--> 245             results = self.quantum_instance.execute(circuits)
    246 
    247             if logger.isEnabledFor(logging.DEBUG):

/usr/local/lib/python3.6/site-packages/qiskit/aqua/quantum_instance.py in execute(self, circuits, **kwargs)
    209 
    210         result = run_qobjs(qobjs, self._backend, self._qjob_config, self._backend_options, self._noise_config,
--> 211                            self._skip_qobj_validation)
    212 
    213         if self._measurement_error_mitigation_fitter is not None:

/usr/local/lib/python3.6/site-packages/qiskit/aqua/utils/run_circuits.py in run_qobjs(qobjs, backend, qjob_config, backend_options, noise_config, skip_qobj_validation)
    364         results = []
    365         for job in jobs:
--> 366             results.append(job.result(**qjob_config))
    367 
    368     result = _combine_result_objects(results) if len(results) != 0 else None

/usr/local/lib/python3.6/site-packages/qiskit/providers/ibmq/job/ibmqjob.py in result(self, timeout, wait)
    252         if status is not JobStatus.DONE:
    253             raise JobError('Invalid job state. The job should be DONE but '
--> 254                            'it is {}'.format(str(status)))
    255 
    256         if not self._result:

JobError: 'Invalid job state. The job should be DONE but it is JobStatus.ERROR'

Also it would be a great help if someone can guide me so as to retrieve the accuracy and other statistics after the job is executed.

$\endgroup$
  • $\begingroup$ Hi, I tried to run your code, but it is missing the values for X_train and X_test. Could you update the code to show where you get these from? $\endgroup$ – met927 Aug 12 '19 at 8:24
  • $\begingroup$ I have csv files from which I am retrieving the data from. I can share the files via mail if you want along with the complete code. $\endgroup$ – Yash Patel Aug 12 '19 at 8:25
  • $\begingroup$ I think the issue is with the way you are creating your datasets training_input = {1:sample_train_positive,0:sample_train_negative}, I think the data has the wrong shape, although I can't say for sure without running it locally. I would suggest running it using Aer to get more meaningful error messages and then swapping back to the real devices once you have debugged it. If you share the error you get when you do that, I can try to help. $\endgroup$ – met927 Aug 12 '19 at 8:52
  • $\begingroup$ Thanks for the question. Could you find a minimal example of code that causes the error? That would be a lot easier to debug, and the solution would be much more useful to others on this site. $\endgroup$ – James Wootton Aug 16 '19 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.