Strangeworks QAOA
The strangeworks-qaoa
package allows users to run construct and solve problems with the QAOA algorithm on multiple hardware providers.
Overview​
The QAOA algorithm allows you to solve quadratic unconstrained binary optimization (QUBO) problems by making use of the power of quantum resources. It is a classical-quantum hybrid algorithm: the general idea is that we propose a quantum ansatz circuit with some variational parameters as the coefficients for some of the quantum gates. We then apply this circuit to our qubits, measure the output and repeat many times in order to build up the required statistics. We take these measurement results and compute the cost function with our defined problem. We then hand the algorithm over to a classical CPU which optimizes the circuit parameters before passing back to the quantum side to re-measure the cost function but now for the new parameterized quantum circuit. The algorithm then iterates back and forth between the application of the quantum circuit and the classical optimization of the circuit parameters before eventually converging on a solution with the lowest cost.
This page will describe how to install and begin to use the QAOA service as well as giving some technical details of the algorithm. ​
Prerequisites​
In order to use the AWS Hybrid job service and/or the IBM Cloud devices, the user must have a billing account properly enabled. Without this, the user can still utilize qiskit runtime jobs through IBMs free services. ​
Installation​
To get started, make sure you have Python 3.9 or above (installation) and are familiar with setting up and using virtual environments.
Install packages using pip: ​
pip install strangeworks
pip install strangeworks-qaoa
​ Import package into python: ​
from strangeworks_qaoa.sdk import StrangeworksQAOA
​
Authentication​
Any issues authenticating, you may need to add a QAOA resource to your account through the Platform, https://portal.strangeworks.com ​
Usage​
Before running:
- Set up your environment and install
strangeworks-qaoa
andstrangeworks
- In the portal, Activate Strangeworks QAOA Service to create a Resource
- Replace
your-api-key
with your key from the Portal homepage - Use examples below to utilize the various functionality. See Examples section below for an example script.
Authenticate with strangeworks python sdk using users API token:
strangeworks.authenticate(api_key="your-api-key")
​ Get QAOA resource using qaoa sdk extension and users resource slug:
sw_qaoa = StrangeworksQAOA(resource_slug=" "))
​ List compatable backends for the qaoa product:
sw_qaoa.backends()
​ List all user qaoa jobs:
jobs = sw_qaoa.job_list(update_status=True)
​ Run problem:
sw_job = sw_qaoa.run(backend, problem, problem_params)
​ Retrieve job with specific slug:
sw_job = strangeworks.jobs(slug=slug)[0]
​ Check the status of job and update
status = sw_qaoa.update_status(sw_job)
Display results
result = sw_qaoa.get_results(sw_job,calculate_exact_sol=True)
Examples​
Here is an example run for a small problem on an IBM simulator:
import strangeworks
from strangeworks_qaoa.sdk import StrangeworksQAOA
import strangeworks_qaoa.utils as utils
strangeworks.authenticate(api_key=" ", store_credentials=False)
sw_qaoa = StrangeworksQAOA(resource_slug=" "))
################################
######## Create problem from QUBO
nodes = 4
seed = 0
n = 3
problem = utils.get_nReg_MaxCut_QUBO(n, nodes, seed)
maxiter = 50
shotsin = 1000
theta0 = [1.0, 1.0]
p = 1
alpha = 0.1
optimizer = "COBYLA"
ansatz = "qaoa_strangeworks"
problem_params = {
"maxiter": maxiter,
"shotsin": shotsin,
"theta0": theta0, # optional
"p": p, # optional
"alpha": alpha, # optional
"optimizer": optimizer, # optional
"ansatz": ansatz, # optional
}
backend = "ibmq_qasm_simulator"
sw_job = sw_qaoa.run(backend, problem, problem_params)
result = sw_qaoa.get_results(sw_job,calculate_exact_sol=True)
🥳 Success! You may view your job in the portal.
😅 Something went wrong? Find us in Slack!
Algorithm Details​
The QAOA algorithm solves quadratic unconstrained binary optimization (QUBO) problems with binary variables , such as one with the (general) cost function,
Typically, upon mapping to a quantum problem so that it can be solved with qubits on a quantum computer, we transform the problem from variables to a new set of variables, transforming the cost function into a Quantum Ising Hamiltonian. However, in this service we have omitted this step. Note that this does not change the validity or performance of the algorithm and in both cases the optimal solution is the same - this choice only changes the value of the cost function (the "energy") that is outputed.
Thus, when defining a QUBO problem to be inputted into the service, it is this problem that is directly minimised and the value of the cost function displayed. To reiterate, it is the QUBO that is optimized not the Ising Hamiltonian.
Troubleshooting​
This section provides troubleshooting tips for the product or service this page covers. ​ ​ ​
Further Reading​
This section provides links to other pages in the documentation that are relevant to the product or service this page covers to drive further exploration and engagement.
[1] - More info on the QAOA algorithm: https://qiskit.org/textbook/ch-applications/qaoa.html
[2] - A list of problems that can be solved with QAOA: https://blog.xa0.de/post/List-of-QUBO-formulations/