Skip to main contentIBM Quantum Documentation

real_amplitudes

class qiskit.circuit.library.real_amplitudes(num_qubits, entanglement='reverse_linear', reps=3, skip_unentangled_qubits=False, skip_final_rotation_layer=False, parameter_prefix='θ', insert_barriers=False, name='RealAmplitudes')

GitHub

Bases:

Construct a real-amplitudes 2-local circuit.

This circuit is a heuristic trial wave function used, e.g., as ansatz in chemistry, optimization or machine learning applications. The circuit consists of alternating layers of YY rotations and CXCX entanglements. The entanglement pattern can be user-defined or selected from a predefined set. This circuit is “real amplitudes” since the prepared quantum states will only have real amplitudes.

For example a real_amplitudes circuit with 2 repetitions on 3 qubits with "reverse_linear" entanglement is

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

The entanglement can be set using the entanglement keyword as string or a list of index-pairs. See the documentation of n_local(). 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.

Examples

from qiskit.circuit.library import real_amplitudes
 
ansatz = real_amplitudes(3, reps=2)  # create the circuit on 3 qubits
ansatz.draw("mpl")
../_images/qiskit-circuit-library-real_amplitudes-1.png
ansatz = real_amplitudes(3, entanglement="full", reps=2)  # it is the same unitary as above
ansatz.draw("mpl")
../_images/qiskit-circuit-library-real_amplitudes-2_00.png../_images/qiskit-circuit-library-real_amplitudes-2_01.png
ansatz = real_amplitudes(3, entanglement="linear", reps=2, insert_barriers=True)
ansatz.draw("mpl")
../_images/qiskit-circuit-library-real_amplitudes-3_00.png../_images/qiskit-circuit-library-real_amplitudes-3_01.png../_images/qiskit-circuit-library-real_amplitudes-3_02.png
ansatz = real_amplitudes(4, reps=2, entanglement=[[0,3], [0,2]], skip_unentangled_qubits=True)
ansatz.draw("mpl")
../_images/qiskit-circuit-library-real_amplitudes-4_00.png../_images/qiskit-circuit-library-real_amplitudes-4_01.png../_images/qiskit-circuit-library-real_amplitudes-4_02.png../_images/qiskit-circuit-library-real_amplitudes-4_03.png

Parameters

  • num_qubits (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 (BlockEntanglement | Iterable[BlockEntanglement] | Callable[[int], BlockEntanglement | Iterable[BlockEntanglement]]) – The indices specifying on which qubits the input blocks act. See n_local() for detailed information.
  • skip_final_rotation_layer (bool) – Whether a final rotation layer is added to the circuit.
  • skip_unentangled_qubits (bool) – If True, the rotation gates act only on qubits that are entangled. If False, the rotation gates act on all qubits.
  • parameter_prefix (str) – The name of the free parameters.
  • insert_barriers (bool) – If True, barriers are inserted in between each layer. If False, no barriers are inserted.
  • name (str) – The name of the circuit.

Returns

A real-amplitudes circuit.

Return type

QuantumCircuit

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