6
$\begingroup$

I have implemented a VQE based on Qiskit's VQE function and want to run that on an actual quantum computer. My understanding was, that an IBMQ backend can be passed into the function as a Quantum Instance. But this doesn't seem to work.

Here is the code that I am using:

from qiskit.algorithms import VQE
from qiskit.algorithms.optimizers import COBYLA
from qiskit.opflow import Z, X, I
from qiskit.circuit.library import TwoLocal
from qiskit import IBMQ

IBMQ.save_account('token') # Insert token here
IBMQ.load_account()

# Define hamiltonian
H = -(Z ^ Z) - 0.2 * ((X ^ I) + (I ^ X))

# Define backend
provider = IBMQ.get_provider(hub='ibm-q')
backend = provider.get_backend('ibmq_bogota')

# Define optimizer
optimizer = COBYLA(maxiter=200)

# Define ansatz
ansatz = TwoLocal(2, 'ry','cz', reps=1)

# Set up VQE and run on backend
vqe = VQE(ansatz=ansatz, optimizer=optimizer, quantum_instance=backend)
result = vqe.compute_minimum_eigenvalue(operator=H)

# print the result
print(result)

The Hamiltonian used in this code is just a dummy, not my actual one. I just want to figure out how to properly run the code on IBMQ, before I try it out with my actual one. I have already tried several approaches, including this one: How to run VQE experiments on IBMQ Backends? But they all did not work either.

Can someone please help me out?

$\endgroup$
4
  • 1
    $\begingroup$ Your code seems fine to me. What was the error? Did you make sure to input the right API token? This can be extracted from your IBM Quantum account. Just clicked on account setting tab and just copy the API token then place it in your line 7 of the code. Also make sure you use the right provider and such too. This can also be extracted from your IBMQ account. $\endgroup$
    – KAJ226
    Oct 22, 2021 at 15:03
  • $\begingroup$ Yes, I have used my API token. When I run this I get a lot of Failure messenges, that say the following: 'FAILURE: Job id: 6172d724bf409e9c######## encounters the error. Error is : Generic error invoking the remote services. Error code: 422.. Re-submit the circuits.' $\endgroup$
    – Tom
    Oct 22, 2021 at 15:24
  • $\begingroup$ You are correct that passing the backend as quantum_instance shouldn't be a problem. How often/when have you tried to re-submit the circuits? The error message makes me think it's an issue with IBM's servers as opposed to your code. $\endgroup$
    – jecado
    Oct 22, 2021 at 16:14
  • $\begingroup$ I have not actively tried to resubmit the circuit. When I run my code as it is it re-submits automatically. But that doesn't work either, so it resubmits again and so on and so forth. I then interrupt the process after some time, because it never works :/ $\endgroup$
    – Tom
    Oct 25, 2021 at 14:12

1 Answer 1

0
$\begingroup$

Your code looks fine - I am afraid you just were out of luck - Bogota appears to have some problems today (24th Oct 2021 as of 11 PM EST). Try switching to a different backend, like ibmq-manila or ibmq-santiago. You can check a list of all backends available to you here.

On a related note, I would sincerely recommend also playing with simpler circuits at first. This way you can get better understanding of the technical aspects of working with IBM Quantum machines and be able to debug more complex code (like VQE) better. Qiskit Textbook is a fantastic resource to learn some theory with working code, but qiskit-tutorials in IBM Quantum Lab (visible on the left-side of the workbook when you first load the page) may be a perfect place for a quick starter

$\endgroup$
1
  • $\begingroup$ I have tried different backends and also looked at the IBMQ backend's list for those devices that where online. But it didn't work for any device. I even tried it out with the 'ibmq_qsam_simulator', that also doesn't work. So I assumed, that maybe I'm passing the backand wrong in the code. I have also been working trough the qiskit workbook and have experimented with vqe's by localy simulating them on my device for some while now, but I really want to test it out on real hardware. Have you ever run a vqe on one of IBMQ's backends? $\endgroup$
    – Tom
    Oct 25, 2021 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.