# How can I run a VQE on one of IBMQ's Quantum Computers

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

# 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.

• 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. Oct 22 '21 at 15:03
• 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.'
– Tom
Oct 22 '21 at 15:24
• 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. Oct 22 '21 at 16:14
• 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 :/
– Tom
Oct 25 '21 at 14:12

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