
    z	i%                        S r SSKJr  SSKrSSKJrJr  SSKrSSKJ	r	  SSK
Jr  SSKJr  SSKJr   " S	 S
\5      r " S S\	5      rg)zRotation around the Y axis.    )annotationsN)OptionalUnion)ControlledGate)Gate)ParameterValueType)StandardGatec                     ^  \ rS rSrSr\R                  rSSU 4S jjjrS r	    S       SU 4S jjjr
SSS jjrSS jrSSS jjrS	 rS
rU =r$ )RYGate   u  Single-qubit rotation about the Y axis.

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.ry` method.

Circuit symbol:

.. code-block:: text

         ┌───────┐
    q_0: ┤ Ry(ϴ) ├
         └───────┘

Matrix representation:

.. math::

    \newcommand{\rotationangle}{\frac{\theta}{2}}

    RY(\theta) = \exp\left(-i \rotationangle Y\right) =
        \begin{pmatrix}
            \cos\left(\rotationangle\right) & -\sin\left(\rotationangle\right) \\
            \sin\left(\rotationangle\right) & \cos\left(\rotationangle\right)
        \end{pmatrix}
c                (   > [         TU ]  SSU/US9  g)zQ
Args:
    theta: The rotation angle.
    label: An optional label for the gate.
ry   labelN)super__init__)selfthetar   	__class__s      b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/ry.pyr   RYGate.__init__7   s     	q5'7    c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gzDefault definitionr   )QuantumCircuitT)legacy_qubitsnameN)	qiskit.circuitr   _from_circuit_datar	   RY_get_definitionparamsr   
definitionr   r   s     r   _defineRYGate._define?   sA     	2 );;OO++DKK8SWS\S\ < 
r   c                   > U(       d:  US:X  a4  [        U R                  S   X#S9nU R                  UR                  l        U$ [        TU ]  UUUUS9nU$ )a  Return a (multi-)controlled-RY gate.

Args:
    num_ctrl_qubits: number of control qubits.
    label: An optional label for the gate [Default: ``None``]
    ctrl_state: control state expressed as integer,
        string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
    annotated: indicates whether the controlled gate should be implemented
        as an annotated gate. If ``None``, this is set to ``True`` if
        the gate contains free parameters and more than one control qubit, in which
        case it cannot yet be synthesized. Otherwise it is set to ``False``.

Returns:
    ControlledGate: controlled version of this gate.
r   r   )r   
ctrl_state)num_ctrl_qubitsr   r)   	annotated)CRYGater#   r   	base_gater   control)r   r*   r   r)   r+   gater   s         r   r.   RYGate.controlL   sb    . _14;;q>ND#'::DNN   7? /%#	 # D r   c                4    [        U R                  S   * 5      $ )a  Return inverse RY gate.

:math:`RY(\lambda)^{\dagger} = RY(-\lambda)`

Args:
    annotated: when set to ``True``, this is typically used to return an
        :class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
        :class:`.Gate`. However, for this class this argument is ignored as the inverse
        of this gate is always a :class:`.RYGate` with an inverted parameter value.

Returns:
    RYGate: inverse gate.
r   )r   r#   r   r+   s     r   inverseRYGate.inverseo   s     t{{1~o&&r   c                    USL a  [        S5      e[        R                  " U R                  S   S-  5      n[        R                  " U R                  S   S-  5      n[
        R                  " X4* /XC//US9$ )z%Return a numpy.array for the RY gate.F9unable to avoid copy while creating an array as requestedr      dtype)
ValueErrormathcosr#   sinnumpyarray)r   r9   copyr<   r=   s        r   	__array__RYGate.__array__   sg    5=XYYhht{{1~)*hht{{1~)*{{S$K#4EBBr   c                8    U R                   u  n[        X-  5      $ N)r#   r   )r   exponentr+   r   s       r   powerRYGate.power   s    ;;h&''r   c                P    [        U[        5      (       a  U R                  U5      $ gNF)
isinstancer   _compare_parametersr   others     r   __eq__RYGate.__eq__   s#    eV$$++E22r   r$   rD   )r   r   r   Optional[str])r   NNN)r*   intr   z
str | Noner)   zstr | int | Noner+   zbool | NoneFr+   boolNN)rE   floatr+   rU   )__name__
__module____qualname____firstlineno____doc__r	   r!   _standard_gater   r&   r.   r3   rA   rF   rN   __static_attributes____classcell__r   s   @r   r   r      s{    4 "__N8 8
  ! '+!%!! ! %	!
 ! !F' C( r   r   c                     ^  \ rS rSrSr\R                  r  SSS.     SU 4S jjjjrS r	SSS jjr
SS jrS	 rS
rU =r$ )r,      u  Controlled-RY gate.

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.cry` method.

Circuit symbol:

.. code-block:: text

    q_0: ────■────
         ┌───┴───┐
    q_1: ┤ Ry(ϴ) ├
         └───────┘

Matrix representation:

.. math::

    \newcommand{\rotationangle}{\frac{\theta}{2}}

    CRY(\theta)\ q_0, q_1 =
        I \otimes |0\rangle\langle 0| + RY(\theta) \otimes |1\rangle\langle 1| =
        \begin{pmatrix}
            1 & 0         & 0 & 0 \\
            0 & \cos\left(\rotationangle\right) & 0 & -\sin\left(\rotationangle\right) \\
            0 & 0         & 1 & 0 \\
            0 & \sin\left(\rotationangle\right) & 0 & \cos\left(\rotationangle\right)
        \end{pmatrix}

.. note::

    In Qiskit's convention, higher qubit indices are more significant
    (little endian convention). In many textbooks, controlled gates are
    presented with the assumption of more significant qubits as control,
    which in our case would be q_1. Thus a textbook matrix for this
    gate will be:

    .. code-block:: text

             ┌───────┐
        q_0: ┤ Ry(ϴ) ├
             └───┬───┘
        q_1: ────■────

    .. math::

        \newcommand{\rotationangle}{\frac{\theta}{2}}

        CRY(\theta)\ q_1, q_0 =
        |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes RY(\theta) =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 \\
                0 & 0 & \cos\left(\rotationangle\right) & -\sin\left(\rotationangle\right) \\
                0 & 0 & \sin\left(\rotationangle\right) & \cos\left(\rotationangle\right)
            \end{pmatrix}
N)_base_labelc               <   > [         TU ]  SSU/SUU[        XS9S9  g)zCreate new CRY gate.cryr7   r   r   )r*   r   r)   r-   N)r   r   r   )r   r   r   r)   rc   r   s        r   r   CRYGate.__init__   s3     	G!U6 	 	
r   c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gr   )	r   r   r    r	   CRYr"   r#   r   r$   r%   s     r   r&   CRYGate._define   sC     	2 );;,,T[[9TXT]T] < 
r   c                F    [        U R                  S   * U R                  S9$ )a  Return inverse CRY gate (i.e. with the negative rotation angle)

Args:
    annotated: when set to ``True``, this is typically used to return an
        :class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
        :class:`.Gate`. However, for this class this argument is ignored as the inverse
        of this gate is always a :class:`.CRYGate` with an inverted parameter value.

Returns:
    CRYGate: inverse gate.
.r   )r)   )r,   r#   r)   r2   s     r   r3   CRYGate.inverse   s     A4??CCr   c           	     j   USL a  [        S5      e[        U R                  S   5      S-  n[        R                  " U5      n[        R
                  " U5      nU R                  (       a&  [        R                  " / SQSUSU* // SQSUSU//US9$ [        R                  " USU* S// SQUSUS// S	Q/US9$ )
z&Return a numpy.array for the CRY gate.Fr6   r   r7   )r   r   r   r   )r   r   r   r   r8   )r   r   r   r   )r   r   r   r   )	r:   rW   r#   r;   r<   r=   r)   r>   r?   )r   r9   r@   
half_thetar<   r=   s         r   rA   CRYGate.__array__   s    5=XYY4;;q>*Q.
hhz"hhz"??;;3C40,CC@PQY^  ;;q3$"L332BLQY^ r   c                    [        U[        5      (       a1  U R                  U5      =(       a    U R                  UR                  :H  $ grI   )rJ   r,   rK   r)   rL   s     r   rN   CRYGate.__eq__  s7    eW%%++E2Zt%JZJZ7ZZr   rP   rV   )r   r   r   rQ   r)   zOptional[Union[str, int]]rS   rT   )rX   rY   rZ   r[   r\   r	   rh   r]   r   r&   r3   rA   rN   r^   r_   r`   s   @r   r,   r,      sh    8t "%%N
  $04	
 
!
 
 .	
 
&
D  r   r,   )r\   
__future__r   r;   typingr   r   r>   qiskit.circuit.controlledgater   qiskit.circuit.gater   "qiskit.circuit.parameterexpressionr   qiskit._accelerate.circuitr	   r   r,    r   r   <module>rx      s?    " "  "  8 $ A 3tT tnn r   