QAOAAnsatz
class qiskit.circuit.library.QAOAAnsatz(cost_operator=None, reps=1, initial_state=None, mixer_operator=None, name='QAOA', flatten=None)
Bases: EvolvedOperatorAnsatz
A generalized QAOA quantum circuit with a support of custom initial states and mixers.
References
[1]: Farhi et al., A Quantum Approximate Optimization Algorithm.
Parameters
- cost_operator (BaseOperator or OperatorBase, optional) – The operator representing the cost of the optimization problem, denoted as in the original paper. Must be set either in the constructor or via property setter.
- reps (int) – The integer parameter p, which determines the depth of the circuit, as specified in the original paper, default is 1.
- initial_state (QuantumCircuit, optional) – An optional initial state to use. If None is passed then a set of Hadamard gates is applied as an initial state to all qubits.
- mixer_operator (BaseOperator or OperatorBase or QuantumCircuit, optional) – An optional custom mixer to use instead of the global X-rotations, denoted as in the original paper. Can be an operator or an optionally parameterized quantum circuit.
- name (str) – A name of the circuit, default ‘qaoa’
- flatten (bool | None) – Set this to
True
to output a flat circuit instead of nesting it inside multiple layers of gate objects. By default currently the contents of the output circuit will be wrapped in nested objects for cleaner visualization. However, if you’re using this circuit for anything besides visualization its strongly recommended to set this flag toTrue
to avoid a large performance overhead for parameter binding.
Attributes
cost_operator
Returns an operator representing the cost of the optimization problem.
Returns
cost operator.
Return type
BaseOperator or OperatorBase
initial_state
Returns an optional initial state as a circuit
mixer_operator
Returns an optional mixer operator expressed as an operator or a quantum circuit.
Returns
mixer operator or circuit.
Return type
BaseOperator or OperatorBase or QuantumCircuit, optional
num_qubits
operators
The operators that are evolved in this circuit.
Returns
The operators to be evolved
(and circuits) in this ansatz.
Return type
List[Union[BaseOperator, OperatorBase, QuantumCircuit]]
parameter_bounds
The parameter bounds for the unbound parameters in the circuit.
Returns
A list of pairs indicating the bounds, as (lower, upper). None indicates an unbounded parameter in the corresponding direction. If None is returned, problem is fully unbounded.
reps
Returns the reps parameter, which determines the depth of the circuit.
name
Type: str
A human-readable name for the circuit.
Example
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 2, name="my_circuit")
print(qc.name)
my_circuit