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)
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")
Parameters
- cost_operator (BaseOperator) – The operator representing the cost of the optimization problem, denoted as in [1].
- reps (int) – The integer determining the depth of the circuit, called in [1].
- initial_state (QuantumCircuit | None) – An optional initial state to use, which defaults to a layer of Hadamard gates preparing the 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- rotations. This is denoted as 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 toFalse
is significantly less performant, especially for parameter binding, but can be desirable for a cleaner visualization.
Return type
References
[1]: Farhi et al., A Quantum Approximate Optimization Algorithm.
Was this page helpful?
Report a bug or request content on GitHub.