QAOA#

class QAOA(sampler, optimizer, *, reps=1, initial_state=None, mixer=None, initial_point=None, aggregation=None, callback=None)[source]#

Bases: SamplingVQE

The Quantum Approximate Optimization Algorithm (QAOA).

QAOA is a well-known algorithm for finding approximate solutions to combinatorial-optimization problems [1].

The QAOA implementation directly extends SamplingVQE and inherits its optimization structure. However, unlike VQE, which can be configured with arbitrary ansatzes, QAOA uses its own fine-tuned ansatz, which comprises \(p\) parameterized global \(x\) rotations and \(p\) different parameterizations of the problem hamiltonian. QAOA is thus principally configured by the single integer parameter, reps, which dictates the depth of the ansatz, and thus affects the approximation quality.

An optional array of \(2p\) parameter values, as the initial_point, may be provided as the starting \(\beta\) and \(\gamma\) parameters for the QAOA ansatz [1].

An operator or a parameterized quantum circuit may optionally also be provided as a custom mixer Hamiltonian. This allows in the case of quantum annealing [2] and QAOA [3], to run constrained optimization problems where the mixer constrains the evolution to a feasible subspace of the full Hilbert space.

The following attributes can be set via the initializer but can also be read and updated once the QAOA object has been constructed.

sampler#

The sampler primitive to sample the circuits.

Type:

BaseSampler

optimizer#

A classical optimizer to find the minimum energy. This can either be an Optimizer or a callable implementing the Minimizer protocol.

Type:

Optimizer | Minimizer

reps#

The integer parameter \(p\). Has a minimum valid value of 1.

Type:

int

initial_state#

An optional initial state to prepend the QAOA circuit with.

mixer#

The mixer Hamiltonian to evolve with or a custom quantum circuit. Allows support of optimizations in constrained subspaces [2, 3] as well as warm-starting the optimization [4].

Type:

QuantumCircuit | BaseOperator

aggregation#

A float or callable to specify how the objective function evaluated on the basis states should be aggregated. If a float, this specifies the \(\alpha \in [0,1]\) parameter for a CVaR expectation value.

Type:

float | Callable[[list[float]], float] | None

callback#

A callback that can access the intermediate data at each optimization step. These data are: the evaluation count, the optimizer parameters for the ansatz, the evaluated value, and the metadata dictionary.

Type:

Callable[[int, np.ndarray, float, dict[str, Any]], None] | None

References

[1]: Farhi, E., Goldstone, J., Gutmann, S., “A Quantum Approximate Optimization Algorithm”

arXiv:1411.4028

[2]: Hen, I., Spedalieri, F. M., “Quantum Annealing for Constrained Optimization”

PhysRevApplied.5.034007

[3]: Hadfield, S. et al, “From the Quantum Approximate Optimization Algorithm to a Quantum

Alternating Operator Ansatz” arXiv:1709.03489

[4]: Egger, D. J., Marecek, J., Woerner, S., “Warm-starting quantum optimization”

arXiv: 2009.10095

Parameters:
  • sampler (BaseSampler) – The sampler primitive to sample the circuits.

  • optimizer (Optimizer | Minimizer) – A classical optimizer to find the minimum energy. This can either be an Optimizer or a callable implementing the Minimizer protocol.

  • reps (int) – The integer parameter \(p\). Has a minimum valid value of 1.

  • initial_state (QuantumCircuit | None) – An optional initial state to prepend the QAOA circuit with.

  • mixer (QuantumCircuit | BaseOperator) – The mixer Hamiltonian to evolve with or a custom quantum circuit. Allows support of optimizations in constrained subspaces [2, 3] as well as warm-starting the optimization [4].

  • initial_point (np.ndarray | None) – An optional initial point (i.e. initial parameter values) for the optimizer. The length of the initial point must match the number of ansatz parameters. If None, a random point will be generated within certain parameter bounds. QAOA will look to the ansatz for these bounds. If the ansatz does not specify bounds, bounds of \(-2\pi\), \(2\pi\) will be used.

  • aggregation (float | Callable[[list[float]], float] | None) – A float or callable to specify how the objective function evaluated on the basis states should be aggregated. If a float, this specifies the \(\alpha \in [0,1]\) parameter for a CVaR expectation value.

  • callback (Callable[[int, np.ndarray, float, dict[str, Any]], None] | None) – A callback that can access the intermediate data at each optimization step. These data are: the evaluation count, the optimizer parameters for the ansatz, the evaluated value, the metadata dictionary.

Attributes

initial_point#

Return the initial point.

Methods

compute_minimum_eigenvalue(operator, aux_operators=None)#

Compute the minimum eigenvalue of a diagonal operator.

Parameters:
  • operator (BaseOperator) – Diagonal qubit operator.

  • aux_operators (ListOrDict[BaseOperator] | None) – Optional list of auxiliary operators to be evaluated with the final state.

Returns:

A SamplingMinimumEigensolverResult containing the optimization result.

Return type:

SamplingMinimumEigensolverResult

classmethod supports_aux_operators()#

Whether computing the expectation value of auxiliary operators is supported.

If the minimum eigensolver computes an eigenstate of the main operator then it can compute the expectation value of the aux_operators for that state. Otherwise they will be ignored.

Returns:

True if aux_operator expectations can be evaluated, False otherwise

Return type:

bool