Skip to content

Run a QAOA workflow on the cloud - QPUs

It is finally time to execute a QAOA computation on a real QPU!

A simple example, connecting to the IBMQ Cloud QASM simulator

To begin, let's start by creating our usual benchmark problem: an instance of vertex cover:

import networkx
from openqaoa.problems import MinimumVertexCover

g = networkx.circulant_graph(6, [1])
vc = MinimumVertexCover(g, field=1.0, penalty=10)
qubo_problem = vc.qubo

Now that we have the qubo problem, let's focus on the cloud access. To connect to a QPU or to a cloud-based simulator, you will need to authenticate with the desired provider. You can check all the available backends go to the devices page, but for our current example, let's focus on IBM.

First, you will need to have a correctly setup account with IBMQ. Once your account has been created, all you need is your IBMQ token (available with the IBMQ landing page). The recommended way to use your token in OpenQAOA is the following

from qiskit import IBMQ


Once we have authenticate we can proceeded with the OpenQAOA workflow

from openqaoa import QAOA, create_device
from qiskit import IBMQ

# Load account from disk

#Create the QAOA
q = QAOA()

# Create a device
ibmq_device = create_device(location='ibmq', name='ibm_oslo')

q.set_classical_optimizer(method='cobyla', maxiter=50, tol=0.05)


There are three main changes compared to the previous examples - We use the set_device() method to select the correct device - We set the n_shots to be executed on the quantum computer - We set bounds in terms of number of circuit executions by giving a maximum of 50 iterations, and a tolerance for subsequent cost values of 0.05


The code above will result in up to 50 optimizer iterations, that is it will submit up to 50 jobs to the ibmq_qasm_simulator device!