# How does the classical optimization of the angles $\gamma$ and $\beta$ in QAOA work?

I have been trying to implement QAOA with classical optimization of the angles $$\gamma$$ and $$\beta$$, but I I'm failing at the classical part.

In paper Quantum Approximate Optimization Algorithm: Performance, Mechanism, and Implementation on Near-Term Devices QAOA works with variational parameters $$\gamma$$ and $$\beta$$ which are first chosen randomely and afer thar is in a loop of 3 steps.

Step1. Simulating $$\langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$ with the Quantum Computer.

Step2. Measure in the Z basis. And getting $$\langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$.

Step3. Use a classical optimizesers to calculate new angles $$\gamma$$ and $$\beta$$. In the paper it says that $$F_p(\vec{\gamma},\vec{\beta}) = \langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$ is maximized.
My Questions are:

1. How does the measured expectiaon Value from step 2 is involved in the classical optimization?
2. Are the old $$\gamma$$ and $$\beta$$ involved in the classical optimization?
3. Are step 1 and step 2 only done once? Becuase then the measurement in step 2 will be very unreliable.
4. How is the function $$F_p(\vec{\gamma},\vec{\beta}) = \langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$ written classicaly so that a classical optimizer can work with is?
5. Is there a paper where this is explained or programmed?
• In Step 1, what you actually sample is $|\boldsymbol \gamma , \boldsymbol \beta \rangle$ after passing through the quantum circuit. This is what you measure in the computational basis. The expectation value is usually simple to calculate since $H$ (the 'cost' Hamiltonian) is diagonal in the computational basis. Oct 2 '20 at 14:06

1. $$\langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$ is basically the function evaluation step during the optimization. If you use a gradient-free optimizer, then it uses this information to drive its search.
3. You seem confused between the simulation and measurement part. $$\langle \psi_p(\gamma,\beta)|H|\psi_p(\gamma,\beta)\rangle$$ is the expression you want to optimize. But with a real quantum computer, you can only estimate it by doing many measurements (you get bitstrings which serve as candidates) and averaging the corresponding energies. So you need many measurements if you want a higher precision for that estimate.