# Quantum Approximation Optimization Algorithm (QAOA)

**Introduction**

QAOA (some pronounce this as qwaah waah) is a quantum heuristic algorithm proposed by Farhi, Goldstone, and Gutmann [5] in 2014, which can be implemented using unitary gates. The QAOA algorithm uses a problem Hamiltonian which encodes the objective function using a phase separation operator and a mixing Hamiltonian that transfers the probability amplitudes of the basis states into solution states. These two operations are applied in alternation \(p\ \geq1\) times to an initial equal superposition state. Then the qubits are measured in the computational basis to get an approximate solution. The process is repeated several times to identify the best possible solution. In the research paper, the original authors showed that the approximation quality increased as \(p\) increases. The circuit depth grows with \(p\ \times\ m\), and the complexity of the algorithm depends upon \(p\) rather than \(n\). The authors applied the algorithm to Max-Cut problems on regular graphs and analyzed the performance on 2-regular and 3-regular graphs for fixed \(p1\). For \(p\ = 1\), on 3-regular graphs, the authors noted that the QAOA algorithm always finds a cut that is at least 0.6924 times the size of the optimal cut.

Using quantum mechanics, we can write the objective function as an operator, which is diagonal in the computational basis.

Note that the \(\left|\left.z\right\rangle\right.\) are the eigenvectors and \(f\left(z\right)\) are the integer eigenvalues of \(C\). The eigenstate with the maximum energy is the solution to the optimization problem. Let us denote this as \(C_{max}\) , let the corresponding eigenvector be \(\left|\left.z^\prime\right\rangle\right.\) and let the corresponding eigenvalue be \(f\left(z^\prime\right)\). Let us now create an equal superposition of \(2^n\) states using \(n\) qubits in the computational basis by applying a Walsh-Hadamard transform.

Note that we can write the state \(\left|\left.s\right\rangle\right.\) as a tensor product of \(\sigma_x\) states:

The initial state is a superposition of all bit strings and represents the ground state of the mixing Hamiltonian, which we shall explain shortly. If we measure the \(n\) qubits in the computational basis, the qubits are projected into a basis state \(\left|\left.z\right\rangle\right.\), which corresponds to a particular \(C\left(z\right)\). If we perform the measurement several times, we get a distribution of \(C\left(z\right)\). One of these measurements is \(C_{max}\), corresponding to the eigenvector \(\left|\left.z^\prime\right\rangle.\right.\) The probability of getting a \(\left|\left.z^\prime\right\rangle\right.\) in a given measurement is \(\frac{1}{2^n}\). Hence it is not an efficient method of solving the problem. However, we can solve the problem efficiently if we somehow find a method of rotating the initial equal superposition state \(\left|\left.s\right\rangle\right.\) to \(\left|\left.z^\prime\right\rangle.\right.\)

QAOA is a quantum approximation algorithm whose approximation ratio can be defined as follows:

The goal of the QAOA algorithm is to find a bit string \(z\) with an approximation ratio higher than \(r\).

Let us now define the two operators.

**The phase separation operator:**

We can define a problem Hamiltonian that encodes the objective function as an expansion in terms of the Pauli-\(Z\) operator. The phase separation operator acts diagonally on the computational basis states of the n-qubits.

This Hamiltonian can then be simulated as a phase separation operator \(U\left(C,\gamma\right)\), where the angle \(\gamma\) has a range of \(\left[0..2\pi\right]\).

Applying Suzuki-Trotter decomposition , since the operators \(C_\alpha\) commute (as they are diagonal in the computational basis)

Applying this to the superposition state created earlier,

Note that when \(C_\alpha\left(z\right)=0,\ {U(C}_\alpha\left(z\right),\gamma)=1\) and when \(C_\alpha\left(z\right)=1,\ {U(C}_\alpha\left(z\right),\gamma)=\ e^{-i\gamma}\). These conditions mean, a phase \(e^{-i\gamma}\) is added to \(\left|\left.z\right\rangle\right.\), whenever \(C_\alpha\left(z\right)\) meets one of the m constraints. We can implement a quantum circuit to simulate the operator \(U\left(C,\gamma\right)\) and introduce a proportional amount of phase shift using a sequence of controlled \(Z\) rotation gates on an ancilla qubit which stores \(f\left(z\right)\). To explain this, consider the quantum circuit shown in the following diagram, which uses two data qubits \(q0\) and \(q1\) (that is, \(n=2\)), and an ancilla qubit \(q2\).

This circuit has two criteria (that is, m=2), namely,

The controlled U1 gates implement a phase gate defined by the matrix

with \(\gamma=0..2π\), if the control qubits are in state \(\left|\left.1\right\rangle\right.\).

As the first step, we apply Hadamard transform to qubits \(q0\) and \(q11\) to put them in an equal superposition state.

The next step is to apply a controlled rotation to the qubit \(q2\), using the qubit \(q0\) as the control qubit.

Hence, the circuit adds a phase \(e^{-i\gamma m\left(z\right)}\), when a \(z\) meets the criteria \(m\left(z\right)\) into the ancilla qubit.

**Mixing operator:**

The phase change alone does not bring about the probability of getting a certain basis. So a rotation operator is needed. Let us introduce a rotational operator \(B\) representing the mixing Hamiltonian \(H_B\), which applies Pauli-\(X\) gates to the superposition states. Note that the initial state defined by equation ( 4 ) is also the ground state of the mixing Hamiltonian, which is also the transverse field Hamiltonian.

Then (following the previous steps),

Recall that in the rotation operator \(R_x\left(\theta\right)=e^{-i\frac{\theta}{2}\sigma_x}\), the range for the angle of rotation \(\theta\) is \(\left[0..2\pi\right]\). Hence \(\beta\) has a range \(\left[0..\pi\right]\).

Implementing a quantum circuit for the mixing operator is straightforward using the R_x gates with 2beta angles. The following figure implements this concept.

If we assume a certain p, then we can construct a quantum state with \(2p\) angles \(\gamma_1\gamma_2\ldots\gamma_p\ \equiv\ \gamma\) and \(\beta_1\beta_2\ldots\beta_p\equiv\beta\). A classical procedure is employed to map the problem domain into the QAOA circuit depending upon the values chosen for \(\gamma\) and \(\beta\). The algorithm then applies the phase separation and mixing operators alternatively to create the QAOA state:

A quantum circuit can be constructed with a circuit depth of \(mp\ +\ p\) (from equations ( 8 ) and ( 15 ) ) to achieve this state. This is a \(2p\)-dimensional optimization problem, and finding the optimal angles \(\left(\gamma,\beta\right)\) is the key. The following figure illustrates the construction of the quantum circuit by repeating the \(U\left(C,\gamma\right)\) and \(U\left(B,\beta\right)\) operators \(p\) times.

Let langle Crangle represent the expectation value of C in the QAOA state. that is,

then the goal of the algorithm is to start with a value of \(p\) and angles \(\left(\gamma,\beta\right)\) in such a way to maximize \(F_p\)

The algorithm assumes that we can somehow determine angles \(\left(\gamma,\beta\right)\) such that the QAOA state \(\left|\left.\gamma,\beta\right\rangle\right.:math:\) has sufficiently large probability amplitude \(\Omega\left(\frac{1}{poly\left(n\right)}\right)\), that corresponds to the best possible approximate solutions. By repeatedly preparing and measuring the QAOA state, we can find the best solution state \(\left|\left.z^\prime\right\rangle\right.\). Repeating this process for polynomial times, we can get the solution \(z^\prime\) with the highest probability. The following figure illustrates the general workflow for the QAOA algorithm.

As illustrated in the diagram, the algorithm generally proceeds by following the steps outlined below:

STEP 1: Start with a value of \(p\) and angles \(\left(\gamma,\beta\right)\).

STEP 2: Initialize the qubits to the state \(\left|\left.s\right\rangle\right.\).

STEP 3: Construct a quantum circuit to get the QAOA state \(\left.\left|\gamma,\beta\right.\right\rangle.\)

STEP 4: Measure the qubits in the computational basis to get the string \(z\) with probability \(\left|\left\langle z\middle|\gamma,\beta\right\rangle\right|^2\), and classically compute \(C\left(z\right)\), using the objective function outlined in the section Binary optimizations.

Repeat steps 2 to 4 with the same values for \(\left(\gamma,\beta\right)\) and \(p\) to get a distribution of \(C\left(z\right)\) until we get a string \(z\), which produces the largest value \(C_{max}\).

Steps 1 to 4 are repeated with a new set of angles \(\left(\gamma,\beta\right)\), keeping \(p\) the same. This produces a distribution of \(C_{max}\). Selecting a new set of angles and repeating the algorithm polynomial times can produce with a high probability \(az^\prime\), such that \(C\left(z\right)\) is close to \(F_p\left(\gamma,\beta\right)\). The angles \(\left(\gamma,\beta\right)\) that maximize the equation ( 17 ) can be considered as the optimal angles. One way to choose the optimal angles is to use a fine grid \(\left[0..2\pi\right]^p\ \times\left[0..\pi\right]^p\) and navigate through the grid to obtain \(F_p\left(\gamma,\beta\right)\). This search can be exhaustive, as it grows to \(O\left(r^{2p}\right)\), where \(r\) is the resolution of the grid. Gradient descent or other classical optimization methods can be used to arrive at the new set of angles, to efficiently converge the algorithm.