Hello! Welcome back to our deep dive into quantum computing.
In our last lesson, we explored Hamiltonian simulation, focusing on how to approximate the time evolution operator using Trotter-Suzuki decomposition. We saw that this method breaks down a complex evolution into a sequence of simpler, implementable gate operations.
Today, we will see how this concept of simulating evolution is ingeniously repurposed for a completely different task: solving combinatorial optimization problems. This lesson addresses the learning outcome: Construct the QAOA ansatz circuit for a given problem Hamiltonian, such as for MaxCut.
We will learn how to:
- Map a classical optimization problem, MaxCut, onto a quantum mechanical Hamiltonian.
- Define the two key components of the QAOA ansatz: the problem Hamiltonian and the mixer Hamiltonian.
- Construct the full, parameterized QAOA quantum circuit by alternating the evolution under these two Hamiltonians.
This lesson serves as a crucial bridge, connecting the simulation techniques we just learned with the broader family of variational algorithms we began exploring with VQE.
1. From Classical Optimization to a Quantum Hamiltonian
The Quantum Approximate Optimization Algorithm (QAOA) is a hybrid quantum-classical algorithm designed to find approximate solutions to combinatorial optimization problems. To use it, we must first rephrase our classical problem in the language of quantum mechanics. We'll use the MaxCut problem as our primary example.
MaxCut is a famous NP-hard problem defined on a graph. The goal is to partition the graph's vertices into two sets, say and , such that the number of edges connecting vertices in different sets is maximized.
Solving MaxCut with QAOA: Quantum Tutorial for 100+ Qubits
To start, let's get a clear picture of the MaxCut problem and a high-level introduction to how QAOA can be used to solve it. This video from the Qiskit YouTube channel provides an excellent conceptual overview.
Please watch from 02:56 to 05:04. This segment explains the MaxCut problem and its relevance to real-world applications.
To solve this with a quantum algorithm, we need to encode the problem into a Hamiltonian whose ground state corresponds to the optimal solution (the maximum cut). This mapping involves a few steps:
- Assign variables: We assign a binary variable to each vertex , say , representing which of the two sets the vertex belongs to.
- Formulate a cost function: We create a function that counts the number of "cut" edges. For an edge , the term is 1 if and 0 otherwise. Summing this over all edges gives the total cut value.
- Convert to a minimization problem: Quantum algorithms naturally find minimum energy states (ground states). So, we flip the sign of our cost function to turn the maximization problem into a minimization one.
- Map to an Ising Hamiltonian: The final step is to map the binary variables to spin variables using the transformation . This converts the cost function into an Ising Hamiltonian, an operator whose terms are composed of Pauli operators and identity operators.
The ground state of this resulting Hamiltonian, which we call the problem Hamiltonian , is the quantum state that encodes the bitstring corresponding to the maximum cut.
Solving MaxCut with QAOA: Quantum Tutorial for 100+ Qubits
The same Qiskit video provides a clear, step-by-step walkthrough of this mapping process.
Please watch from 06:15 to 12:24. This segment details the transformation from the MaxCut objective function to a QUBO (Quadratic Unconstrained Binary Optimization) problem, and finally to an Ising Hamiltonian expressed as a sum of Pauli strings.
For a graph with unweighted edges, the resulting problem Hamiltonian is remarkably simple:
Finding the ground state of this is equivalent to solving the MaxCut problem.
2. The Structure of the QAOA Ansatz
The QAOA ansatz is a parameterized quantum circuit inspired by adiabatic quantum computing. Instead of a slow, continuous evolution, QAOA uses a discrete, layered approach.
The state is prepared by applying a sequence of operators to an initial state. The general form of the QAOA state for layers is:
Let's break this down:
- Initial State : The circuit starts by applying a Hadamard gate to each qubit, preparing an equal superposition of all possible computational basis states. This ensures we start with an unbiased exploration of the entire search space.
- Problem Hamiltonian : This is the Hamiltonian we just derived from the MaxCut problem. The unitary is an evolution under this Hamiltonian for a "time" . This operator's role is to impart a phase to each basis state according to its corresponding cut value, effectively "rewarding" states that represent good solutions.
- Mixer Hamiltonian : This is a second Hamiltonian, standard for most QAOA applications, defined as the sum of Pauli-X operators: . The unitary evolves the system under this mixer. Its role is to induce transitions between different computational basis states, allowing the algorithm to "mix" and explore different potential solutions. The initial state is the ground state of this mixer.
- Parameters : The angles and are the variational parameters that are optimized by a classical computer to find the best possible approximation to the ground state of .
The structure is a repeated, alternating application of the problem and mixer evolution operators.
3. Constructing the Circuit from the Hamiltonians
Now we arrive at the core task: translating the abstract operators and into a sequence of quantum gates. This is where our knowledge from the previous lesson on Hamiltonian simulation becomes directly applicable.
{
"intro": "For a more formal treatment, which aligns with your background, the Qiskit lecture 'Introduction to the Quantum Approximate Optimization Algorithm and Applications' explains precisely how these Hamiltonian evolutions are compiled into gates.",
"resource_title": "Lecture 5.2 - Introduction to the Quantum Approximate Optimization Algorithm and Applications",
"resource_id": "6b43e",
"relevant_parts": [
2,
3
],
"instructions": "Please watch from 18:37 to 24:14. This segment first gives a high-level overview of the QAOA variational form, then dives into the details of matrix exponentiation, explaining how the cost Hamiltonian (a sum of Z and ZZ terms) becomes a layer of RZ and controlled-RZ gates, and how the mixer Hamiltonian (a sum of X terms) becomes a layer of RX gates.",
"estimated_time": "6 minutes"
}
Let's summarize the construction for a single QAOA layer ():
A. The Problem (Cost) Layer:
The MaxCut problem Hamiltonian is .
The evolution operator is .
- The identity terms contribute only a global phase, which doesn't affect measurement outcomes, so we can focus on the terms.
- Crucially, all terms for different edges commute with each other. For example, . This means we don't need a Trotter approximation here; the exponential of the sum is exactly the product of the exponentials:
- Each term (with ) is a two-qubit gate that we learned how to build in the last lesson. It can be decomposed as:
So, the problem layer consists of applying this CNOT-RZ-CNOT sequence for every edge in the graph.
B. The Mixer Layer:
The mixer Hamiltonian is .
- Similar to the problem layer, all individual terms commute with each other (). Therefore, the evolution operator decomposes exactly:
- Each term is simply a rotation around the X-axis, which is implemented by the gate.
So, the mixer layer consists of applying an gate to every qubit in the circuit.
C. The Full p=1 Ansatz Circuit
Combining these pieces, the QAOA ansatz circuit for one layer () for a given graph is constructed as follows:
- Initialization: Apply a Hadamard gate to every qubit.
- Problem Layer: For each edge in the graph, apply the sequence .
- Mixer Layer: Apply an gate to every qubit.
For a deeper ansatz with , you simply repeat steps 2 and 3 times, using new parameters and for each layer.
Lecture 5.2 - Introduction to the Quantum Approximate Optimization Algorithm and Applications
To see what this looks like for a concrete example, the Qiskit lecture concludes by showing the full circuit for a 5-vertex MaxCut problem.
Please watch from 24:14 to 26:12. This part shows the complete circuit, including the initial Hadamard layer, the cost layer (decomposed into CNOTs and RZ gates), and the mixer layer. It also clarifies how the circuit depth increases by repeating these layers.
Conclusion
In this lesson, we have detailed the construction of the QAOA ansatz, a cornerstone of modern variational quantum algorithms. We have seen how a classical optimization problem like MaxCut can be systematically translated into a quantum circuit.
Key Takeaways:
- Combinatorial optimization problems can be mapped to Ising Hamiltonians (), where the ground state of the Hamiltonian encodes the optimal solution. For MaxCut, is a sum of terms for each edge.
- The QAOA ansatz creates a trial state by starting in a uniform superposition and then repeatedly applying two alternating evolution operators:
- Problem Evolution (): Phases the states based on the problem's cost function.
- Mixer Evolution (): Mixes the states to explore the solution space.
- The construction of these evolution operators into gates is a direct application of the principles of Hamiltonian simulation. Since the terms within and commute among themselves, no Trotter approximation is needed for each layer.
- The problem layer for MaxCut is built from CNOT and RZ gates, while the mixer layer is built from RX gates.
Preview of the Next Lesson
We have now successfully constructed the parameterized quantum circuit, or ansatz. However, the parameters and are still undefined. In our next lesson, Implement the full QAOA workflow, including the classical optimization loop, to solve a small instance of the MaxCut problem, we will address this. We will see how the quantum circuit is embedded within a classical optimization loop that iteratively adjusts these parameters to minimize the expectation value , thereby guiding the algorithm toward the optimal solution.