§
    ¹³Ùg'  ã                  óL  — d Z ddlmZ ddlmZ ddlmZm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 d	d
gd
d	ggZ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dS )zSqrt(X) and C-Sqrt(X) gates.é    )Úannotations)Úpi)ÚOptionalÚUnion)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)ÚQuantumRegister)Úwith_gate_arrayÚwith_controlled_gate_array)ÚStandardGatey      à?      à?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d„Z	 	 	 	 ddˆ fd„Zd„ Zˆ xZS )ÚSXGateua  The single-qubit Sqrt(X) gate (:math:`\sqrt{X}`).

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

    **Matrix Representation:**

    .. math::

        \sqrt{X} = \frac{1}{2} \begin{pmatrix}
                1 + i & 1 - i \\
                1 - i & 1 + i
            \end{pmatrix}

    **Circuit symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”€â”�
        q_0: â”¤ âˆšX â”œ
             â””â”€â”€â”€â”€â”˜

    .. note::

        A global phase difference exists between the definitions of
        :math:`RX(\pi/2)` and :math:`\sqrt{X}`.

        .. math::

            RX(\pi/2) = \frac{1}{\sqrt{2}} \begin{pmatrix}
                        1 & -i \\
                        -i & 1
                      \end{pmatrix}
                    = e^{-i \pi/4} \sqrt{X}

    NÚdt©ÚdurationÚunitÚlabelúOptional[str]c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new SX gate.Úsxé   ©r   r   r   N©ÚsuperÚ__init__©Úselfr   r   r   Ú	__class__s       €ú^/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/sx.pyr   zSXGate.__init__F   s.   ø€ å‰Œ×Ò˜˜q "¨E¸HÈ4ÐÑPÔPÐPÐPÐPó    c                óD  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        t          dz  ¬¦  «        } |¦   «         |d         gg f |¦   «         |d         gg f |¦   «         |d         gg fg}|D ]\  }}}	| 	                    |||	¦  «         Œ|| _
        d	S )
z<
        gate sx a { rz(-pi/2) a; h a; rz(-pi/2); }
        r   ©ÚQuantumCircuitr   )ÚSdgGate©ÚHGateÚqé   ©ÚnameÚglobal_phaseN)Úqiskit.circuit.quantumcircuitr$   Úsr%   Úhr'   r
   r+   r   Ú_appendÚ
definition)
r   r$   r%   r'   r(   ÚqcÚrulesÚ	operationÚqubitsÚclbitss
             r    Ú_definezSXGate._defineL   sç   € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤I½BÀ¹FÐCÑCÔCˆØ�'‘)”)˜a œd˜V RÐ(¨5¨5©7¬7°Q°q´T°F¸BÐ*?À'À'Á)Ä)ÈaÐPQÌdÈVÐUWÐAXÐYˆØ).ð 	2ð 	2Ñ%ˆI�v˜vØ�JŠJ�y &¨&Ñ1Ô1Ð1Ð1ØˆŒˆˆr!   FÚ	annotatedÚboolc                ó   — t          ¦   «         S )aÎ  Return inverse SX gate (i.e. SXdg).

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

        Returns:
            SXdgGate: inverse of :class:`.SXGate`.
        )ÚSXdgGate©r   r8   s     r    ÚinversezSXGate.inverse\   s   € õ ‰zŒzÐr!   r   Únum_ctrl_qubitsÚintú
str | NoneÚ
ctrl_stateústr | int | Noneúbool | Nonec                ó’   •— |s|dk    rt          ||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )ah  Return a (multi-)controlled-SX gate.

        One control returns a CSX 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 handled as ``False``.

        Returns:
            SingletonControlledGate: controlled version of this gate.
        r   )r   rA   Ú_base_label)r>   r   rA   r8   )ÚCSXGater   r   Úcontrol)r   r>   r   rA   r8   Úgater   s         €r    rG   zSXGate.controlj   s^   ø€ ð, ð 	˜_°Ò1Ð1Ý °:È4Ì:ÐVÑVÔVˆDˆDå‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr!   c                ó,   — t          |t          ¦  «        S ©N)Ú
isinstancer   ©r   Úothers     r    Ú__eq__zSXGate.__eq__‹   s   € Ý˜%¥Ñ(Ô(Ð(r!   rJ   ©r   r   ©F©r8   r9   )r   NNN)r>   r?   r   r@   rA   rB   r8   rC   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú_standard_gater   r	   Ú_singleton_lookup_keyr7   r=   rG   rN   Ú__classcell__©r   s   @r    r   r      sè   ø€ € € € € ð#ð #ðJ "Ô(€NðQÀÈ4ð Qð Qð Qð Qð Qð Qð Qð Qð 1Ð0Ñ2Ô2Ððð ð ð ð ð ð ð ð   !Ø Ø'+Ø!%ðð ð ð ð ð ð ðB)ð )ð )ð )ð )ð )ð )r!   r   c                  óf   ‡ — e Zd ZdZej        Zddddœdˆ fd„Z e¦   «         Z	d„ Z
ddd„Zd„ Zˆ xZS )r;   aÈ  The inverse single-qubit Sqrt(X) gate.

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

    .. math::

        \sqrt{X}^{\dagger} = \frac{1}{2} \begin{pmatrix}
                1 - i & 1 + i \\
                1 + i & 1 - i
            \end{pmatrix}


    .. note::

        A global phase difference exists between the definitions of
        :math:`RX(-\pi/2)` and :math:`\sqrt{X}^{\dagger}`.

        .. math::

            RX(-\pi/2) = \frac{1}{\sqrt{2}} \begin{pmatrix}
                        1 & i \\
                        i & 1
                      \end{pmatrix}
                    = e^{-i \pi/4} \sqrt{X}^{\dagger}
    Nr   r   r   r   c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new SXdg gate.Úsxdgr   r   Nr   r   s       €r    r   zSXdgGate.__init__®   s.   ø€ å‰Œ×Ò˜  B¨e¸hÈTÐÑRÔRÐRÐRÐRr!   c                óF  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        t           dz  ¬¦  «        } |¦   «         |d         gg f |¦   «         |d         gg f |¦   «         |d         gg fg}|D ]\  }}}	| 	                    |||	¦  «         Œ|| _
        d	S )
z<
        gate sxdg a { rz(pi/2) a; h a; rz(pi/2); }
        r   r#   r   )ÚSGater&   r(   r)   r*   N)r-   r$   r.   r^   r/   r'   r
   r+   r   r0   r1   )
r   r$   r^   r'   r(   r2   r3   r4   r5   r6   s
             r    r7   zSXdgGate._define´   sè   € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤I½R¸CÀ!¹GÐDÑDÔDˆØ�%‘'”'˜A˜aœD˜6 2Ð&¨¨©¬°1°Q´4°&¸"Ð(=ÀÀÁÄÈ!ÈAÌ$ÈÐQSÐ?TÐUˆØ).ð 	2ð 	2Ñ%ˆI�v˜vØ�JŠJ�y &¨&Ñ1Ô1Ð1Ð1ØˆŒˆˆr!   Fr8   r9   c                ó   — t          ¦   «         S )aË  Return inverse SXdg gate (i.e. SX).

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

        Returns:
            SXGate: inverse of :class:`.SXdgGate`
        )r   r<   s     r    r=   zSXdgGate.inverseÄ   s   € õ ‰xŒxˆr!   c                ó,   — t          |t          ¦  «        S rJ   )rK   r;   rL   s     r    rN   zSXdgGate.__eq__Ò   s   € Ý˜%¥Ñ*Ô*Ð*r!   rJ   rO   rP   rQ   )rR   rS   rT   rU   r   r;   rV   r   r	   rW   r7   r=   rN   rX   rY   s   @r    r;   r;   �   sµ   ø€ € € € € ðð ð6 "Ô*€NðSÀÈ4ð Sð Sð Sð Sð Sð Sð Sð Sð 1Ð0Ñ2Ô2Ððð ð ð ð ð ð ð ð+ð +ð +ð +ð +ð +ð +r!   r;   r   ©r>   c                  óf   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd	„Z ed
¬¦  «        Z	d„ Z
d„ Zˆ xZS )rF   uG  Controlled-âˆšX gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â”€â– â”€â”€
             â”Œâ”€â”´â”€â”€â”�
        q_1: â”¤ âˆšX â”œ
             â””â”€â”€â”€â”€â”˜

    **Matrix representation:**

    .. math::

        C\sqrt{X} \ q_0, q_1 =
        I \otimes |0 \rangle\langle 0| + \sqrt{X} \otimes |1 \rangle\langle 1|  =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & (1 + i) / 2 & 0 & (1 - i) / 2 \\
                0 & 0 & 1 & 0 \\
                0 & (1 - i) / 2 & 0 & (1 + i) / 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: â”¤ âˆšX â”œ
                 â””â”€â”¬â”€â”€â”˜
            q_1: â”€â”€â– â”€â”€

        .. math::

            C\sqrt{X}\ q_1, q_0 =
                |0 \rangle\langle 0| \otimes I + |1 \rangle\langle 1| \otimes \sqrt{X} =
                \begin{pmatrix}
                    1 & 0 & 0 & 0 \\
                    0 & 1 & 0 & 0 \\
                    0 & 0 & (1 + i) / 2 & (1 - i) / 2 \\
                    0 & 0 & (1 - i) / 2 & (1 + i) / 2
                \end{pmatrix}

    Nr   )r   r   rE   r   r   rA   úOptional[Union[str, int]]c               óx   •— t          ¦   «                              ddg d||t          |¬¦  «        ||¬¦	  «	         dS )zCreate new CSX gate.Úcsxé   r   )r   )r>   r   rA   Ú	base_gater   r   N)r   r   r   )r   r   rA   r   r   rE   r   s         €r    r   zCSXGate.__init__  sV   ø€ õ 	‰Œ×ÒØØØØØØ!Ý ;Ð/Ñ/Ô/ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r!   r   ra   c                óR  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        ¬¦  «        } |¦   «         |d         gg f |t          dz  ¦  «        |d         |d         gg f |¦   «         |d         gg fg}|D ]\  }}}	| 	                    |||	¦  «         Œ|| _
        d	S )
z;
        gate csx a,b { h b; cu1(pi/2) a,b; h b; }
        r   r#   r   r&   )ÚCU1Gaterf   r(   )r+   N)r-   r$   r/   r'   Úu1ri   r
   r+   r   r0   r1   )
r   r$   r'   ri   r(   r2   r3   r4   r5   r6   s
             r    r7   zCSXGate._define*  sð   € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�%‘'”'˜A˜aœD˜6 2Ð&¨¨µ°a±©¬¸1¸Q¼4ÀÀ1Ä¸,ÈÐ(KÈeÈeÉgÌgÐXYÐZ[ÔX\ÐW]Ð_aÐMbÐcˆØ).ð 	2ð 	2Ñ%ˆI�v˜vØ�JŠJ�y &¨&Ñ1Ô1Ð1Ð1ØˆŒˆˆr!   c                óL   — t          |t          ¦  «        o| j        |j        k    S rJ   )rK   rF   rA   rL   s     r    rN   zCSXGate.__eq__:  s!   € Ý˜%¥Ñ)Ô)ÐQ¨d¬oÀÔAQÒ.QÐQr!   )NN)r   r   rA   rc   )rR   rS   rT   rU   r   rF   rV   r   r	   rW   r7   rN   rX   rY   s   @r    rF   rF   Ö   s¯   ø€ € € € € ð6ð 6ðp "Ô)€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐðð ð ð Rð Rð Rð Rð Rð Rð Rr!   rF   N)rU   Ú
__future__r   Úmathr   Útypingr   r   Úqiskit.circuit.singletonr   r   r	   Úqiskit.circuit.quantumregisterr
   Úqiskit.circuit._utilsr   r   Úqiskit._accelerate.circuitr   Ú	_SX_ARRAYÚ_SXDG_ARRAYr   r;   rF   © r!   r    ú<module>rv      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ð ˜*Ð%¨
°JÐ'?Ð@€	Ø˜JÐ'¨*°jÐ)AÐB€ð €�ÑÔðn)ð n)ð n)ð n)ð n)ˆ]ñ n)ô n)ñ Ôðn)ðb €�ÑÔðC+ð C+ð C+ð C+ð C+ˆ}ñ C+ô C+ñ ÔðC+ðL Ð˜I°qÐ9Ñ9Ô9ðdRð dRð dRð dRð dRÐ%ñ dRô dRñ :Ô9ðdRð dRð dRr!   