σ
    Σz	iL  γ                  σΔ    S r SSKJr  SSKJrJr  SSKrSSKJ	r	  SSK
JrJr  SSKJr  SS	KJrJr  SS
KJr         S                 SS jjr " S S\5      rg)z$The real-amplitudes 2-local circuit.ι    )Ϊannotations)ΪCallableΪIterableN)ΪQuantumCircuit)ΪRYGateΪCXGate)Ϊdeprecate_funcι   )Ϊn_localΪBlockEntanglement)ΪTwoLocalΪRealAmplitudesc                σD    U S:  a  S/O/ n[        U S/UUUUUSUUU5      $ )u*  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 :math:`Y`
rotations and :math:`CX` 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

.. parsed-literal::

     ββββββββββββ β            β ββββββββββββ β            β ββββββββββββ
     β€ 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 :func:`.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:

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context:

    from qiskit.circuit.library import real_amplitudes

    ansatz = real_amplitudes(3, reps=2)  # create the circuit on 3 qubits
    ansatz.draw("mpl")

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    ansatz = real_amplitudes(3, entanglement="full", reps=2)  # it is the same unitary as above
    ansatz.draw("mpl")

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    ansatz = real_amplitudes(3, entanglement="linear", reps=2, insert_barriers=True)
    ansatz.draw("mpl")

.. plot::
    :alt: Circuit diagram output by the previous code.
    :include-source:
    :context: close-figs

    ansatz = real_amplitudes(4, reps=2, entanglement=[[0,3], [0,2]], skip_unentangled_qubits=True)
    ansatz.draw("mpl")

Args:
    num_qubits: The number of qubits of the RealAmplitudes circuit.
    reps: Specifies how often the structure of a rotation layer followed by an entanglement
        layer is repeated.
    entanglement: The indices specifying on which qubits the input blocks act.
        See :func:`.n_local` for detailed information.
    skip_final_rotation_layer: Whether a final rotation layer is added to the circuit.
    skip_unentangled_qubits: If ``True``, the rotation gates act only on qubits that
        are entangled. If ``False``, the rotation gates act on all qubits.
    parameter_prefix: The name of the free parameters.
    insert_barriers: If True, barriers are inserted in between each layer. If False,
        no barriers are inserted.
    name: The name of the circuit.

Returns:
    A real-amplitudes circuit.
r
   ΪcxΪryT)r   )	Ϊ
num_qubitsΪentanglementΪrepsΪskip_unentangled_qubitsΪskip_final_rotation_layerΪparameter_prefixΪinsert_barriersΪnameΪentanglement_blockss	            Ϊh/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/n_local/real_amplitudes.pyΪreal_amplitudesr      sE    π~ %/°£N4&ΈΠδΨΨ	ΨΨΨΨΨΨΨ!ΨΨσπ σ    c                  σ   ^  \ rS rSrSr\" SSSS9          S
                     SU 4S jjj5       r\SS j5       rS	r	U =r
$ )r   ι   uΔ%  The real-amplitudes 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
alternating layers of :math:`Y` rotations and :math:`CX` entanglements. The entanglement
pattern can be user-defined or selected from a predefined set.
It is called ``RealAmplitudes`` since the prepared quantum states will only have
real amplitudes, the complex part is always 0.

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

.. code-block:: text

     ββββββββββββ β            β ββββββββββββ β            β ββββββββββββ
     β€ 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 :class:`~qiskit.circuit.library.TwoLocal` and
:class:`~qiskit.circuit.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 :math:`Y` rotations can be reduced to a single :math:`Y`
rotation with summed rotation angles.

Examples:

    >>> ansatz = RealAmplitudes(3, reps=2)  # create the circuit on 3 qubits
    >>> print(ansatz.decompose())
         ββββββββββββ                 ββββββββββββ                 ββββββββββββ
    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(3, entanglement='full', reps=2, flatten=True)
    >>> 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,
    ... flatten=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,
    ... flatten=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, flatten=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]) βββββββββββββ
         βββββββββββββββββββββββββββββ            βββββββββββββββββ

.. seealso::

    The :func:`.real_amplitudes` function constructs a functionally equivalent circuit, but faster.

z2.1z@Use the function qiskit.circuit.library.real_amplitudes instead.zin Qiskit 3.0)ΪsinceΪadditional_msgΪremoval_timelinec                σF   > [         TU ]  UU[        [        UUUUUUU	U
S9  g)aΐ  
Args:
    num_qubits: The number of qubits of the RealAmplitudes circuit.
    reps: Specifies how often the structure of a rotation layer followed by an entanglement
        layer is repeated.
    entanglement: Specifies the entanglement structure. Can be a string ('full', 'linear'
        'reverse_linear, 'circular' 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.
        Default to 'reverse_linear' entanglement.
        Note that 'reverse_linear' entanglement provides the same unitary as 'full'
        with fewer entangling gates.
        See the Examples section of :class:`~qiskit.circuit.library.TwoLocal` for more
        detail.
    initial_state: A `QuantumCircuit` object to prepend to the circuit.
    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: If False, a rotation layer is added at the end of the
        ansatz. If True, no rotation layer is added.
    parameter_prefix: The parameterized gates require a parameter to be defined, for which
        we use :class:`~qiskit.circuit.ParameterVector`.
    insert_barriers: If True, barriers are inserted in between each layer. If False,
        no barriers are inserted.
    flatten: 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.
)r   r   Ϊrotation_blocksr   r   Ϊinitial_stater   r   r   r   r   ΪflattenN)ΪsuperΪ__init__r   r   )Ϊselfr   r   r   r   r   r   r   r%   r   r&   Ϊ	__class__s              r   r(   ΪRealAmplitudes.__init__π   s<   ψ τd 	ΡΨ!Ψά"ά &Ψ%Ψ'Ψ$;Ψ&?Ψ-Ψ+ΨΨπ 	ς 	
r   c                σ`    U R                   [        R                  * [        R                  4/-  $ )zAReturn the parameter bounds.

Returns:
    The parameter bounds.
)Ϊnum_parametersΪnpΪpi)r)   s    r   Ϊparameter_boundsΪRealAmplitudes.parameter_bounds1  s&    π Χ"Ρ"¬―© v¬r―u©u oΠ%6Ρ6Π6r   © )
NΪreverse_linearι   FFυ   ΞΈFNr   N)r   z
int | Noner   z2str | list[list[int]] | Callable[[int], list[int]]r   Ϊintr   Ϊboolr   r7   r   Ϊstrr   r7   r%   zQuantumCircuit | Noner   r8   r&   zbool | NoneΪreturnΪNone)r9   zlist[tuple[float, float]])Ϊ__name__Ϊ
__module__Ϊ__qualname__Ϊ__firstlineno__Ϊ__doc__r	   r(   Ϊpropertyr0   Ϊ__static_attributes__Ϊ__classcell__)r*   s   @r   r   r      sΞ   ψ ρbρH ΨΨYΨ(ρπ "&ΨK[ΨΨ(-Ψ*/Ψ $Ψ %Ψ/3Ψ$Ψ#π:
ΰπ:
π Iπ:
π π	:
π
 "&π:
π $(π:
π π:
π π:
π -π:
π π:
π π:
π 
χ:
σπ
:
πx σ7σ φ7r   )r3   r4   FFr5   Fr   )r   r6   r   zrBlockEntanglement | Iterable[BlockEntanglement] | Callable[[int], BlockEntanglement | Iterable[BlockEntanglement]]r   r6   r   r7   r   r7   r   r8   r   r7   r   r8   r9   r   )r?   Ϊ
__future__r   Ϊcollections.abcr   r   Ϊnumpyr.   Ϊqiskit.circuitr   Ϊ%qiskit.circuit.library.standard_gatesr   r   Ϊqiskit.utils.deprecationr	   r   r   Ϊ	two_localr   r   r   r2   r   r   Ϊ<module>rJ      s°   πρ +ε "ί .γ ε )ί @έ 3ί /έ π 	ΨΨ$)Ψ&+Ψ Ψ!Ψ πmΨπmπ	Kπmπ πmπ "πmπ  $πmπ πmπ πmπ πmπ υmτ`m7Xυ m7r   