
    z	iH4                    h   S r SSKJr  SSKJrJr  SSKrSSKJrJ	r	J
r
  SSKJrJr  SSKJr  \R                   " SS/SS	//5      r\R                   " SS/SS
//5      r\" \5       " S S\5      5       r\" \5       " S S\5      5       r\" \SS9 " S S\	5      5       r\" \SS9 " S S\	5      5       rg)zThe S, Sdg, CS and CSdg gates.    )annotations)OptionalUnionN)SingletonGateSingletonControlledGatestdlib_singleton_key)with_gate_arraywith_controlled_gate_array)StandardGate   y              ?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U 4S jjjrSSS jjrSSS jjrS rS	rU =r$ )SGate   uB  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.
c                &   > [         TU ]  SS/ US9  g)z2
Args:
    label: An optional label for the gate.
sr   labelNsuper__init__selfr   	__class__s     a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/s.pyr   SGate.__init__?   s    
 	a51    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   S_get_definitionparamsr!   
definitionr   r   s     r   _defineSGate._defineH   sA     	2 );;NN**4;;7tRVR[R[ < 
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-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   
ctrl_state_base_labelnum_ctrl_qubitsr   r-   	annotated)CSGater   r   controlr   r0   r   r-   r1   gater   s         r   r3   SGate.controlU   sN    , _1$**UD  7? /%#	 # D r   c                    [        5       $ )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   r1   s     r   inverseSGate.inversev   s     yr   c                F    SSK Jn  U" S[        R                  -  U-  5      $ )Nr   	PhaseGate      ?pr>   numpypir   exponentr1   r>   s       r   powerSGate.power   s     uxx(233r   c                "    [        U[        5      $ N)
isinstancer   r   others     r   __eq__SGate.__eq__   s    %''r   r'   rI   r   Optional[str]r   NNNr0   intr   z
str | Noner-   zint | str | Noner1   zbool | NoneFr1   boolrE   floatr1   rW   )__name__
__module____qualname____firstlineno____doc__r   r$   _standard_gater   r   _singleton_lookup_keyr)   r3   r:   rF   rM   __static_attributes____classcell__r   s   @r   r   r      s    : "^^N2 2 12
  ! '+!%  %	
  B4
( (r   r   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U 4S jjjrSSS jjrSSS jjrS rS	rU =r$ )r8      u4  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.
c                &   > [         TU ]  SS/ US9  g)zCreate new Sdg gate.sdgr   r   Nr   r   s     r   r   SdgGate.__init__   s    2U3r   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   Sdgr%   r&   r!   r'   r(   s     r   r)   SdgGate._define   sC     	2 );;,,T[[9TXT]T] < 
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-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,   r/   )CSdgGater   r   r3   r4   s         r   r3   SdgGate.control   sN    , _1%DJJWD  7? /%#	 # D r   c                    [        5       $ )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   r9   s     r   r:   SdgGate.inverse   s     wr   c                F    SSK Jn  U" S[        R                  -  U-  5      $ )Nr   r=         r@   rD   s       r   rF   SdgGate.power   s     8344r   c                "    [        U[        5      $ rI   )rJ   r8   rK   s     r   rM   SdgGate.__eq__   s    %))r   rO   rI   rP   rR   rS   rU   rV   rX   )rZ   r[   r\   r]   r^   r   rj   r_   r   r   r`   r)   r3   r:   rF   rM   ra   rb   rc   s   @r   r8   r8      s    : "%%N4 4 12
  ! '+!%  %	
  B5
* *r   r8   r0   c                     ^  \ 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SS	 jjrSSS
 jjrS rSrU =r$ )r2      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}
Nr.   c               <   > [         TU ]  SS/ USU[        US9US9  g)zCreate new CS gate.cs   r   r   )r   r0   r-   	base_gater.   N)r   r   r   r   r   r-   r.   r   s       r   r   CSGate.__init__  s4     	!+.# 	 		
r   r   rv   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   CSr%   r&   r!   r'   r(   s     r   r)   CSGate._define.  sA     	2 );;OO++DKK8SWS\S\ < 
r   c                (    [        U R                  S9$ )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-   )rm   r-   r9   s     r   r:   CSGate.inverse=  s     4??33r   c                F    SSK Jn  U" S[        R                  -  U-  5      $ )Nr   
CPhaseGater?   rA   r   rB   rC   r   rE   r1   r   s       r   rF   CSGate.powerK  s    !#.8344r   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ rI   )rJ   r2   r-   rK   s     r   rM   CSGate.__eq__P  s#    %(PT__@P@P-PPr   rO   NNr   rQ   r-   zOptional[Union[str, int]]rU   rV   rX   )rZ   r[   r\   r]   r^   r   r   r_   r   r   r`   r)   r:   rF   rM   ra   rb   rc   s   @r   r2   r2      si    8 "__N  $04

 

 .
 
& 1C
45
Q Qr   r2   c                     ^  \ 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SS	 jjrSSS
 jjrS rSrU =r$ )rm   iT  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}
Nry   c               :   > [         TU ]  SS/ USU[        US9S9  g)zCreate new CSdg gate.csdgr|   r   r   )r   r0   r-   r}   N)r   r   r8   r~   s       r   r   CSdgGate.__init__t  s1     	!K0 	 	
r   r   rv   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   CSdgr%   r&   r!   r'   r(   s     r   r)   CSdgGate._define  sC     	2 );;--dkk:$UYU^U^ < 
r   c                (    [        U R                  S9$ )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   )r2   r-   r9   s     r   r:   CSdgGate.inverse  s     11r   c                F    SSK Jn  U" S[        R                  -  U-  5      $ )Nr   r   rr   r   r   s       r   rF   CSdgGate.power  s    !$/H455r   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ rI   )rJ   rm   r-   rK   s     r   rM   CSdgGate.__eq__  s#    %*Rt%BRBR/RRr   rO   r   r   rU   rV   rX   )rZ   r[   r\   r]   r^   r   r   r_   r   r   r`   r)   r:   rF   rM   ra   rb   rc   s   @r   rm   rm   T  sk    8 "&&N  $04

 

 .
 
$ 1C
26
S Sr   rm   )r^   
__future__r   typingr   r   rB   qiskit.circuit.singletonr   r   r   qiskit.circuit._utilsr	   r
   qiskit._accelerate.circuitr   array_S_ARRAY
_SDG_ARRAYr   r8   r2   rm    r   r   <module>r      s    % " "  a a M 3 ;;AB()[[1a&1c(+,
 k(M k( k(\ h*m h* h*V Ha8WQ$ WQ 9WQt J:VS& VS ;VSr   