class RealAmplitudes(num_qubits=None, entanglement='full', reps=3, skip_unentangled_qubits=False, skip_final_rotation_layer=False, parameter_prefix='θ', insert_barriers=False, initial_state=None)[source]

The RealAmplitudes 2-local circuit.

The RealAmplitudes circuit is a heuristic trial wave function used as Ansatz in chemistry applications or classification circuits in machine learning. The circuit consists of of alternating layers of \(Y\) rotations and \(CX\) entanglements. The entanglement pattern can be user-defined or selected from a predefined set.

For example a RealAmplitudes circuit with 2 repetitions on 3 qubits with 'full' entanglement is

┌──────────┐ ░                 ░ ┌──────────┐ ░                 ░ ┌──────────┐
┤ RY(θ[0]) ├─░───■────■────────░─┤ RY(θ[3]) ├─░───■────■────────░─┤ RY(θ[6]) ├
├──────────┤ ░ ┌─┴─┐  │        ░ ├──────────┤ ░ ┌─┴─┐  │        ░ ├──────────┤
┤ RY(θ[1]) ├─░─┤ X ├──┼────■───░─┤ RY(θ[4]) ├─░─┤ X ├──┼────■───░─┤ RY(θ[7]) ├
├──────────┤ ░ └───┘┌─┴─┐┌─┴─┐ ░ ├──────────┤ ░ └───┘┌─┴─┐┌─┴─┐ ░ ├──────────┤
┤ RY(θ[2]) ├─░──────┤ X ├┤ X ├─░─┤ RY(θ[5]) ├─░──────┤ X ├┤ X ├─░─┤ RY(θ[8]) ├
└──────────┘ ░      └───┘└───┘ ░ └──────────┘ ░      └───┘└───┘ ░ └──────────┘

The entanglement can be set using the entanglement keyword as string or a list of index-pairs. See the documentation of TwoLocal and NLocal for more detail. Additional options that can be set include the number of repetitions, skipping rotation gates on qubits that are not entangled, leaving out the final rotation layer and inserting barriers in between the rotation and entanglement layers.

If some qubits are not entangled with other qubits it makes sense to not apply rotation gates on these qubits, since a sequence of \(Y\) rotations can be reduced to a single \(Y\) rotation with summed rotation angles.


>>> ansatz = RealAmplitudes(3, reps=2)  # create the circuit on 3 qubits
>>> print(ansatz)
     ┌──────────┐          ┌──────────┐                      ┌──────────┐
q_0: ┤ RY(θ[0]) ├──■────■──┤ RY(θ[3]) ├──────────────■────■──┤ RY(θ[6]) ├────────────
     ├──────────┤┌─┴─┐  │  └──────────┘┌──────────┐┌─┴─┐  │  └──────────┘┌──────────┐
q_1: ┤ RY(θ[1]) ├┤ X ├──┼───────■──────┤ RY(θ[4]) ├┤ X ├──┼───────■──────┤ RY(θ[7]) ├
     ├──────────┤└───┘┌─┴─┐   ┌─┴─┐    ├──────────┤└───┘┌─┴─┐   ┌─┴─┐    ├──────────┤
q_2: ┤ RY(θ[2]) ├─────┤ X ├───┤ X ├────┤ RY(θ[5]) ├─────┤ X ├───┤ X ├────┤ RY(θ[8]) ├
     └──────────┘     └───┘   └───┘    └──────────┘     └───┘   └───┘    └──────────┘
>>> ansatz = RealAmplitudes(3, entanglement='linear', reps=2, insert_barriers=True)
>>> qc = QuantumCircuit(3)  # create a circuit and append the RY variational form
>>> qc.compose(ansatz, inplace=True)
>>> qc.draw()
     ┌──────────┐ ░            ░ ┌──────────┐ ░            ░ ┌──────────┐
q_0: ┤ RY(θ[0]) ├─░───■────────░─┤ RY(θ[3]) ├─░───■────────░─┤ RY(θ[6]) ├
     ├──────────┤ ░ ┌─┴─┐      ░ ├──────────┤ ░ ┌─┴─┐      ░ ├──────────┤
q_1: ┤ RY(θ[1]) ├─░─┤ X ├──■───░─┤ RY(θ[4]) ├─░─┤ X ├──■───░─┤ RY(θ[7]) ├
     ├──────────┤ ░ └───┘┌─┴─┐ ░ ├──────────┤ ░ └───┘┌─┴─┐ ░ ├──────────┤
q_2: ┤ RY(θ[2]) ├─░──────┤ X ├─░─┤ RY(θ[5]) ├─░──────┤ X ├─░─┤ RY(θ[8]) ├
     └──────────┘ ░      └───┘ ░ └──────────┘ ░      └───┘ ░ └──────────┘
>>> ansatz = RealAmplitudes(4, reps=1, entanglement='circular', insert_barriers=True)
>>> print(ansatz)
     ┌──────────┐ ░ ┌───┐                ░ ┌──────────┐
q_0: ┤ RY(θ[0]) ├─░─┤ X ├──■─────────────░─┤ RY(θ[4]) ├
     ├──────────┤ ░ └─┬─┘┌─┴─┐           ░ ├──────────┤
q_1: ┤ RY(θ[1]) ├─░───┼──┤ X ├──■────────░─┤ RY(θ[5]) ├
     ├──────────┤ ░   │  └───┘┌─┴─┐      ░ ├──────────┤
q_2: ┤ RY(θ[2]) ├─░───┼───────┤ X ├──■───░─┤ RY(θ[6]) ├
     ├──────────┤ ░   │       └───┘┌─┴─┐ ░ ├──────────┤
q_3: ┤ RY(θ[3]) ├─░───■────────────┤ X ├─░─┤ RY(θ[7]) ├
     └──────────┘ ░                └───┘ ░ └──────────┘
>>> ansatz = RealAmplitudes(4, reps=2, entanglement=[[0,3], [0,2]],
... skip_unentangled_qubits=True)
>>> print(ansatz)
     ┌──────────┐                 ┌──────────┐                 ┌──────────┐
q_0: ┤ RY(θ[0]) ├──■───────■──────┤ RY(θ[3]) ├──■───────■──────┤ RY(θ[6]) ├
     └──────────┘  │       │      └──────────┘  │       │      └──────────┘
q_1: ──────────────┼───────┼────────────────────┼───────┼──────────────────
     ┌──────────┐  │     ┌─┴─┐    ┌──────────┐  │     ┌─┴─┐    ┌──────────┐
q_2: ┤ RY(θ[1]) ├──┼─────┤ X ├────┤ RY(θ[4]) ├──┼─────┤ X ├────┤ RY(θ[7]) ├
q_3: ┤ RY(θ[2]) ├┤ X ├┤ RY(θ[5]) ├────────────┤ X ├┤ RY(θ[8]) ├────────────
     └──────────┘└───┘└──────────┘            └───┘└──────────┘

Create a new RealAmplitudes 2-local circuit.

  • num_qubits (Optional[int]) – The number of qubits of the RealAmplitudes circuit.

  • reps (int) – Specifies how often the structure of a rotation layer followed by an entanglement layer is repeated.

  • entanglement (Union[str, List[List[int]], Callable[[int], List[int]]]) – Specifies the entanglement structure. Can be a string (‘full’, ‘linear’ or ‘sca’), a list of integer-pairs specifying the indices of qubits entangled with one another, or a callable returning such a list provided with the index of the entanglement layer. See the Examples section of TwoLocal for more detail.

  • initial_state (Optional[Any]) – An InitialState object to prepend to the circuit.

  • skip_unentangled_qubits (bool) – If True, the single qubit gates are only applied to qubits that are entangled with another qubit. If False, the single qubit gates are applied to each qubit in the Ansatz. Defaults to False.

  • skip_unentangled_qubits – If True, the single qubit gates are only applied to qubits that are entangled with another qubit. If False, the single qubit gates are applied to each qubit in the Ansatz. Defaults to False.

  • skip_final_rotation_layer (bool) – If False, a rotation layer is added at the end of the ansatz. If True, no rotation layer is added.

  • parameter_prefix (str) – The parameterized gates require a parameter to be defined, for which we use ParameterVector.

  • insert_barriers (bool) – If True, barriers are inserted in between each layer. If False, no barriers are inserted.



Returns a list of classical bits in the order that the registers were added.

Return the circuit data (instructions and context).


Get the entanglement strategy.


The blocks in the entanglement layers.




Return the initial state that is added in front of the n-local circuit.


If barriers are inserted in between the layers or not.



Deprecated, use num_qubits instead.


Return number of classical bits.


Return the number of layers in the n-local circuit.


Convenience function to get the number of parameter objects in the circuit.


The number of total parameters that can be set to distinct values.


Returns the number of qubits in this circuit.


The parameters used in the underlying circuit.


Return the parameter bounds.


Get the Parameter objects in the circuit.


The initial points for the parameters.



A list of the quantum registers associated with the circuit.


Returns a list of quantum bits in the order that the registers were added.


The number of times rotation and entanglement block are repeated.


The blocks in the rotation layers.


RealAmplitudes.AND(qr_variables, qb_target, …)

Build a collective conjunction (AND) circuit in place using mct.

RealAmplitudes.OR(qr_variables, qb_target, …)

Build a collective disjunction (OR) circuit in place using mct.


Return indexed operation.


Return number of operations in circuit.

RealAmplitudes.add_layer(other[, …])

Append another layer to the NLocal.


Add registers.

RealAmplitudes.append(instruction[, qargs, …])

Append one or more instructions to the end of the circuit, modifying the circuit in place.


Assign parameters to the n-local circuit.


Apply Barrier.


Assign numeric parameters to values yielding a new circuit.

RealAmplitudes.cast(value, _type)

Best effort to cast value to type.


Converts several classical bit representations (such as indexes, range, etc.) into a list of classical bits.

RealAmplitudes.ccx(control_qubit1, …[, …])

Apply CCXGate., target_qubit, *)

Apply CHGate.


Return the current number of instances of this class, useful for auto naming.


Return the prefix to use for auto naming.

RealAmplitudes.cnot(control_qubit, …[, …])

Apply CXGate.


Append rhs to self if self contains compatible registers.

RealAmplitudes.compose(other[, qubits, …])

Compose circuit with other circuit or instruction, optionally permuting wires.


Copy the circuit.


Count each operation kind in the circuit.

RealAmplitudes.crx(theta, control_qubit, …)

Apply CRXGate.

RealAmplitudes.cry(theta, control_qubit, …)

Apply CRYGate.

RealAmplitudes.crz(theta, control_qubit, …)

Apply CRZGate.

RealAmplitudes.cswap(control_qubit, …[, …])

Apply CSwapGate.

RealAmplitudes.cu1(theta, control_qubit, …)

Apply CU1Gate.

RealAmplitudes.cu3(theta, phi, lam, …[, …])

Apply CU3Gate., target_qubit, *)

Apply CXGate., target_qubit, *)

Apply CYGate., target_qubit, *)

Apply CZGate.

RealAmplitudes.dcx(qubit1, qubit2)

Apply DCXGate.


Call a decomposition pass on this circuit, to decompose one level (shallow decompose).


Return circuit depth (i.e., length of critical path).

RealAmplitudes.diag_gate(diag, qubit)

Deprecated version of QuantumCircuit.diagonal.

RealAmplitudes.diagonal(diag, qubit)

Attach a diagonal gate to a circuit.

RealAmplitudes.draw([output, scale, …])

Draw the quantum circuit.


Append QuantumCircuit to the right hand side if it contains compatible registers.

RealAmplitudes.fredkin(control_qubit, …[, …])

Apply CSwapGate.


Take in a QASM file and generate a QuantumCircuit object.


Take in a QASM string and generate a QuantumCircuit object.

RealAmplitudes.get_entangler_map(rep_num, …)

Overloading to handle the special case of 1 qubit where the entanglement are ignored.


Get the indices of unentangled qubits in a set.

RealAmplitudes.h(qubit, *[, q])

Apply HGate.

RealAmplitudes.hamiltonian(operator, time, …)

Apply hamiltonian evolution to to qubits.


Test if this circuit has the register r.

RealAmplitudes.i(qubit, *[, q])

Apply IGate., *[, q])

Apply IGate.

RealAmplitudes.iden(qubit, *[, q])

Deprecated identity gate.

RealAmplitudes.initialize(params, qubits)

Apply initialize to circuit.


Invert this circuit.

RealAmplitudes.iso(isometry, q_input, …[, …])

Attach an arbitrary isometry from m to n qubits to a circuit.

RealAmplitudes.isometry(isometry, q_input, …)

Attach an arbitrary isometry from m to n qubits to a circuit.

RealAmplitudes.iswap(qubit1, qubit2)

Apply iSwapGate.

RealAmplitudes.mcmt(gate, control_qubits, …)

Apply a multi-control, multi-target using a generic gate.

RealAmplitudes.mcrx(theta, q_controls, q_target)

Apply Multiple-Controlled X rotation gate

RealAmplitudes.mcry(theta, q_controls, …)

Apply Multiple-Controlled Y rotation gate

RealAmplitudes.mcrz(lam, q_controls, q_target)

Apply Multiple-Controlled Z rotation gate

RealAmplitudes.mct(control_qubits, target_qubit)

Apply MCXGate.

RealAmplitudes.mcu1(lam, control_qubits, …)

Apply MCU1Gate.

RealAmplitudes.mcx(control_qubits, target_qubit)

Apply MCXGate.

RealAmplitudes.measure(qubit, cbit)

Measure quantum bit into classical bit (tuples).


Adds measurement to all non-idle qubits.


Adds measurement to all qubits.


Mirror the circuit by reversing the instructions., qubits)

Apply MSGate.


How many non-entangled subcircuits can the circuit be factored to.


Return number of non-local gates (i.e.


Computes the number of tensor factors in the unitary (quantum) part of the circuit only.


Computes the number of tensor factors in the unitary (quantum) part of the circuit only.


Returns information about the setting.

RealAmplitudes.qasm([formatted, filename])

Return OpenQASM string.


Converts several qubit representations (such as indexes, range, etc.) into a list of qubits.

RealAmplitudes.r(theta, phi, qubit, *[, q])

Apply RGate.

RealAmplitudes.rcccx(control_qubit1, …)

Apply RC3XGate.

RealAmplitudes.rccx(control_qubit1, …)

Apply RCCXGate.


Removes final measurement on all qubits if they are present.


Reset q.

RealAmplitudes.rx(theta, qubit, *[, label, q])

Apply RXGate.

RealAmplitudes.rxx(theta, qubit1, qubit2)

Apply RXXGate.

RealAmplitudes.ry(theta, qubit, *[, label, q])

Apply RYGate.

RealAmplitudes.ryy(theta, qubit1, qubit2)

Apply RYYGate.

RealAmplitudes.rz(phi, qubit, *[, q])

Apply RZGate.

RealAmplitudes.rzx(theta, qubit1, qubit2)

Apply RZXGate.

RealAmplitudes.rzz(theta, qubit1, qubit2)

Apply RZZGate.

RealAmplitudes.s(qubit, *[, q])

Apply SGate.

RealAmplitudes.sdg(qubit, *[, q])

Apply SdgGate.


Returns total number of gate operations in circuit.

RealAmplitudes.snapshot(label[, …])

Take a statevector snapshot of the internal simulator representation.


Take a density matrix snapshot of simulator state.


Take a snapshot of expectation value <O> of an Operator.

RealAmplitudes.snapshot_probabilities(label, …)

Take a probability snapshot of the simulator state.


Take a stabilizer snapshot of the simulator state.


Take a statevector snapshot of the simulator state.

RealAmplitudes.squ(unitary_matrix, qubit[, …])

Decompose an arbitrary 2*2 unitary into three rotation gates.

RealAmplitudes.swap(qubit1, qubit2)

Apply SwapGate.

RealAmplitudes.t(qubit, *[, q])

Apply TGate.

RealAmplitudes.tdg(qubit, *[, q])

Apply TdgGate.


Create a Gate out of this circuit.


Create an Instruction out of this circuit.

RealAmplitudes.toffoli(control_qubit1, …)

Apply CCXGate.

RealAmplitudes.u1(theta, qubit, *[, q])

Apply U1Gate.

RealAmplitudes.u2(phi, lam, qubit, *[, q])

Apply U2Gate.

RealAmplitudes.u3(theta, phi, lam, qubit, *)

Apply U3Gate.

RealAmplitudes.uc(gate_list, q_controls, …)

Attach a uniformly controlled gates (also called multiplexed gates) to a circuit.

RealAmplitudes.ucg(angle_list, q_controls, …)

Deprecated version of uc.

RealAmplitudes.ucrx(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed) Rx rotation gate to a circuit.

RealAmplitudes.ucry(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed) Ry rotation gate to a circuit.

RealAmplitudes.ucrz(angle_list, q_controls, …)

Attach a uniformly controlled (also called multiplexed gates) Rz rotation gate to a circuit.

RealAmplitudes.ucx(angle_list, q_controls, …)

Deprecated version of ucrx.

RealAmplitudes.ucy(angle_list, q_controls, …)

Deprecated version of ucry.

RealAmplitudes.ucz(angle_list, q_controls, …)

Deprecated version of ucrz.

RealAmplitudes.unitary(obj, qubits[, label])

Apply unitary gate to q.


Return number of qubits plus clbits in circuit.

RealAmplitudes.x(qubit, *[, label, …])

Apply XGate.

RealAmplitudes.y(qubit, *[, q])

Apply YGate.

RealAmplitudes.z(qubit, *[, q])

Apply ZGate.


Return indexed operation.


Return number of operations in circuit.