QAOA¶
- class QAOA(problem, *, initial_state=None, trotterization_strategy=None, max_iterations=10, n_layers=1, **kwargs)[source]¶
Bases:
VariationalQuantumAlgorithmQuantum Approximate Optimization Algorithm (QAOA) implementation.
QAOA is a hybrid quantum-classical algorithm designed to solve combinatorial optimization problems. It alternates between applying a cost Hamiltonian (encoding the problem) and a mixer Hamiltonian (enabling exploration).
The problem is provided as a
QAOAProbleminstance that supplies the cost Hamiltonian, mixer Hamiltonian, initial state, loss constant, and decode function.- Parameters:
problem (
QAOAProblem) – AQAOAProbleminstance providing the QAOA ingredients.initial_state (
InitialState|None) – Override the problem’s recommended initial state.trotterization_strategy (
TrotterizationStrategy|None) – The trotterization strategy. Defaults to ExactTrotterization.max_iterations (
int) – Maximum number of optimization iterations. Defaults to 10.n_layers (
int) – Number of QAOA layers. Defaults to 1.**kwargs – Additional keyword arguments passed to
VariationalQuantumAlgorithm, includingoptimizerandbackend.
Initialize the QAOA algorithm.
- Parameters:
problem (
QAOAProblem) – AQAOAProbleminstance that provides cost/mixer Hamiltonians, loss constant, decode function, and recommended initial state.initial_state (
InitialState|None) – Override the problem’s recommended initial state. IfNone, usesproblem.recommended_initial_state.trotterization_strategy (
TrotterizationStrategy|None) – Strategy for Hamiltonian evolution. Defaults toExactTrotterization.max_iterations (
int) – Maximum number of optimization iterations. Defaults to 10.n_layers (
int) – Number of QAOA layers (circuit depth). Defaults to 1.**kwargs – Passed to
VariationalQuantumAlgorithm, includingoptimizer,backend,shots, etc.
Attributes Summary
Number of trainable parameters per ansatz layer.
Get the solution found by QAOA optimization.
Most-probable bitstring measured at the optimized parameters.
Methods Summary
get_top_solutions([n, min_prob, ...])Get top-N solutions with optional feasibility filtering and repair.
sample_solution([params])Run measurement circuits with the given parameters and decode the solution.
Attributes Documentation
- n_params_per_layer¶
- solution¶
Get the solution found by QAOA optimization.
The return type depends on the Problem’s decode function;
Noneis a legitimate decoded value after.run().- Raises:
RuntimeError – If
.run()has not yet been called.
- solution_bitstring¶
Most-probable bitstring measured at the optimized parameters.
Always a string of
0/1characters of lengthn_qubits, regardless of how the problem’s decode function shapessolution.- Raises:
RuntimeError – If
.run()has not yet been called.
Methods Documentation
- get_top_solutions(n=10, *, min_prob=0.0, include_decoded=False, feasibility='ignore')[source]¶
Get top-N solutions with optional feasibility filtering and repair.
- Parameters:
n (
int) – Number of top solutions to return (0 = all). Defaults to 10.min_prob (
float) – Minimum probability threshold. Defaults to 0.0.include_decoded (
bool) – Include decoded representations. Defaults to False.feasibility (
Literal['ignore','filter','repair']) –How to handle infeasible solutions:
"ignore"(default): return all solutions, ranked by probability."filter": drop infeasible solutions, rank by objective energy. This implements the PHQC (Polynomial-time Hybrid Quantum-Classical) post-processing from arXiv:2511.14296 (Algorithm 4): every sampled bitstring is checked for feasibility and scored bycompute_energy(the true objective, not the penalty Hamiltonian), then the lowest-energy feasible solution is returned."repair": repair infeasible solutions via the Problem’srepair_infeasible_bitstringmethod, rank by energy.
- Return type:
- Returns:
List of
SolutionEntry.