QAOA

class QAOA

Quantum Approximate Optimization Algorithm (QAOA).

A variational quantum algorithm that alternates between a cost Hamiltonian and a mixer Hamiltonian to find approximate solutions to combinatorial optimization problems encoded as Ising models.

Pass this class to any QuantumBaseClient subclass to run QAOA on the corresponding backend.

Methods

acceptable_degrees

Return the polynomial degrees accepted by the selected QAOA variant.

run

Run QAOA on the given optimization model.

class Parameters

Configuration parameters for a QAOA run.

__eq__(other)

Return self==value.

__init__(reps: int = 10, shots: int = 1024, qaoa_type: QAOAType | tuple[type[QAOAImplProtocol], AcceptableDegrees] = QAOAType.AUTO, minimize: MinimizeProtocol = <factory>) None
__repr__()

Return repr(self).

__dataclass_fields__ = {'minimize': Field(name='minimize',type='MinimizeProtocol',default=<dataclasses._MISSING_TYPE object>,default_factory=<class 'amplify_quantum.minimize.scipy.ScipyMinimize'>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'qaoa_type': Field(name='qaoa_type',type='QAOAType | tuple[type[QAOAImplProtocol], AcceptableDegrees]',default=<QAOAType.AUTO: (<class 'amplify_quantum.algo.qaoa.impls.qaoa_auto.AutoQAOAImpl'>, <amplify.AcceptableDegrees object>)>,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'reps': Field(name='reps',type='int',default=10,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD), 'shots': Field(name='shots',type='int',default=1024,default_factory=<dataclasses._MISSING_TYPE object>,init=True,repr=True,hash=None,compare=True,metadata=mappingproxy({}),kw_only=False,_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
__match_args__ = ('reps', 'shots', 'qaoa_type', 'minimize')
minimize: MinimizeProtocol

Classical optimizer used to tune the variational circuit parameters. Defaults to ScipyMinimize with the COBYLA method.

qaoa_type: QAOAType | tuple[type[QAOAImplProtocol], AcceptableDegrees] = (<class 'amplify_quantum.algo.qaoa.impls.qaoa_auto.AutoQAOAImpl'>, <amplify.AcceptableDegrees object>)

QAOA implementation to use. Either a QAOAType value for the built-in strategies, or a custom class implementing the QAOAImplProtocol interface.

reps: int = 10

Number of QAOA layers (circuit depth p). Increasing this value may improve solution quality at the cost of a deeper circuit.

Must be greater than or equal to 0.

shots: int = 1024

Number of measurement shots per circuit evaluation. Must be greater than or equal to 0.

class Result

Bases: Generic[SamplingMeta_co]

Result of a QAOA run.

__init__(result: QAOAResult[SamplingMeta_co]) None
durations: QAOADurations

Total timing breakdown for the entire QAOA run.

history: Sequence[QAOAHistoryItem[SamplingMeta_co]]

Per-evaluation records accumulated during classical optimization, in the order they were evaluated.

num_execution: int

Number of objective function evaluations performed during classical optimization.

optimized_cost: float

Best (lowest) cost value found.

optimized_counts: IsingSeqFreqList

Measurement results from the circuit evaluated at optimized_parameters, as a list of (spin_sequence, frequency) pairs.

optimized_parameters: tuple[float, ...]

Circuit parameter values that produced the best cost.

static acceptable_degrees(parameters: Parameters) AcceptableDegrees

Return the polynomial degrees accepted by the selected QAOA variant.

Parameters:

parameters (Parameters) – QAOA configuration from which the qaoa_type is read.

Returns:

The degree constraints for the objective polynomial, determined by the chosen QAOAType or custom implementation tuple.

Return type:

AcceptableDegrees

static run(
sampler: SamplerProtocol[SamplingMeta_co, SupportsAnsatz | SupportsCAnsatz],
model: Model,
parameters: Parameters,
dry_run: Literal[False] = False,
) Result[SamplingMeta_co]
static run(
sampler: SamplerProtocol[SamplingMeta_co, SupportsAnsatz | SupportsCAnsatz],
model: Model,
parameters: Parameters,
dry_run: Literal[True],
) None

Run QAOA on the given optimization model.

Parameters:
  • sampler (SamplerProtocol[SamplingMeta_co, SupportsAnsatz | SupportsCAnsatz]) – Backend sampler that executes quantum circuits and returns measurement results.

  • model (Model) – The optimization model containing the objective function and constraints.

  • parameters (Parameters) – QAOA configuration (circuit depth, shots, optimizer, etc.).

  • dry_run (bool) – If True, validate inputs without executing circuits and return None.

Returns:

The QAOA result, or None if dry_run is True.

Return type:

Result[SamplingMeta_co] | None