
    z	i:                        S r SSKJr  SSK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	KJr   " S
 S\	5      r " S S\5      r " S S\5      rg)zU1 Gate.    )annotations)expN)ControlledGate)Gate)ParameterValueType)_ctrl_state_to_int)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 rS	rU =r$ )U1Gate   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).

.. warning::

   This gate is deprecated. Instead, the following replacements should be used

   .. math::

       U1(\theta) = P(\theta)= U(0,0,\theta)

   .. code-block:: python

      circuit = QuantumCircuit(1)
      circuit.p(lambda, 0) # or circuit.u(0, 0, lambda, 0)

Circuit symbol:

.. code-block:: text

         ┌───────┐
    q_0: ┤ U1(θ) ├
         └───────┘

Matrix representation:

.. math::

    U1(\theta) =
        \begin{pmatrix}
            1 & 0 \\
            0 & e^{i\theta}
        \end{pmatrix}

Examples:

.. math::

    U1(\theta = \pi) = Z

.. math::

    U1(\theta = \pi/2) = S

.. math::

    U1(\theta = \pi/4) = T

.. seealso::

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

        .. math::

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

    :class:`~qiskit.circuit.library.standard_gates.U3Gate`:
    U3 is a generalization of U2 that covers all single-qubit rotations,
    using two X90 pulses.

    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.
u1   labelN)super__init__)selfthetar   	__class__s      b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/u1.pyr   U1Gate.__init__^   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	   U1_get_definitionparamsr   
definitionr   r   s     r   _defineU1Gate._definef   sA     	2 );;OO++DKK8SWS\S\ < 
r   c                2  > U(       d:  US:X  a4  [        U R                  S   X#S9nU R                  UR                  l        U$ U(       d=  Uc:  US:  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-U1 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.

Returns:
    ControlledGate: controlled version of this gate.
r   r   )r   
ctrl_stater   num_ctrl_qubitsr   r)   	annotated)CU1Gater#   r   	base_gateMCU1Gater   controlr   r+   r   r)   r,   gater   s         r   r0   U1Gate.controls   s    ( _14;;q>ND#'::DNN   z1o6IDKKNOID#'::DNN   7? /%#	 # D r   c                4    [        U R                  S   * 5      $ )a  Return inverted U1 gate (:math:`U1(\lambda)^{\dagger} = U1(-\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:`.U1Gate` with inverse parameter values.

Returns:
    U1Gate: inverse gate.
r   )r   r#   r   r,   s     r   inverseU1Gate.inverse   s     t{{1~o&&r   c                    USL a  [        S5      e[        U R                  S   5      n[        R                  " SS/S[        R
                  " SU-  5      //US9$ )z%Return a numpy.array for the U1 gate.F9unable to avoid copy while creating an array as requestedr   r                 ?dtype)
ValueErrorfloatr#   numpyarrayr   )r   r<   copylams       r   	__array__U1Gate.__array__   sS    5=XYYDKKN#{{QFQ		"s((;$<=UKKr   c                R    [        U[        5      =(       a    U R                  U5      $ N)
isinstancer   _compare_parametersr   others     r   __eq__U1Gate.__eq__   s    %(LT-E-Ee-LLr   r$   rF   )r   r   r   
str | Noner   NNFr+   intr   rN   r)   str | int | Noner,   boolFr,   rS   NN)__name__
__module____qualname____firstlineno____doc__r	   r!   _standard_gater   r&   r0   r6   rC   rK   __static_attributes____classcell__r   s   @r   r   r      sz    AF "__N8 8
  ! '+!! ! %	!
 ! !F'LM M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U 4S jjjr
SSS jjrSS	 jrS
 rSrU =r$ )r-      u  Controlled-U1 gate.

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

.. warning::

   This gate is deprecated. Instead, the :class:`.CPhaseGate` should be used

   .. math::

       CU1(\lambda) = CP(\lambda)

   .. code-block:: python

      circuit = QuantumCircuit(2)
      circuit.cp(lambda, 0, 1)




Circuit symbol:

.. code-block:: text


    q_0: ─■──
          │θ
    q_1: ─■──


Matrix representation:

.. math::

    CU1(\theta) =
        I \otimes |0\rangle\langle 0| + U1 \otimes |1\rangle\langle 1| =
        \begin{pmatrix}
            1 & 0 & 0 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 0 & 0 & e^{i\theta}
        \end{pmatrix}

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.CRZGate`:
    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 CU1 gate.cu1   r   r   r+   r   r)   r.   Nr   r   r   )r   r   r   r)   rc   r   s        r   r   CU1Gate.__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	   CU1r"   r#   r   r$   r%   s     r   r&   CU1Gate._define   sC     	2 );;,,T[[9TXT]T] < 
r   c                   > U(       d;  Uc8  [        U R                  S   US-   US9nU R                  UR                  l        U$ [        TU ]  UUUUS9nU$ )  Controlled version of this 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.

Returns:
    ControlledGate: controlled version of this gate.
r   r   )r+   r   r*   )r/   r#   r   r.   r   r0   r1   s         r   r0   CU1Gate.control  sh    ( Z/DKKNOa<OW\]D#'::DNN   7? /%#	 # D r   c                F    [        U R                  S   * U R                  S9$ )a  Return inverted CU1 gate (:math:`CU1(\lambda)^{\dagger} = CU1(-\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:`.CU1Gate` with inverse parameter
        values.

Returns:
    CU1Gate: inverse gate.
r   )r)   )r-   r#   r)   r5   s     r   r6   CU1Gate.inverse(  s     A4??CCr   c           	        USL a  [        S5      e[        S[        U R                  S   5      -  5      nU R                  (       a#  [
        R                  " / SQ/ SQ/ SQSSSU//US9$ [
        R                  " / SQ/ SQSSUS// S	Q/US9$ )
z&Return a numpy.array for the CU1 gate.Fr9   r:   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   r;   )r   r   r   r   )r=   r   r>   r#   r)   r?   r@   )r   r<   rA   eiths       r   rC   CU1Gate.__array__7  s    5=XYY2dkk!n--.??;;|\Aq!T?KSX  ;;|aD!_lKSX r   c                    [        U[        5      =(       a1    U R                  UR                  :H  =(       a    U R                  U5      $ rF   )rG   r-   r)   rH   rI   s     r   rK   CU1Gate.__eq__E  s;    ug& 05#3#330((/	
r   rM   rV   )r   r   r   rN   r)   rR   rO   rP   rT   rU   )rW   rX   rY   rZ   r[   r	   rk   r\   r   r&   r0   r6   rC   rK   r]   r^   r_   s   @r   r-   r-      s    2h "%%N
 !'+	
 
!
 
 %	
 
&
"  ! '+  %	
  @D
 
r   r-   c                     ^  \ rS rSrSr  SSS.       SU 4S jjjjrS r    S       SU 4S jjjrSSS jjrS	 r	S
r
U =r$ )r/   iM  uF  Multi-controlled-U1 gate.

This is a diagonal and symmetric gate that induces a
phase on the state of the target qubit, depending on the state of the control qubits.

.. warning::

   This gate is deprecated. Instead, the following replacements should be used

   .. math::

       MCU1(\lambda) = MCP(\lambda)

   .. code-block:: python

      circuit = QuantumCircuit(5)
      circuit.mcp(lambda, list(range(4)), 4)




Circuit symbol:

.. code-block:: text

        q_0: ────■────
                 │
                 .
                 │
    q_(n-1): ────■────
             ┌───┴───┐
        q_n: ┤ U1(λ) ├
             └───────┘

.. seealso::

    :class:`~qiskit.circuit.library.standard_gates.CU1Gate`:
    The singly-controlled-version of this gate.
Nrb   c               B   > [         TU ]  SUS-   U/UUU[        XS9S9  g)zCreate new MCU1 gate.mcu1r   r   rg   Nrh   )r   rB   r+   r   r)   rc   r   s         r   r   MCU1Gate.__init__v  s8     	aE+!S4 	 	
r   c                <   U R                   S:X  a#  [        U R                  S   5      R                  nOcU R                   S:X  a#  [	        U R                  S   5      R                  nO0SSKJn  U" U R                  S   U R                   5      R                  nXl        g )Nr   r   )MCPhaseGate)r+   r   r#   r$   r-   pr|   )r   r$   r|   s      r   r&   MCU1Gate._define  sv    1$A/::J!!Q& Q0;;J&$T[[^T5I5IJUUJ$r   c                   > U(       d_  [        X15      nU R                  U-  U-  n[        U R                  S   XR                  -   UUS9nU R
                  UR                  l        U$ [        TU ]!  UUUUS9nU$ )rn   r   )r+   r   r)   r*   )	r   r)   r/   r#   r+   r   r.   r   r0   )r   r+   r   r)   r,   new_ctrl_stater2   r   s          r   r0   MCU1Gate.control  s    ( +JHJ"oo@JNNA /2F2F F)	D $(::DNN   7? /%#	 # D r   c                \    [        U R                  S   * U R                  U R                  S9$ )a  Return inverted MCU1 gate (:math:`MCU1(\lambda)^{\dagger} = MCU1(-\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:`.MCU1Gate` with inverse
        parameter values.

Returns:
    MCU1Gate: inverse gate.
r   )r+   r)   )r/   r#   r+   r)   r5   s     r   r6   MCU1Gate.inverse  s,     [[^OT-A-Adoo
 	
r   c                    [        U[        5      =(       aQ    U R                  UR                  :H  =(       a1    U R                  UR                  :H  =(       a    U R	                  U5      $ rF   )rG   r/   r+   r)   rH   rI   s     r   rK   MCU1Gate.__eq__  sV    uh' 0$$(=(==05#3#330 ((/		
r   rM   rV   )rB   r   r+   rQ   r   rN   r)   rR   rO   rP   rT   rU   )rW   rX   rY   rZ   r[   r   r&   r0   r6   rK   r]   r^   r_   s   @r   r/   r/   M  s    &X !'+
 

 
 	

 %
 
(%  ! '+%% % %	%
 % %N
"
 
r   r/   )r[   
__future__r   cmathr   r?   qiskit.circuit.controlledgater   qiskit.circuit.gater   "qiskit.circuit.parameterexpressionr   qiskit.circuit._utilsr   qiskit._accelerate.circuitr	   r   r-   r/    r   r   <module>r      sP     "   8 $ A 4 3TMT TMn[
n [
|H
~ H
r   