
    z	i'                        S r SSKJr  SSKJr  SSKJrJ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 Z axis.    )annotations)exp)OptionalUnion)Gate)ControlledGate)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$ )RZGate   u  Single-qubit rotation about the Z axis.

This is a diagonal gate. It can be implemented virtually in hardware
via framechanges (i.e. at zero error and duration).

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

Circuit symbol:

.. code-block:: text

         ┌───────┐
    q_0: ┤ Rz(φ) ├
         └───────┘

Matrix representation:

.. math::

    RZ(\phi) = \exp\left(-i\frac{\phi}{2}Z\right) =
        \begin{pmatrix}
            e^{-i\frac{\phi}{2}} & 0 \\
            0 & e^{i\frac{\phi}{2}}
        \end{pmatrix}

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.U1Gate`
    This gate is equivalent to U1 up to a phase factor.

        .. math::

            U1(\theta=\phi) = e^{i{\phi}/2}RZ(\phi)

    Reference for virtual Z gate implementation:
    `1612.00858 <https://arxiv.org/abs/1612.00858>`_
c                (   > [         TU ]  SSU/US9  g)zQ
Args:
    theta: The rotation angle.
    label: An optional label for the gate.
rz   labelN)super__init__)selfphir   	__class__s      b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/rz.pyr   RZGate.__init__C   s     	q3%u5    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
   RZ_get_definitionparamsr   
definitionr   r   s     r   _defineRZGate._defineK   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-RZ 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)CRZGater$   r   	base_gater   control)r   r+   r   r*   r,   gater   s         r   r/   RZGate.controlY   sb    . _14;;q>ND#'::DNN   7? /%#	 # D r   c                4    [        U R                  S   * 5      $ )a  Return inverted RZ gate

:math:`RZ(\lambda)^{\dagger} = RZ(-\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:`.RZGate` with an inverted parameter value.

Returns:
    RZGate: inverse gate.
r   )r   r$   r   r,   s     r   inverseRZGate.inverse|   s     t{{1~o&&r   c                    SSK nUSL a  [        S5      eS[        U R                  S   5      -  nUR	                  [        U* 5      S/S[        U5      //US9$ )z%Return a numpy.array for the RZ gate.r   NF9unable to avoid copy while creating an array as requestedy              ?dtype)numpy
ValueErrorfloatr$   arrayr   )r   r9   copynpilam2s        r   	__array__RZGate.__array__   sZ    5=XYYuT[[^,,xx#uf+q)As5z?;5xIIr   c                8    U R                   u  n[        X-  5      $ N)r$   r   )r   exponentr,   thetas       r   powerRZGate.power   s    ;;h&''r   c                P    [        U[        5      (       a  U R                  U5      $ gNF)
isinstancer   _compare_parametersr   others     r   __eq__RZGate.__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   r<   r,   rV   )__name__
__module____qualname____firstlineno____doc__r
   r"   _standard_gater   r'   r/   r4   rA   rG   rO   __static_attributes____classcell__r   s   @r   r   r      s|    %N "__N6 6
   ! '+!%!! ! %	!
 ! !F' J( 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-      uQ  Controlled-RZ gate.

This is a diagonal but non-symmetric gate that induces a
phase on the state of the target qubit, depending on the control state.

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

Circuit symbol:

.. code-block:: text

    q_0: ────■────
         ┌───┴───┐
    q_1: ┤ Rz(θ) ├
         └───────┘

Matrix representation:

.. math::

    CRZ(\theta)\ q_0, q_1 =
        I \otimes |0\rangle\langle 0| + RZ(\phi=\theta) \otimes |1\rangle\langle 1| =
        \begin{pmatrix}
            1 & 0 & 0 & 0 \\
            0 & e^{-i\frac{\theta}{2}} & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 0 & 0 & e^{i\frac{\theta}{2}}
        \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: ┤ Rz(θ) ├
             └───┬───┘
        q_1: ────■────

    .. math::

        CRZ(\theta)\ q_1, q_0 =
            |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes RZ(\theta) =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 \\
                0 & 0 & e^{-i\frac{\theta}{2}} & 0 \\
                0 & 0 & 0 & e^{i\frac{\theta}{2}}
            \end{pmatrix}

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.CU1Gate`:
    Due to the global phase difference in the matrix definitions
    of U1 and RZ, CU1 and CRZ are different gates with a relative
    phase difference.
N)_base_labelc               <   > [         TU ]  SSU/SUU[        XS9S9  g)zCreate new CRZ gate.crz   r   r   )r+   r   r*   r.   N)r   r   r   )r   rF   r   r*   rc   r   s        r   r   CRZGate.__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
   CRZr#   r$   r   r%   r&   s     r   r'   CRZGate._define   sC     	2 );;,,T[[9TXT]T] < 
r   c                F    [        U R                  S   * U R                  S9$ )a  Return inverse CRZ 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:`.CRZGate` with an inverted parameter value.

 Returns:
    CRZGate: inverse gate.
r   )r*   )r-   r$   r*   r3   s     r   r4   CRZGate.inverse  s     A4??CCr   c                T   SSK nUSL a  [        S5      eS[        U R                  S   5      -  S-  nU R                  (       a3  UR                  / SQS[        U* 5      SS// SQSSS[        U5      //US	9$ UR                  [        U* 5      SSS// S
QSS[        U5      S// SQ/US	9$ )z&Return a numpy.array for the CRZ gate.r   NFr7   y              ?rf   )r   r   r   r   )r   r   r   r   r8   )r   r   r   r   )r   r   r   r   )r:   r;   r<   r$   r*   r=   r   )r   r9   r>   r:   args        r   rA   CRZGate.__array__  s    5=XYY5Q((1,??;;3t9a3\Aq!SQTXCVW   
 ;;sd)Q1%|aCHa5H,W   r   c                    [        U[        5      (       a1  U R                  U5      =(       a    U R                  UR                  :H  $ grJ   )rK   r-   rL   r*   rM   s     r   rO   CRZGate.__eq__#  s7    eW%%++E2Zt%JZJZ7ZZr   rQ   rW   )rF   r	   r   rR   r*   zOptional[Union[str, int]]rT   rU   )rX   rY   rZ   r[   r\   r
   ri   r]   r   r'   r4   rA   rO   r^   r_   r`   s   @r   r-   r-      sh    >@ "%%N
  $04	
 
!
 
 .	
 
&
D$ r   r-   N)r\   
__future__r   cmathr   typingr   r   qiskit.circuit.gater   qiskit.circuit.controlledgater   "qiskit.circuit.parameterexpressionr	   qiskit._accelerate.circuitr
   r   r-    r   r   <module>rz      s<    " "  " $ 8 A 3CT CLGn Gr   