Quantum Approximate Optimization Algorithm(QAOA) Supporting material
Group Eve: Yuyang Qin,Tingxu Ren,Ke Chen
In this project, we focus on the optimization and simulation of QAOA algorithm and its implementation on the Max-Cut problem in Python. And our paper is here.
First we implement the QAOA utilizing unitary matrix operator in numpy form. Then we use grid search, Bayesian Optimization and L-BFGS-B to find the best
graphic_in.py
: To prepare a random graph with n nodes and get the Max-Cut classic result of it, where generateGraph()
could new a graph and graphic(n,edge.ask_min())
provides its Max-Cut answer as well as division scheme in hexadecimal. The graph will be save into grapy_in.npy
graphic_print.py
: draw the graph using networkx SDK.
In QAOA algorithm, we have
where
which could be achieved by scipy.linalg import expm
.
In our experiment, utilizing
Now, given an array of optimize.ipynb
,finding best array of
We use dfs to achieve the grid search,hyperopt package to finish Bayesian Optimization and scipy.optimize to implement basinhopping algorithm in L-BFGS-B method. We compare these three algorithm using its
It turns out that basinhopping and L-BFGS-B have done a faster and better job.
In optimize.py
, We want to find out how result7_p/p=pi.npy
.
We run optimize.py
for grapy8_in.npy
,whose picture is graphic_n=8.png
. Its result is ploted in result_8.png
with the help of draw_result.py
. And the formulation of accuracy is shown bellow.
We run optimize.py
for grapy_in.npy
,whose picture is graphic_n=7.png
. Its result is ploted in result_7.png
with the help of draw_result.py
. We could only simulate quantum circuit with noise in n=7 utlizing qiskit, since the free IBM quantum machine has a maxium qubit of 7 and we use its noise data.
The experiment result shows that
We prepare our qubit with an Hadamard Gate to obtain the mixed state. circuit.png
is a quantum circuit example at n=7,p=2.
To run the sim.py
,you need to replace My_token
with your IBM Quantum account token and change provider.get_backend('ibm_nairobi')
to the name of an 7 qubits quantum machine in your account.
The datasheet of ibm_nairobi,the real quantum machine we simulate, is shown in overview of ibm_nairobi.png
We obtain our result both with and without noise with the help of 'qasm_simulator'. We draw the top 5 states of each situation in the same histogram for p in range(1,7) . The result is in figure/
. We try the original 1024 shots and the large enough 100000 shots, which we aim to observe the real quantum computation result and the expectation of the final states individually. At the same time,we plot the Accuracy-p figure with and without noise, to help us better understand the influence of noise.
Besides, in the experiment we attempt to construct the failure.jpg
, we set the possibility of error to zero, but we still obtain an undesired gate result.(It's P(1) is obviously not zero and its P(3) is not 1.) We failed to fix this precision bug. That's why we turn to actual quantum machine noise data.
As we analyze the histogram pictures in figure folder, we will find that for shots=100000, the accuracy states could always be distinguished,though hard, while for shots=1024,they could be figured out at p=2 and 3. It's due to the random nature of quantum measurement. As long as the expectation two states are close, they will mix up easily.
As we analyze Accuracy-p figure, it's easy to obtain that noise dramatically decrease the accuracy. As p increases, the depth of quantum circuit increases,leading to more noise and less accuracy. Besides, although Accuracy increase with p for noiseless situation just as it's theoretically proved , the noise effect will over weigh the accuracy improvement of p and become dominate for sufficient large p (in this case p=2). That's why Accuracy first increase then decrease as p increases.
- We implement QAOA on Max-Cut using unitary matrix operator.
- We tried three different ways of parameters optimization and test them with various n and p to find out the pros and cons.
- We construct the quantum circuit of QAOA.
- We simulate the quantum circuit using qiskit and use real quantum machine's error data to simulate the noise.
- We plot our experiment result and discuss the reason behind it.
[1] Farhi, E., Goldstone, J. and Gutmann, S., 2014. A quantum approximate optimization algorithm. arXiv preprint arXiv:1411.4028.