§
    ¹³Ùg2  ã                  óÎ  — d Z ddlmZ ddlmZ ddlmZmZ ddlZddl	m
Z
mZmZ ddlmZ ddlmZmZ dd	lmZ  ej        d
dgddgg¦  «        Z ej        d
dgddgg¦  «        Z ee¦  «         G d„ de
¦  «        ¦   «         Z ee¦  «         G d„ de
¦  «        ¦   «         Z eed
¬¦  «         G d„ de¦  «        ¦   «         Z eed
¬¦  «         G d„ de¦  «        ¦   «         ZdS )zThe S, Sdg, CS and CSdg gates.é    )Úannotations)Úpi)ÚOptionalÚUnionN)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)ÚQuantumRegister)Úwith_gate_arrayÚwith_controlled_gate_array)ÚStandardGateé   y              ð?y       €      ð¿c                  ó†   ‡ — e Zd ZdZej        Zddddœdˆ fd„Z e¦   «         Z	d„ Z
	 	 	 	 ddˆ fd„Zddd„Zddd„Zd„ Zˆ xZS ) ÚSGateuŽ  Single qubit S gate (Z**0.5).

    It induces a :math:`\pi/2` phase, and is sometimes called the P gate (phase).

    This is a Clifford gate and a square-root of Pauli-Z.

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

    **Matrix Representation:**

    .. math::

        S = \begin{pmatrix}
                1 & 0 \\
                0 & i
            \end{pmatrix}

    **Circuit symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”�
        q_0: â”¤ S â”œ
             â””â”€â”€â”€â”˜

    Equivalent to a :math:`\pi/2` radian rotation about the Z axis.
    NÚdt©ÚdurationÚunitÚlabelúOptional[str]c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new S gate.Úsr   ©r   r   r   N©ÚsuperÚ__init__©Úselfr   r   r   Ú	__class__s       €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/s.pyr   zSGate.__init__A   s.   ø€ å‰Œ×Ò˜˜a ¨5¸8È$ÐÑOÔOÐOÐOÐOó    c                óì   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |t          dz  ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        dS )	z*
        gate s a { u1(pi/2) a; }
        r   ©ÚQuantumCircuitr   ©ÚU1GateÚq©Únameé   N©	Úqiskit.circuit.quantumcircuitr$   Úu1r&   r
   r)   r   Ú_appendÚ
definition©	r   r$   r&   r'   ÚqcÚrulesÚinstrÚqargsÚcargss	            r    Ú_definezSGate._defineG   s©   € ð
 	AÐ@Ð@Ð@Ð@Ð@àÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&�˜a™‘.”. 1 Q¤4 &¨"Ð-Ð.ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr!   r   Únum_ctrl_qubitsÚintú
str | NoneÚ
ctrl_stateúint | str | NoneÚ	annotatedúbool | Nonec                ó’   •— |s|dk    rt          ||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )al  Return a (multi-)controlled-S gate.

        One control qubit returns a :class:`.CSGate`.

        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 handled as ``False``.

        Returns:
            ControlledGate: controlled version of this gate.
        r   ©r   r:   Ú_base_label©r7   r   r:   r<   )ÚCSGater   r   Úcontrol©r   r7   r   r:   r<   Úgater   s         €r    rC   zSGate.controlX   s^   ø€ ð, ð 	˜_°Ò1Ð1Ý °*È$Ì*ÐUÑUÔUˆDˆDå‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr!   FÚboolc                ó   — t          ¦   «         S )aÅ  Return inverse of S (SdgGate).

        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:`.SdgGate`.

        Returns:
            SdgGate: inverse of :class:`.SGate`
        )ÚSdgGate©r   r<   s     r    ÚinversezSGate.inversey   s   € õ ‰yŒyÐr!   ÚexponentÚfloatc                óD   — ddl m}  |dt          j        z  |z  ¦  «        S )Nr   ©Ú	PhaseGateç      à?©ÚprO   Únumpyr   ©r   rK   r<   rO   s       r    ÚpowerzSGate.power‡   s/   € Ø Ð Ð Ð Ð Ð àˆy˜�uœx™¨(Ñ2Ñ3Ô3Ð3r!   c                ó,   — t          |t          ¦  «        S ©N)Ú
isinstancer   ©r   Úothers     r    Ú__eq__zSGate.__eq__Œ   s   € Ý˜%¥Ñ'Ô'Ð'r!   rW   ©r   r   ©r   NNN©r7   r8   r   r9   r:   r;   r<   r=   ©F©r<   rF   ©rK   rL   r<   rF   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú_standard_gater   r	   Ú_singleton_lookup_keyr6   rC   rJ   rU   r[   Ú__classcell__©r   s   @r    r   r       s   ø€ € € € € ðð ð: "Ô'€NðPÀÈ4ð Pð Pð Pð Pð Pð Pð Pð Pð 1Ð0Ñ2Ô2Ððð ð ð&  !Ø Ø'+Ø!%ðð ð ð ð ð ð ðBð ð ð ð ð4ð 4ð 4ð 4ð 4ð
(ð (ð (ð (ð (ð (ð (r!   r   c                  ó†   ‡ — e Zd ZdZej        Zddddœdˆ fd„Z e¦   «         Z	d„ Z
	 	 	 	 ddˆ fd„Zddd„Zddd„Zd„ Zˆ xZS ) rH   u€  Single qubit S-adjoint gate (~Z**0.5).

    It induces a :math:`-\pi/2` phase.

    This is a Clifford gate and a square-root of Pauli-Z.

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

    **Matrix Representation:**

    .. math::

        Sdg = \begin{pmatrix}
                1 & 0 \\
                0 & -i
            \end{pmatrix}

    **Circuit symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”€â”€â”�
        q_0: â”¤ Sdg â”œ
             â””â”€â”€â”€â”€â”€â”˜

    Equivalent to a :math:`-\pi/2` radian rotation about the Z axis.
    Nr   r   r   r   c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new Sdg gate.Úsdgr   r   Nr   r   s       €r    r   zSdgGate.__init__±   s.   ø€ å‰Œ×Ò˜  2¨U¸XÈDÐÑQÔQÐQÐQÐQr!   c                óî   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |t           dz  ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        dS )	z-
        gate sdg a { u1(-pi/2) a; }
        r   r#   r   r%   r'   r(   r*   Nr+   r0   s	            r    r6   zSdgGate._define·   s«   € ð
 	AÐ@Ð@Ð@Ð@Ð@àÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&�"˜˜q™‘/”/ A a¤D 6¨2Ð.Ð/ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr!   r   r7   r8   r9   r:   r;   r<   r=   c                ó’   •— |s|dk    rt          ||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )ap  Return a (multi-)controlled-Sdg gate.

        One control qubit returns a :class:`.CSdgGate`.

        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 handled as ``False``.

        Returns:
            ControlledGate: controlled version of this gate.
        r   r?   rA   )ÚCSdgGater   r   rC   rD   s         €r    rC   zSdgGate.controlÈ   s^   ø€ ð, ð 	˜_°Ò1Ð1Ý %°JÈDÌJÐWÑWÔWˆDˆDå‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr!   FrF   c                ó   — t          ¦   «         S )aÃ  Return inverse of Sdg (SGate).

        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:`.SGate`.

        Returns:
            SGate: inverse of :class:`.SdgGate`
        )r   rI   s     r    rJ   zSdgGate.inverseé   s   € õ ‰wŒwˆr!   rK   rL   c                óD   — ddl m}  |dt          j        z  |z  ¦  «        S )Nr   rN   ç      à¿rQ   rT   s       r    rU   zSdgGate.power÷   s/   € Ø Ð Ð Ð Ð Ð àˆy˜¥¤™¨8Ñ3Ñ4Ô4Ð4r!   c                ó,   — t          |t          ¦  «        S rW   )rX   rH   rY   s     r    r[   zSdgGate.__eq__ü   s   € Ý˜%¥Ñ)Ô)Ð)r!   rW   r\   r]   r^   r_   r`   ra   )rb   rc   rd   re   r   rH   rf   r   r	   rg   r6   rC   rJ   rU   r[   rh   ri   s   @r    rH   rH   �   s   ø€ € € € € ðð ð: "Ô)€NðRÀÈ4ð Rð Rð Rð Rð Rð Rð Rð Rð 1Ð0Ñ2Ô2Ððð ð ð&  !Ø Ø'+Ø!%ðð ð ð ð ð ð ðBð ð ð ð ð5ð 5ð 5ð 5ð 5ð
*ð *ð *ð *ð *ð *ð *r!   rH   ©r7   c                  óz   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd	„Z ed
¬¦  «        Z	d„ Z
ddd„Zddd„Zd„ Zˆ xZS )rB   uƒ  Controlled-S gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â”€â– â”€â”€
             â”Œâ”€â”´â”€â”�
        q_1: â”¤ S â”œ
             â””â”€â”€â”€â”˜

    **Matrix representation:**

    .. math::

        CS \ q_0, q_1 =
        I \otimes |0 \rangle\langle 0| + S \otimes |1 \rangle\langle 1|  =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 \\
                0 & 0 & 1 & 0 \\
                0 & 0 & 0 & i
            \end{pmatrix}
    Nr   ©r   r   r@   r   r   r:   úOptional[Union[str, int]]c               óz   •— t          ¦   «                              ddg |d|t          |¬¦  «        |||¬¦
  «
         dS )zCreate new CS gate.Úcsr*   r   ©r   )r   r7   r:   Ú	base_gater   r@   r   N)r   r   r   ©r   r   r:   r   r   r@   r   s         €r    r   zCSGate.__init__   sY   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØ#Øð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r!   r   rt   c                óN   — ddl m}  |t          dz  ¬¦  «        j        | _        dS )z9
        gate cs a,b { h b; cp(pi/2) a,b; h b; }
        r   ©Ú
CPhaseGater*   ©ÚthetaN©rR   r   r   r/   ©r   r   s     r    r6   zCSGate._define9  s5   € ð 	"Ð!Ð!Ð!Ð!Ð!à$˜*­2°©6Ð2Ñ2Ô2Ô=ˆŒˆˆr!   Fr<   rF   c                ó,   — t          | j        ¬¦  «        S )aÎ  Return inverse of CSGate (CSdgGate).

        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:`.CSdgGate`.

        Returns:
            CSdgGate: inverse of :class:`.CSGate`
        ©r:   )ro   r:   rI   s     r    rJ   zCSGate.inverseA  s   € õ  4¤?Ð3Ñ3Ô3Ð3r!   rK   rL   c                óD   — ddl m}  |dt          j        z  |z  ¦  «        S )Nr   r~   rP   ©rR   r   rS   r   ©r   rK   r<   r   s       r    rU   zCSGate.powerO  s/   € Ø!Ð!Ð!Ð!Ð!Ð!àˆz˜#¥¤™.¨8Ñ3Ñ4Ô4Ð4r!   c                óL   — t          |t          ¦  «        o| j        |j        k    S rW   )rX   rB   r:   rY   s     r    r[   zCSGate.__eq__T  s!   € Ý˜%¥Ñ(Ô(ÐP¨T¬_ÀÔ@PÒ-PÐPr!   ©NN©r   r   r:   rw   r_   r`   ra   )rb   rc   rd   re   r   rB   rf   r   r	   rg   r6   rJ   rU   r[   rh   ri   s   @r    rB   rB      sà   ø€ € € € € ðð ð8 "Ô(€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð. 1Ð0ÀÐCÑCÔCÐð>ð >ð >ð4ð 4ð 4ð 4ð 4ð5ð 5ð 5ð 5ð 5ð
Qð Qð Qð Qð Qð Qð Qr!   rB   c                  óz   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd	„Z ed
¬¦  «        Z	d„ Z
ddd„Zddd„Zd„ Zˆ xZS )ro   u²  Controlled-S^\dagger gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â”€â”€â– â”€â”€â”€
             â”Œâ”€â”€â”´â”€â”€â”�
        q_1: â”¤ Sdg â”œ
             â””â”€â”€â”€â”€â”€â”˜

    **Matrix representation:**

    .. math::

        CS^\dagger \ q_0, q_1 =
        I \otimes |0 \rangle\langle 0| + S^\dagger \otimes |1 \rangle\langle 1|  =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 \\
                0 & 0 & 1 & 0 \\
                0 & 0 & 0 & -i
            \end{pmatrix}
    Nr   rv   r   r   r:   rw   c               óx   •— t          ¦   «                              ddg |d|t          |¬¦  «        ||¬¦	  «	         dS )zCreate new CSdg gate.Úcsdgr*   r   rz   )r   r7   r:   r{   r   r   N)r   r   rH   r|   s         €r    r   zCSdgGate.__init__x  sV   ø€ õ 	‰Œ×ÒØØØØØØ!Ý KÐ0Ñ0Ô0ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r!   r   rt   c                óP   — ddl m}  |t           dz  ¬¦  «        j        | _        dS )z<
        gate csdg a,b { h b; cp(-pi/2) a,b; h b; }
        r   r~   r*   r€   Nr‚   rƒ   s     r    r6   zCSdgGate._define�  s7   € ð 	"Ð!Ð!Ð!Ð!Ð!à$˜*­B¨3°©7Ð3Ñ3Ô3Ô>ˆŒˆˆr!   Fr<   rF   c                ó,   — t          | j        ¬¦  «        S )aÌ  Return inverse of CSdgGate (CSGate).

        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:`.CSGate`.

        Returns:
            CSGate: inverse of :class:`.CSdgGate`
        r…   )rB   r:   rI   s     r    rJ   zCSdgGate.inverse˜  s   € õ  ¤Ð1Ñ1Ô1Ð1r!   rK   rL   c                óD   — ddl m}  |dt          j        z  |z  ¦  «        S )Nr   r~   rr   r‡   rˆ   s       r    rU   zCSdgGate.power¦  s/   € Ø!Ð!Ð!Ð!Ð!Ð!àˆz˜$¥¤™/¨HÑ4Ñ5Ô5Ð5r!   c                óL   — t          |t          ¦  «        o| j        |j        k    S rW   )rX   ro   r:   rY   s     r    r[   zCSdgGate.__eq__«  s!   € Ý˜%¥Ñ*Ô*ÐR¨t¬À%ÔBRÒ/RÐRr!   rŠ   r‹   r_   r`   ra   )rb   rc   rd   re   r   ro   rf   r   r	   rg   r6   rJ   rU   r[   rh   ri   s   @r    ro   ro   X  sà   ø€ € € € € ðð ð8 "Ô*€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐð?ð ?ð ?ð2ð 2ð 2ð 2ð 2ð6ð 6ð 6ð 6ð 6ð
Sð Sð Sð Sð Sð Sð Sr!   ro   )re   Ú
__future__r   Úmathr   Útypingr   r   rS   Úqiskit.circuit.singletonr   r   r	   Úqiskit.circuit.quantumregisterr
   Úqiskit.circuit._utilsr   r   Úqiskit._accelerate.circuitr   ÚarrayÚ_S_ARRAYÚ
_SDG_ARRAYr   rH   rB   ro   © r!   r    ú<module>rž      s=  ðð %Ð $à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "à €€€à aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ :Ð :Ð :Ð :Ð :Ð :Ø MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ 3Ð 3Ð 3Ð 3Ð 3Ð 3ð ˆ5Œ;˜˜A˜  B Ð(Ñ)Ô)€ØˆUŒ[˜1˜a˜& 1 c (Ð+Ñ,Ô,€
ð €�ÑÔðl(ð l(ð l(ð l(ð l(ˆMñ l(ô l(ñ Ôðl(ð^ €�ÑÔðl*ð l*ð l*ð l*ð l*ˆmñ l*ô l*ñ Ôðl*ð^ Ð˜H°aÐ8Ñ8Ô8ðTQð TQð TQð TQð TQÐ$ñ TQô TQñ 9Ô8ðTQðn Ð˜J¸Ð:Ñ:Ô:ðSSð SSð SSð SSð SSÐ&ñ SSô SSñ ;Ô:ðSSð SSð SSr!   