---
title: QAOAAnsatz (latest version)
description: API reference for qiskit.circuit.library.QAOAAnsatz in the latest version of qiskit
source: https://eu-de.quantum.cloud.ibm.com/docs/en/api/qiskit/qiskit.circuit.library.QAOAAnsatz
---

# QAOAAnsatz

*class* `qiskit.circuit.library.QAOAAnsatz(cost_operator=None, reps=1, initial_state=None, mixer_operator=None, name='QAOA', flatten=None)`

[GitHub](https://github.com/Qiskit/qiskit/tree/stable/2.5/qiskit/circuit/library/n_local/qaoa_ansatz.py#L108-L367)

Bases: [`EvolvedOperatorAnsatz`](/docs/api/qiskit/qiskit.circuit.library.EvolvedOperatorAnsatz "qiskit.circuit.library.n_local.evolved_operator_ansatz.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. [arXiv:1411.4028](https://arxiv.org/pdf/1411.4028)

**Parameters**

- **cost\_operator** (*BaseOperator or OperatorBase, optional*) – The operator representing the cost of the optimization problem, denoted as $U(C, \gamma)$ in the original paper. Must be set either in the constructor or via property setter.
- **reps** ([*int*](https://docs.python.org/3/library/functions.html#int)) – The integer parameter p, which determines the depth of the circuit, as specified in the original paper, default is 1.
- **initial\_state** ([*QuantumCircuit*](/docs/api/qiskit/qiskit.circuit.QuantumCircuit "qiskit.circuit.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*](/docs/api/qiskit/qiskit.circuit.QuantumCircuit "qiskit.circuit.QuantumCircuit")*, optional*) – An optional custom mixer to use instead of the global X-rotations, denoted as $U(B, \beta)$ in the original paper. Can be an operator or an optionally parameterized quantum circuit.
- **name** ([*str*](https://docs.python.org/3/library/stdtypes.html#str)) – A name of the circuit, default ‘qaoa’
- **flatten** ([*bool*](https://docs.python.org/3/library/functions.html#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 to `True` 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](/docs/api/qiskit/qiskit.circuit.QuantumCircuit "qiskit.circuit.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](/docs/api/qiskit/qiskit.circuit.QuantumCircuit "qiskit.circuit.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**

```python
from qiskit import QuantumCircuit

qc = QuantumCircuit(2, 2, name="my_circuit")
print(qc.name)
```

```text
my_circuit
```
