1
$\begingroup$

I'm trying to run QSVM algorithm in IBMQ experience, want to run in one of those real quantum computers.

 from qiskit import IBMQ
 IBMQ.load_accounts()
 print("Available backends:")
 IBMQ.backends()

 [<IBMQSimulator('ibmq_qasm_simulator') from IBMQ(ibm-q, open, main)>,
  <IBMQBackend('ibmqx4') from IBMQ(ibm-q, open, main)>,
  <IBMQBackend('ibmqx2') from IBMQ(ibm-q, open, main)>,
  <IBMQBackend('ibmq_16_melbourne') from IBMQ(ibm-q, open, main)>,
  <IBMQSimulator('ibmq_qasm_simulator') from IBMQ()>]


backend = BasicAer.get_backend('ibmq_qasm_simulator')

With the BasicAer I realize I'm using IBMQ's simulator and not the actual IBMQ device. if I chose 'ibmq_qasm_simulator', it works!!!

 device = IBMQ.get_backend('ibmq_16_melbourne') # ibmx4
 #Choose a real - device

 quantum_instance = QuantumInstance(device, shots=100, seed=seed, 
                                      seed_transpiler=seed)
 result = qsvm.run(quantum_instance)

The above code which is supposed to use real Quantum computer "ibmq_16_melbourne" throws me a

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-19-b7c0ec9bc7c4> in <module>
  1 
----> 2 result = qsvm.run(quantum_instance)
  3 print("testing success ratio: ", result['testing_accuracy'])
  4 end = timer()
  5 print("timedelta: " , timedelta(seconds=end-start))

/opt/conda/lib/python3.7/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

/opt/conda/lib/python3.7/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

/opt/conda/lib/python3.7/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])

/opt/conda/lib/python3.7/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)

/opt/conda/lib/python3.7/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):

/opt/conda/lib/python3.7/site-packages/qiskit/aqua/quantum_instance.py in 
execute(self, circuits, **kwargs)
192         qobjs = compile_circuits(circuits, self._backend, 
self._backend_config, self._compile_config, self._run_config,
193                                  
show_circuit_summary=self._circuit_summary, circuit_cache=self._circuit_cache,
--> 194                                  **kwargs)
195 
196         if self._measurement_error_mitigation_cls is not None:

/opt/conda/lib/python3.7/site-packages/qiskit/aqua/utils/run_circuits.py in 
compile_circuits(circuits, backend, backend_config, compile_config, run_config, 
show_circuit_summary, circuit_cache, **kwargs)
195                     transpiled_sub_circuits = 
compiler.transpile(sub_circuits, backend, **backend_config,
196                                                                  
**compile_config)
--> 197                     qobj = 
circuit_cache.load_qobj_from_cache(transpiled_sub_circuits, i, 
run_config=run_config)
198                 else:
199                     qobj = circuit_cache.load_qobj_from_cache(sub_circuits, 
i, run_config=run_config)

/opt/conda/lib/python3.7/site-packages/qiskit/aqua/utils/circuit_cache.py in 
load_qobj_from_cache(self, circuits, chunk, run_config)
178                 if not hasattr(compiled_gate, 'params') or 
len(compiled_gate.params) < 1: continue
179                 if compiled_gate.name == 'snapshot': continue
--> 180                 cache_index = self.mappings[chunk][circ_num][gate_num]
181                 (uncompiled_gate, regs, _) = raw_gates[cache_index]
182 

KeyError: 0

This is my qiskit version via pip: qiskit 0.10.1 qiskit-aer 0.2.0 qiskit-aqua 0.5.0 qiskit-chemistry 0.5.0 qiskit-ibmq-provider 0.2.2 qiskit-ignis 0.1.1 qiskit-terra 0.8.0

$\endgroup$
  • $\begingroup$ that doesn't look like the full error message $\endgroup$ – glS Jun 1 at 15:14
  • $\begingroup$ @gIS: I have edited to add the full error $\endgroup$ – driven_spider Jun 2 at 7:36
  • $\begingroup$ This looks like it is an issue with the Qiskit Aqua code, your code looks correct to me! Could you submit this as an issue to the qiskit-aqua GitHub repo? $\endgroup$ – met927 Jun 3 at 9:44
  • 2
    $\begingroup$ @met927: I have created a github issue. github.com/Qiskit/qiskit-aqua/issues/550 $\endgroup$ – driven_spider Jun 4 at 10:47
  • 1
    $\begingroup$ @driven_spider As I commented on the github issue, this is likely a bug in the way circuits are being batched for public devices. $\endgroup$ – Paul Nation Jun 8 at 10:38

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.