§
    ¹³Ùg’>  ã                  óÆ   — d Z ddlmZ ddlmZ ddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ dd
lmZ  G d„ de	¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )zU1 Gate.é    )Úannotations)ÚexpN)ÚControlledGate)ÚGate)ÚParameterValueType)ÚQuantumRegister)Ú_ctrl_state_to_int)ÚStandardGatec                  ór   ‡ — e Zd ZdZej        Z	 ddddœdˆ fd	„Zd
„ Z	 	 	 	 ddˆ fd„Z	ddd„Z
dd„Zd„ Zˆ xZS )ÚU1Gateuæ  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>`_
    NÚdt)ÚdurationÚunitÚthetar   Úlabelú
str | Nonec               óX   •— t          ¦   «                              dd|g|||¬¦  «         dS )zCreate new U1 gate.Úu1é   )r   r   r   N)ÚsuperÚ__init__)Úselfr   r   r   r   Ú	__class__s        €ú^/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/u1.pyr   zU1Gate.__init__b   s3   ø€ õ 	‰Œ×Ò˜˜q 5 '°ÀÐPTÐÑUÔUÐUÐUÐUó    c                óö   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |dd| j        d         ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        d S )Nr   ©ÚQuantumCircuitr   )ÚU3GateÚq©Úname)	Úqiskit.circuit.quantumcircuitr   Úu3r   r   r"   ÚparamsÚ_appendÚ
definition)	r   r   r   r    ÚqcÚrulesÚinstrÚqargsÚcargss	            r   Ú_definezU1Gate._defineh   s®   € à@Ð@Ð@Ð@Ð@Ð@ØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&˜˜A˜tœ{¨1œ~Ñ.Ô.°°1´°¸Ð;Ð<ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   r   FÚnum_ctrl_qubitsÚintÚ
ctrl_stateústr | int | NoneÚ	annotatedÚboolc                ó2  •— |s5|dk    r/t          | j        d         ||¬¦  «        }| j        |j        _        n^|s7|€5|dk    r/t	          | j        d         ||¬¦  «        }| j        |j        _        n%t          ¦   «                              ||||¬¦  «        }|S )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   r0   N©r   ©r.   r   r0   r2   )ÚCU1Gater%   r   Ú	base_gateÚMCU1Gater   Úcontrol©r   r.   r   r0   r2   Úgater   s         €r   r:   zU1Gate.controlu   s¯   ø€ ð( ð 	˜_°Ò1Ð1Ý˜4œ; qœ>°À:ÐNÑNÔNˆDØ#'¤:ˆDŒNÔ Ð Øð 		˜zÐ1°oÈÒ6IÐ6IÝ˜DœK¨œN¨OÀ5ÐIÑIÔIˆDØ#'¤:ˆDŒNÔ Ð å‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr   c                ó8   — t          | j        d          ¦  «        S )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   r2   s     r   ÚinversezU1Gate.inverse˜   s   € õ �t”{ 1”~�oÑ&Ô&Ð&r   c                ó¾   — |du rt          d¦  «        ‚t          | j        d         ¦  «        }t          j        ddgdt          j        d|z  ¦  «        gg|¬¦  «        S )z%Return a numpy.array for the U1 gate.Fú9unable to avoid copy while creating an array as requestedr   r   ù              ð?©Údtype)Ú
ValueErrorÚfloatr%   ÚnumpyÚarrayr   )r   rD   ÚcopyÚlams       r   Ú	__array__zU1Gate.__array__¦   s^   € à�5ˆ=ˆ=ÝÐXÑYÔYÐYÝ�D”K ”NÑ#Ô#ˆÝŒ{˜Q ˜F Q­¬	°"°s±(Ñ(;Ô(;Ð$<Ð=ÀUÐKÑKÔKÐKr   c                óV   — t          |t          ¦  «        o|                      |¦  «        S ©N)Ú
isinstancer   Ú_compare_parameters©r   Úothers     r   Ú__eq__zU1Gate.__eq__­   s%   € Ý˜%¥Ñ(Ô(ÐL¨T×-EÒ-EÀeÑ-LÔ-LÐLr   rM   )r   r   r   r   ©r   NNF©r.   r/   r   r   r0   r1   r2   r3   ©F©r2   r3   ©NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Ú_standard_gater   r-   r:   r?   rK   rR   Ú__classcell__©r   s   @r   r   r      s   ø€ € € € € ðDð DðL "Ô(€Nð >BðVØOSÐZ^ðVð Vð Vð Vð Vð Vð Vð Vðð ð ð  !Ø Ø'+Øð!ð !ð !ð !ð !ð !ð !ðF'ð 'ð 'ð 'ð 'ðLð Lð Lð LðMð Mð Mð Mð Mð Mð Mr   r   c                  óv   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd„Zd„ Z	 	 	 	 ddˆ fd„Z	ddd„Z
dd„Zd„ Zˆ xZS )r7   ur  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.
    Nr   ©r   r   Ú_base_labelr   r   r   r   r0   r1   c               ó|   •— t          ¦   «                              dd|gd||t          ||¬¦  «        ||¬¦	  «	         dS )zCreate new CU1 gate.Úcu1é   r   r5   ©r.   r   r0   r8   r   r   N©r   r   r   )r   r   r   r0   r   r   ra   r   s          €r   r   zCU1Gate.__init__è   sZ   ø€ õ 	‰Œ×ÒØØØˆGØØØ!Ý˜U¨+Ð6Ñ6Ô6ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r   c                ó  — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        }t          | j        d         dz  ¦  «        |d         gg f |¦   «         |d         |d         gg ft          | j        d          dz  ¦  «        |d         gg f |¦   «         |d         |d         gg ft          | j        d         dz  ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _	        dS )	z�
        gate cu1(lambda) a,b
        { u1(lambda/2) a; cx a,b;
          u1(-lambda/2) b; cx a,b;
          u1(lambda/2) b;
        }
        r   r   r   )ÚCXGaterd   r    r!   N)
r#   r   Úxrh   r   r"   r   r%   r&   r'   )	r   r   rh   r    r(   r)   r*   r+   r,   s	            r   r-   zCU1Gate._defineÿ   s6  € ð 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐõ ˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆå�D”K ”N QÑ&Ñ'Ô'¨!¨A¬$¨°Ð4ØˆV‰XŒX˜˜!œ˜a œd�| RÐ(Ý�T”[ ”^�O aÑ'Ñ(Ô(¨1¨Q¬4¨&°"Ð5ØˆV‰XŒX˜˜!œ˜a œd�| RÐ(Ý�D”K ”N QÑ&Ñ'Ô'¨!¨A¬$¨°Ð4ð
ˆð $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   r   Fr.   r/   r2   r3   c                ó¾   •— |s4|€2t          | j        d         |dz   |¬¦  «        }| j        |j        _        n%t	          ¦   «                              ||||¬¦  «        }|S )á  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.
        Nr   r   )r.   r   r6   )r9   r%   r   r8   r   r:   r;   s         €r   r:   zCU1Gate.control  sp   ø€ ð( ð 		˜ZÐ/Ý˜DœK¨œN¸OÈaÑ<OÐW\Ð]Ñ]Ô]ˆDØ#'¤:ˆDŒNÔ Ð å‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr   c                óF   — t          | j        d          | j        ¬¦  «        S )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   )r0   )r7   r%   r0   r>   s     r   r?   zCU1Gate.inverse>  s!   € õ ˜œ Aœ�°4´?ÐCÑCÔCÐCr   c           	     ó  — |du rt          d¦  «        ‚t          dt          | j        d         ¦  «        z  ¦  «        }| j        r$t          j        g d¢g d¢g d¢ddd|gg|¬¦  «        S t          j        g d¢g d¢dd|dgg d	¢g|¬¦  «        S )
z&Return a numpy.array for the CU1 gate.FrA   rB   r   )r   r   r   r   )r   r   r   r   )r   r   r   r   rC   )r   r   r   r   )rE   r   rF   r%   r0   rG   rH   )r   rD   rI   Úeiths       r   rK   zCU1Gate.__array__M  s¾   € à�5ˆ=ˆ=ÝÐXÑYÔYÐYÝ�2�˜dœk¨!œnÑ-Ô-Ñ-Ñ.Ô.ˆØŒ?ð 	Ý”;Ø��˜|˜|˜|¨\¨\¨\¸A¸qÀ!ÀT¸?ÐKÐSXðñ ô ð õ ”;Ø��˜|˜|˜|¨a°°D¸!¨_¸l¸l¸lÐKÐSXðñ ô ð r   c                óv   — t          |t          ¦  «        o$| j        |j        k    o|                      |¦  «        S rM   )rN   r7   r0   rO   rP   s     r   rR   zCU1Gate.__eq__[  s<   € å�u�gÑ&Ô&ð 0Ø” 5Ô#3Ò3ð0à×(Ò(¨Ñ/Ô/ð	
r   rW   )r   r   r   r   r0   r1   rS   rT   rU   rV   )rX   rY   rZ   r[   r
   r7   r\   r   r-   r:   r?   rK   rR   r]   r^   s   @r   r7   r7   ±   s÷   ø€ € € € € ð2ð 2ðh "Ô)€Nð
 !Ø'+ð	
ð ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð.ð ð ðB  !Ø Ø'+Øðð ð ð ð ð ð ð@Dð Dð Dð Dð Dðð ð ð ð
ð 
ð 
ð 
ð 
ð 
ð 
r   r7   c                  ó`   ‡ — e Zd ZdZ	 	 dddddœdˆ fd„Zd„ Z	 	 	 	 ddˆ fd„Zddd„Zd„ Zˆ xZ	S )r9   u¦  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.
    Nr   r`   rJ   r   r.   r/   r   r   r0   r1   c               ó‚   •— t          ¦   «                              d|dz   |g|||t          ||¬¦  «        ||¬¦	  «	         dS )zCreate new MCU1 gate.Úmcu1r   r5   re   Nrf   )	r   rJ   r.   r   r0   r   r   ra   r   s	           €r   r   zMCU1Gate.__init__Œ  s_   ø€ õ 	‰Œ×ÒØØ˜aÑØˆEØ+ØØ!Ý˜S¨Ð4Ñ4Ô4ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r   c                óÜ  — ddl m} t          | j        d¦  «        } ||| j        ¬¦  «        }| j        dk    rt          | j        d         ¦  «        j        }| j        dk    r t          | j        d         ¦  «        j        }nBddl
m} | j        d         d| j        dz
  z  z  }t          |¦  «        } ||| j        |¦  «        }|D ]\  }}	}
|                     ||	|
¦  «         Œ|| _        d S )Nr   r   r    r!   r   )Ú_gray_code_chainrd   )r#   r   r   Ú
num_qubitsr"   r.   r   r%   r'   r7   r$   rt   r&   )r   r   r    r(   r'   rt   Ú
scaled_lamÚbottom_gater*   r+   r,   s              r   r-   zMCU1Gate._define¤  s  € à@Ð@Ð@Ð@Ð@Ð@å˜DœO¨SÑ1Ô1ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàÔ 1Ò$Ð$Ý ¤¨A¤Ñ/Ô/Ô:ˆJØÔ 1Ò$Ð$Ý  ¤¨Q¤Ñ0Ô0Ô;ˆJˆJà,Ð,Ð,Ð,Ð,Ð,àœ Qœ¨1°Ô1EÈÑ1IÑ+JÑKˆJÝ! *Ñ-Ô-ˆKØ)Ð)¨!¨TÔ-AÀ;ÑOÔOˆJØ#-ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+ØˆŒˆˆr   r   Fr2   r3   c                ó   •— |sUt          ||¦  «        }| j        |z  |z  }t          | j        d         || j        z   ||¬¦  «        }| j        |j        _        n%t          ¦   «                              ||||¬¦  «        }|S )rk   r   )r.   r   r0   r6   )	r	   r0   r9   r%   r.   r   r8   r   r:   )r   r.   r   r0   r2   Únew_ctrl_stater<   r   s          €r   r:   zMCU1Gate.control¹  s›   ø€ ð( ð 	Ý+¨J¸ÑHÔHˆJØ"œo°Ñ@ÀJÑNˆNÝØ”˜A”Ø /°$Ô2FÑ FØØ)ð	ñ ô ˆDð $(¤:ˆDŒNÔ Ð å‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr   c                óD   — t          | j        d          | j        ¦  «        S )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   )r9   r%   r.   r>   s     r   r?   zMCU1Gate.inverseà  s   € õ ˜œ Qœ˜¨Ô)=Ñ>Ô>Ð>r   c                ó–   — t          |t          ¦  «        o4| j        |j        k    o$| j        |j        k    o|                      |¦  «        S rM   )rN   r9   r.   r0   rO   rP   s     r   rR   zMCU1Gate.__eq__ï  sQ   € å�u�hÑ'Ô'ð 0ØÔ$¨Ô(=Ò=ð0à” 5Ô#3Ò3ð0ð ×(Ò(¨Ñ/Ô/ð		
r   rW   )rJ   r   r.   r/   r   r   r0   r1   rS   rT   rU   rV   )
rX   rY   rZ   r[   r   r-   r:   r?   rR   r]   r^   s   @r   r9   r9   c  sÓ   ø€ € € € € ð&ð &ðX !Ø'+ð
ð ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð0ð ð ð.  !Ø Ø'+Øð%ð %ð %ð %ð %ð %ð %ðN?ð ?ð ?ð ?ð ?ð
ð 
ð 
ð 
ð 
ð 
ð 
r   r9   )r[   Ú
__future__r   Úcmathr   rG   Úqiskit.circuit.controlledgater   Úqiskit.circuit.gater   Ú"qiskit.circuit.parameterexpressionr   Úqiskit.circuit.quantumregisterr   Úqiskit.circuit._utilsr	   Úqiskit._accelerate.circuitr
   r   r7   r9   © r   r   ú<module>r…      sQ  ðð €Ø "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð Ø €€€Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø $Ð $Ð $Ð $Ð $Ð $Ø AÐ AÐ AÐ AÐ AÐ AØ :Ð :Ð :Ð :Ð :Ð :Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ðUMð UMð UMð UMð UMˆTñ UMô UMð UMðpo
ð o
ð o
ð o
ð o
ˆnñ o
ô o
ð o
ðdR
ð R
ð R
ð R
ð R
ˆ~ñ R
ô R
ð R
ð R
ð R
r   