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?
token
? This can be extracted from your IBM Quantum account. Just clicked onaccount 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$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$