Skip to main contentIBM Quantum Documentation

qaoa_ansatz

class qiskit.circuit.library.qaoa_ansatz(cost_operator, reps=1, initial_state=None, mixer_operator=None, insert_barriers=False, name='QAOA', flatten=True)

GitHub

Bases:

A generalized QAOA quantum circuit with a support of custom initial states and mixers.

Examples

To define the QAOA ansatz we require a cost Hamiltonian, encoding the classical optimization problem:

from qiskit.quantum_info import SparsePauliOp
from qiskit.circuit.library import qaoa_ansatz
 
cost_operator = SparsePauliOp(["ZZII", "IIZZ", "ZIIZ"])
ansatz = qaoa_ansatz(cost_operator, reps=3, insert_barriers=True)
ansatz.draw("mpl")
../_images/qiskit-circuit-library-qaoa_ansatz-1.png

Parameters

  • cost_operator (BaseOperator) – The operator representing the cost of the optimization problem, denoted as U(C,γ)U(C, \gamma) in [1].
  • reps (int) – The integer determining the depth of the circuit, called pp in [1].
  • initial_state (QuantumCircuit | None) – An optional initial state to use, which defaults to a layer of Hadamard gates preparing the +n|+\rangle^{\otimes n} state. If a custom mixer is chosen, this circuit should be set to prepare its ground state, to appropriately fulfill the annealing conditions.
  • mixer_operator (BaseOperator | None) – An optional custom mixer, which defaults to global Pauli-XX rotations. This is denoted as U(B,β)U(B, \beta) in [1]. If this is set, the initial_state might also require modification.
  • insert_barriers (bool) – Whether to insert barriers in-between the cost and mixer operators.
  • name (str) – The name of the circuit.
  • flatten (bool) – If True, a flat circuit is returned instead of nesting it inside multiple layers of gate objects. Setting this to False is significantly less performant, especially for parameter binding, but can be desirable for a cleaner visualization.

Return type

QuantumCircuit

References

[1]: Farhi et al., A Quantum Approximate Optimization Algorithm.

arXiv:1411.4028

Was this page helpful?
Report a bug or request content on GitHub.