ó
    Óz	i"  ã                  óî   • 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Q/ S	Q/ S
Q/ SQ/5      r\" \5       " S S\5      5       r\" \SS9 " S S\	5      5       rg)z
Swap gate.é    )Úannotations)ÚOptionalÚUnionN)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)Úwith_gate_arrayÚwith_controlled_gate_array)ÚStandardGate)é   r   r   r   )r   r   r   r   )r   r   r   r   )r   r   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 rSrU =r$ )ÚSwapGateé   uT  The SWAP gate.

This is a symmetric and Clifford gate.

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

Circuit symbol:

.. code-block:: text

    q_0: â”€Xâ”€
          â”‚
    q_1: â”€Xâ”€

Matrix representation:

.. math::

    SWAP =
        \begin{pmatrix}
            1 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 \\
            0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 1
        \end{pmatrix}

The gate is equivalent to a state swap and is a classical logic gate.

.. math::

    |a, b\rangle \rightarrow |b, a\rangle
c                ó&   >• [         TU ]  SS/ US9  g)z2
Args:
    label: An optional label for the gate.
Úswapé   ©ÚlabelN)ÚsuperÚ__init__)Úselfr   Ú	__class__s     €Úd/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/swap.pyr   ÚSwapGate.__init__A   s   ø€ ô
 	‰Ñ˜  B¨eÐÒ4ó    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   ÚSwapÚ_get_definitionÚparamsr    Ú
definition©r   r   s     r   Ú_defineÚSwapGate._defineJ   sC   € õ 	2ð )×;Ñ;Ü×Ñ×-Ñ-¨d¯k©kÓ:È$ÐUY×U^ÑU^ð <ð 
ˆ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-SWAP gate.

One control returns a CSWAP (Fredkin) 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:
    ControlledGate: controlled version of this gate.
r   )r   Ú
ctrl_stateÚ_base_label)Únum_ctrl_qubitsr   r+   Ú	annotated)Ú	CSwapGater   r   Úcontrol)r   r-   r   r+   r.   Úgater   s         €r   r0   ÚSwapGate.controlY   sN   ø€ ö, ˜_°Ó1Ü 5ÈTÏZÉZÑXˆDð ˆô ‘7‘?Ø /ØØ%Ø#ð	 #ð ˆDð ˆr   c                ó   • [        5       $ )ao  Return inverse Swap gate (itself).

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 this gate
        is self-inverse.

Returns:
    SwapGate: inverse gate (self-inverse).
)r   ©r   r.   s     r   ÚinverseÚSwapGate.inversez   s   € ô ‹zÐr   c                ó"   • [        U[        5      $ ©N)Ú
isinstancer   ©r   Úothers     r   Ú__eq__ÚSwapGate.__eq__ˆ   s   € Ü˜%¤Ó*Ð*r   ©r&   r8   )r   úOptional[str])r   NNN)r-   Úintr   z
str | Noner+   zstr | int | Noner.   zbool | None©F©r.   Úbool)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r#   Ú_standard_gater   r   Ú_singleton_lookup_keyr(   r0   r5   r<   Ú__static_attributes__Ú__classcell__©r   s   @r   r   r      s~   ø† ñ ðD "×&Ñ&€N÷5ñ 5ñ 1Ó2Ðò
ð"  !Ø Ø'+Ø!%ðàðð ðð %ð	ð
 ÷ð öB÷+ð +r   r   r   ©r-   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
 rSrU =r$ )r/   éŒ   u˜  Controlled-SWAP gate, also known as the Fredkin gate.

Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
with the :meth:`~qiskit.circuit.QuantumCircuit.cswap` and
:meth:`~qiskit.circuit.QuantumCircuit.fredkin` methods.

Circuit symbol:

.. code-block:: text

    q_0: â”€â– â”€
          â”‚
    q_1: â”€Xâ”€
          â”‚
    q_2: â”€Xâ”€


Matrix representation:

.. math::

    CSWAP\ q_0, q_1, q_2 =
        I \otimes I \otimes |0 \rangle \langle 0| +
        SWAP \otimes |1 \rangle \langle 1| =
        \begin{pmatrix}
            1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
            0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
            0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
            0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
            0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
            0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
        \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_2. Thus a textbook matrix for this
    gate will be:

    .. code-block:: text

        q_0: â”€Xâ”€
              â”‚
        q_1: â”€Xâ”€
              â”‚
        q_2: â”€â– â”€

    .. math::

        CSWAP\ q_2, q_1, q_0 =
            |0 \rangle \langle 0| \otimes I \otimes I +
            |1 \rangle \langle 1| \otimes SWAP =
            \begin{pmatrix}
                1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\
                0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
                0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 \\
                0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 \\
                0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 \\
                0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 \\
                0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 \\
                0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 \\
            \end{pmatrix}

In the computational basis, this gate swaps the states of
the two target qubits if the control qubit is in the
:math:`|1\rangle` state.

.. math::
    |0, b, c\rangle \rightarrow |0, b, c\rangle
    |1, b, c\rangle \rightarrow |1, c, b\rangle
N)r,   c               ó:   >• [         TU ]  SS/ SUU[        US9S9  g)zCreate new CSWAP gate.Úcswapé   r   r   )r-   r   r+   Ú	base_gateN)r   r   r   )r   r   r+   r,   r   s       €r   r   ÚCSwapGate.__init__Ü   s1   ø€ ô 	‰ÑØØØØØØ!Ü [Ñ1ð 	ò 	
r   r   rN   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   ÚCSwapr$   r%   r    r&   r'   s     r   r(   ÚCSwapGate._defineð   sC   € õ 	2ð )×;Ñ;Ü×Ñ×.Ñ.¨t¯{©{Ó;È4ÐVZ×V_ÑV_ð <ð 
ˆr   c                ó(   • [        U R                  S9$ )aq  Return inverse CSwap gate (itself).

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 this gate
        is self-inverse.

Returns:
    CSwapGate: inverse gate (self-inverse).
)r+   )r/   r+   r4   s     r   r5   ÚCSwapGate.inverse   s   € ô  D§O¡OÑ4Ð4r   c                ób   • [        U[        5      =(       a    U R                  UR                  :H  $ r8   )r9   r/   r+   r:   s     r   r<   ÚCSwapGate.__eq__  s#   € Ü˜%¤Ó+×S°·±À5×CSÑCSÑ0SÐSr   r>   )NN)r   r?   r+   zOptional[Union[str, int]]rA   rB   )rD   rE   rF   rG   rH   r   rW   rI   r   r   rJ   r(   r5   r<   rK   rL   rM   s   @r   r/   r/   Œ   sh   ø† ñJðX "×'Ñ'€Nð  $Ø04ð
ð
 ñ
àð
ð .÷
ñ 
ñ$ 1ÀÑCÐò
ö 5÷Tð Tr   r/   )rH   Ú
__future__r   Útypingr   r   ÚnumpyÚqiskit.circuit.singletonr   r   r   Úqiskit.circuit._utilsr	   r
   Úqiskit._accelerate.circuitr   ÚarrayÚ_SWAP_ARRAYr   r/   © r   r   Ú<module>rf      s…   ðñ å "ç "Û ß aÑ aß MÝ 3ð kŠkš<ª²|Â\ÐRÓS€ñ Óôm+ˆ}ó m+ó ðm+ñ` ˜K¸Ñ;ôBTÐ'ó BTó <ñBTr   