A hybrid quantum-classical approach to solving the Graph Coloring Problem using the Quantum Approximate Optimization Algorithm (QAOA).
- Overview
- The Problem
- Algorithm
- Implementation
- Experiments
- Results
- Limitations & Future Work
- Getting Started
- Repository Structure
- Team
- References
This project was developed as part of the Brazil Quantum CAMP competition by Team Q-Trust AI. We implement QAOA - a hybrid quantum-classical algorithm - to solve the Graph Coloring Problem, which consists of assigning colors to graph vertices such that no two adjacent vertices share the same color.
We validate the approach across three experiments of increasing complexity:
| Experiment | Graph | Vertices | Colors | Qubits | Ο (chromatic number) |
|---|---|---|---|---|---|
| 1 | Path Pβ | 3 | 2 | 6 | 2 |
| 2 | Cycle Cβ | 5 | 3 | 15 | 3 |
| 3 | Complete Kβ | 4 | 4 | 16 | 4 |
In the Graph Coloring Problem, given a graph G = (V, E), we seek a function that assigns a color c β {0, ..., kβ1} to each vertex such that for every edge (u, v) β E:
color(u) β color(v)
The minimum number of colors needed is called the chromatic number Ο(G).
To represent this on a quantum computer, we use one-hot encoding: each vertex v is represented by k qubits x_{v,0}, ..., x_{v,kβ1}, where exactly one qubit equals 1, indicating the assigned color. The qubit index is:
q(v, c) = v Β· k + c
The QUBO (Quadratic Unconstrained Binary Optimization) formulation is converted to an Ising Hamiltonian:
H_C = Ξ£_{(u,v)βE} Ξ£_c x_{u,c} Β· x_{v,c} <- conflict term
+ A Β· Ξ£_v (Ξ£_c x_{v,c} β 1)Β² <- one-hot constraint
The penalty coefficient A = 5 was used empirically to balance constraint enforcement and conflict minimization.
QAOA (Quantum Approximate Optimization Algorithm) is a hybrid quantum-classical algorithm that iteratively refines a parameterized quantum circuit to minimize an expectation value β¨H_Cβ©.
1. Initialize: uniform superposition |+β©^βn via Hadamard gates
2. Repeat p layers:
a. Cost layer: U_C(Ξ³) = exp(-iΞ³ H_C) - biases qubits toward low-energy states
b. Mixer layer: U_M(Ξ²) = exp(-iΞ² H_M) - prevents trapping in local minima
3. Measure: sample bitstrings and decode the best valid coloring
4. Optimize: classical optimizer updates Ξ³ and Ξ² parameters
The circuit depth (number of layers p) controls the trade-off between solution quality and computational cost.
Framework: PennyLane v0.44
indice_qubit(v, c, k)- maps vertex-color pair to qubit indexconstruir_hamiltoniano(n, k, edges, A)- builds the Ising Hamiltonian (h, J, cst)circuito_qaoa(params, coefs, obs, n_qubits, p)- variational QAOA circuitotimizar(n_qubits, coefs, obs, p, n_iter, n_restarts)- classical optimization loopamostrar(params, ...)- samples bitstrings from the optimized circuitdecodificar(bitstring, n, k)- decodes measurement outcome to color assignment
| Optimizer | Strategy | Best for |
|---|---|---|
| COBYLA | Gradient-free, constraint-aware | Noisy landscapes |
| Nelder-Mead | Simplex-based, gradient-free | Smooth landscapes |
| L-BFGS-B | Quasi-Newton (Hessian approx.) | Differentiable objectives |
All optimizers used 10 random restarts to mitigate local minima.
- 3 vertices, 2 colors, 6 qubits
- Known optimal: 0 conflicts (2-colorable)
- Used to validate the Hamiltonian construction and circuit
- 5 vertices, 3 colors, 15 qubits
- Ο(Cβ ) = 3 - requires an odd number of colors
- Tests scalability to mid-size instances
- 4 vertices, 4 colors, 16 qubits
- Ο(Kβ) = 4 - every vertex is adjacent to all others
- Most constrained instance; tests maximum density
| Graph | p=1 | p=2 | p=3 |
|---|---|---|---|
| Pβ | Higher cost | Best trade-off | Marginal gain |
| Cβ | Higher cost | Best trade-off | Diminishing returns |
| Kβ | Higher cost | Best trade-off | Diminishing returns |
Increasing p from 1β2 yielded the largest improvement; gains from 2β3 were minimal (diminishing returns).
All three optimizers converged to valid colorings with 0 conflicts. L-BFGS-B achieved the best final cost value, though differences were small. The algorithm was robust to optimizer choice when multiple restarts were used.
| Experiment | Graph | Qubits | Final Cost | Conflicts |
|---|---|---|---|---|
| 1 | Pβ | 6 | ~β7.25 | 0 |
| 2 | Cβ | 15 | closer to theoretical | 0 |
| 3 | Kβ | 16 | further from theoretical | 0 |
Despite not reaching theoretical optima in larger instances, QAOA found valid colorings with zero conflicts in all three experiments.
- Low-depth circuits are outperformed by classical algorithms (e.g., QAOA p=1 achieves approximation ratio 0.6924 on MaxCut vs. 0.878 for Goemans-Williamson)
- Standard mixer H_M = Ξ£ X_i does not preserve the one-hot subspace, allowing the circuit to explore invalid states
- Barren plateaus (near-zero gradients) can hinder convergence at large p
- Decoherence limits circuit depth on real NISQ hardware
- XY Mixer - replace the standard mixer with one that preserves the one-hot subspace, restricting evolution to valid states only
- Warm-start initialization - use
greedy_colorsolution to initialize circuit parameters, reducing the number of restarts needed - Progressive depth growth - transfer optimized parameters from depth p to p+1 instead of re-initializing
- Systematic penalty tuning - vary A systematically rather than fixing A=5 empirically
python >= 3.10
pip install pennylane networkx scipy matplotlibOption 1 - Google Colab (recommended):
Option 2 - Local:
git clone https://github.com/<your-username>/qaoa-graph-coloring.git
cd qaoa-graph-coloring
pip install -r requirements.txt
jupyter notebook notebooks/QAOA_Graph_Coloring.ipynbqaoa-graph-coloring/
β
βββ notebooks/
β βββ QAOA_Graph_Coloring.ipynb # Main experiment notebook
β
βββ docs/
β βββ report.pdf # Technical report (Brazil Quantum CHMP)
β
βββ assets/
β βββ (figures generated by the notebook)
β
βββ requirements.txt # Python dependencies
βββ LICENSE # MIT License
βββ README.md # This file
Team Q-Trust AI - Brazil Quantum CAMP, 2026 Amanda Arruda, Caio Silva, Diogo Lacerda, Eduarda Mendes, Igor Oliveira, Mateus Granha, Paulo Aquino, Rebeca VitΓ³ria TenΓ³rio, VinΓcius Leal
- Farhi, E., Goldstone, J., & Gutmann, S. (2014). A Quantum Approximate Optimization Algorithm. MIT. arXiv:1411.4028
- Ceroni, J. Intro to QAOA. PennyLane Demos. pennylane.ai
- Baker, J. S., & Radha, S. K. (2022). Wasserstein solution quality and the QAOA: a portfolio optimization case study. arXiv:2202.06782
- Hodson, M. et al. (2019). Portfolio rebalancing experiments using the quantum alternating operator ansatz. arXiv:1911.05296
- Chandarana, P. et al. (2022). Digitized-counterdiabatic quantum algorithm for protein folding.
- Li, J. et al. (2020). Hierarchical improvement of QAOA for object detection. ISQED 2020. DOI