
    z	iS%                        S r SSKJr  SSKJrJr  SSKJrJrJ	r	  SSK
JrJr  SSKJr  SS/SS//rSS/SS//r\" \5       " S	 S
\5      5       r\" \5       " S S\5      5       r\" \SS9 " S S\5      5       rg)zSqrt(X) and C-Sqrt(X) gates.    )annotations)OptionalUnion)SingletonGateSingletonControlledGatestdlib_singleton_key)with_gate_arraywith_controlled_gate_array)StandardGatey      ?      ?y      ?      c                     ^  \ rS rSrSr\R                  rS	S
U 4S jjjr\	" 5       r
S rSSS jjr    S       SU 4S jjjrS rSrU =r$ )SXGate   u  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}

c                &   > [         TU ]  SS/ US9  g)z2
Args:
    label: An optional label for the gate.
sx   labelNsuper__init__selfr   	__class__s     b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/sx.pyr   SXGate.__init__D   s    
 	q"E2    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   SX_get_definitionparamsr!   
definitionr   r   s     r   _defineSXGate._defineM   sA     	2 );;OO++DKK8SWS\S\ < 
r   c                    [        5       $ )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   	annotateds     r   inverseSXGate.inverse[   s     zr   c                n   > U(       d  US:X  a  [        X#U R                  S9nU$ [        TU ]  UUUUS9nU$ )a  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   
ctrl_state_base_label)num_ctrl_qubitsr   r2   r.   )CSXGater   r   control)r   r4   r   r2   r.   gater   s         r   r6   SXGate.controli   sN    , _14::VD  7? /%#	 # D r   c                "    [        U[        5      $ N)
isinstancer   r   others     r   __eq__SXGate.__eq__   s    %((r   r'   r:   r   Optional[str]Fr.   bool)r   NNN)r4   intr   z
str | Noner2   zstr | int | Noner.   zbool | None)__name__
__module____qualname____firstlineno____doc__r   r$   _standard_gater   r   _singleton_lookup_keyr)   r/   r6   r>   __static_attributes____classcell__r   s   @r   r   r      s|    #J "__N3 3 12
   ! '+!%  %	
  B) )r   r   c                  t   ^  \ rS rSrSr\R                  rSS	U 4S jjjr\	" 5       r
S rS
SS jjrS rSrU =r$ )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}
c                &   > [         TU ]  SS/ US9  g)zCreate new SXdg gate.sxdgr   r   Nr   r   s     r   r   SXdgGate.__init__   s    Be4r   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   SXdgr%   r&   r!   r'   r(   s     r   r)   SXdgGate._define   sC     	2 );;--dkk:$UYU^U^ < 
r   c                    [        5       $ )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/   SXdgGate.inverse   s     xr   c                "    [        U[        5      $ r:   )r;   r,   r<   s     r   r>   SXdgGate.__eq__   s    %**r   r@   r:   rA   rC   rD   )rG   rH   rI   rJ   rK   r   rW   rL   r   r   rM   r)   r/   r>   rN   rO   rP   s   @r   r,   r,      s>    6 "&&N5 5 12
+ +r   r,   r   r4   c                  v   ^  \ rS rSrSr\R                  r  SSS.   SU 4S jjjjr\	" SS9r
S rS	 rS
rU =r$ )r5      u  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}

N)r3   c               :   > [         TU ]  SS/ SUU[        US9S9  g)zCreate new CSX gate.csx   r   r   )r4   r   r2   	base_gateN)r   r   r   )r   r   r2   r3   r   s       r   r   CSXGate.__init__  s1     	!;/ 	 	
r   r   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   CSXr%   r&   r!   r'   r(   s     r   r)   CSXGate._define#  sC     	2 );;,,T[[9TXT]T] < 
r   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ r:   )r;   r5   r2   r<   s     r   r>   CSXGate.__eq__1  s#    %)QdooAQAQ.QQr   r@   )NN)r   rB   r2   zOptional[Union[str, int]])rG   rH   rI   rJ   rK   r   rf   rL   r   r   rM   r)   r>   rN   rO   rP   s   @r   r5   r5      sb    6p "%%N  $04

 

 .
 
$ 1C
R Rr   r5   N)rK   
__future__r   typingr   r   qiskit.circuit.singletonr   r   r   qiskit.circuit._utilsr	   r
   qiskit._accelerate.circuitr   	_SX_ARRAY_SXDG_ARRAYr   r,   r5    r   r   <module>rr      s    # " " a a M 3 *%
J'?@	J'*j)AB o)] o) o)d A+} A+ A+H Iq9^R% ^R :^Rr   