§
    ¹³ÙgþÉ  ã                  óÂ  — d Z ddlmZ ddlmZmZmZ ddlmZ ddl	Z	ddl
mZ ddlmZmZmZ ddlmZ dd	lmZmZmZ dd
l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d¬¦  «         G d„ de¦  «        ¦   «         Z eedd¬¦  «         G d„ de¦  «        ¦   «         Z eg d¢g d¢g d¢g d¢g d¢g d¢g d¢g d ¢g¦  «         G d!„ d"e¦  «        ¦   «         Z eed#d$¬¦  «         G d%„ d&e¦  «        ¦   «         Z  eed#d$¬¦  «         G d'„ d(e¦  «        ¦   «         Z! eg d)¢g d*¢g d+¢g d,¢g d-¢g d.¢g d/¢g d0¢g d1¢g d2¢g d3¢g d4¢g d5¢g d6¢g d7¢g d8¢g¦  «         G d9„ d:e¦  «        ¦   «         Z" eed;d<¬¦  «         G d=„ d>e¦  «        ¦   «         Z# G d?„ d@e¦  «        Z$ G dA„ dBe$¦  «        Z% G dC„ dDe$¦  «        Z& G dE„ dFe$¦  «        Z'dS )Gz(X, CX, CCX and multi-controlled X gates.é    )Úannotations)ÚOptionalÚUnionÚType)ÚpiN)ÚControlledGate)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)ÚQuantumRegister)Ú_ctrl_state_to_intÚwith_gate_arrayÚwith_controlled_gate_array)ÚStandardGate)Údeprecate_funcé   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„ Zˆ xZS )ÚXGateuß  The single-qubit Pauli-X gate (:math:`\sigma_x`).

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

    **Matrix Representation:**

    .. math::

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

    **Circuit symbol:**

    .. code-block:: text

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

    Equivalent to a :math:`\pi` radian rotation about the X axis.

    .. note::

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

        .. math::

            RX(\pi) = \begin{pmatrix}
                        0 & -i \\
                        -i & 0
                      \end{pmatrix}
                    = -i X

    The gate is equivalent to a classical bit flip.

    .. math::

        |0\rangle \rightarrow |1\rangle \\
        |1\rangle \rightarrow |0\rangle
    NÚdt©ÚdurationÚunitÚlabelúOptional[str]c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new X gate.Úxr   ©r   r   r   N©ÚsuperÚ__init__©Úselfr   r   r   Ú	__class__s       €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/x.pyr    zXGate.__init__N   s.   ø€ å‰Œ×Ò˜˜a ¨5¸8È$ÐÑOÔOÐOÐOÐOó    c                óô   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |t          dt          ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        dS )z-
        gate x a { u3(pi,0,pi) a; }
        r   ©ÚQuantumCircuitr   )ÚU3GateÚq©ÚnameN)	Úqiskit.circuit.quantumcircuitr(   Úu3r)   r   r,   r   Ú_appendÚ
definition)	r"   r(   r)   r*   ÚqcÚrulesÚinstrÚqargsÚcargss	            r$   Ú_definezXGate._defineT   s«   € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&�˜Q¥Ñ#Ô# a¨¤d V¨RÐ0Ð1ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   r   FÚnum_ctrl_qubitsÚintÚ
ctrl_stateúOptional[Union[str, int]]Ú	annotatedÚboolc                óˆ   •— |st          |||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )aT  Return a (multi-)controlled-X gate.

        One control returns a CX gate. Two controls returns a CCX 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.

        Returns:
            ControlledGate: controlled version of this gate.
        ©r7   r   r9   Ú_base_label©r7   r   r9   r;   )ÚMCXGater   r   Úcontrol©r"   r7   r   r9   r;   Úgater#   s         €r$   rB   zXGate.controld   sb   ø€ ð, ð 	ÝØ /ØØ%Ø œJð	ñ ô ˆDˆDõ ‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr%   c                ó   — t          ¦   «         S )aª  Return inverted X 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:
            XGate: inverse gate (self-inverse).
        )r   ©r"   r;   s     r$   ÚinversezXGate.inverseŠ   s   € õ ‰wŒwˆr%   c                ó,   — t          |t          ¦  «        S ©N)Ú
isinstancer   ©r"   Úothers     r$   Ú__eq__zXGate.__eq__˜   s   € Ý˜%¥Ñ'Ô'Ð'r%   rI   ©r   r   ©r   NNF©r7   r8   r   r   r9   r:   r;   r<   ©F©r;   r<   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú_standard_gater    r   Ú_singleton_lookup_keyr6   rB   rG   rM   Ú__classcell__©r#   s   @r$   r   r      sè   ø€ € € € € ð+ð +ðZ "Ô'€NðPÀÈ4ð Pð Pð Pð Pð Pð Pð Pð Pð 1Ð0Ñ2Ô2Ððð ð ð$  !Ø#Ø04Øð$ð $ð $ð $ð $ð $ð $ðLð ð ð ð ð(ð (ð (ð (ð (ð (ð (r%   r   ©r7   c                  ó€   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd	„Z ed
¬¦  «        Z		 	 	 	 ddˆ fd„Z
ddd„Zd„ Zˆ xZS )ÚCXGateuô  Controlled-X gate.

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

    **Circuit symbol:**

    .. code-block:: text

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

    **Matrix representation:**

    .. math::

        CX\ q_0, q_1 =
            I \otimes |0\rangle\langle0| + X \otimes |1\rangle\langle1| =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & 0 & 0 & 1 \\
                0 & 0 & 1 & 0 \\
                0 & 1 & 0 & 0
            \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::

            CX\ q_1, q_0 =
                |0 \rangle\langle 0| \otimes I + |1 \rangle\langle 1| \otimes X =
                \begin{pmatrix}
                    1 & 0 & 0 & 0 \\
                    0 & 1 & 0 & 0 \\
                    0 & 0 & 0 & 1 \\
                    0 & 0 & 1 & 0
                \end{pmatrix}


    In the computational basis, this gate flips the target qubit
    if the control qubit is in the :math:`|1\rangle` state.
    In this sense it is similar to a classical XOR gate.

    .. math::
        `|a, b\rangle \rightarrow |a, a \oplus b\rangle`
    Nr   ©r   r   r?   r   r   r9   r:   c               óz   •— t          ¦   «                              ddg d||t          |¬¦  «        |||¬¦
  «
         dS )zCreate new CX gate.Úcxé   r   ©r   )r7   r   r9   Ú	base_gater?   r   r   N©r   r    r   ©r"   r   r9   r   r   r?   r#   s         €r$   r    zCXGate.__init__ß   sY   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.Ø#ØØð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r%   r   r[   Fr7   r8   r;   r<   c                óÈ   •— |s9t          ||¦  «        }| j        |z  |z  }t          |dz   ||| j        ¬¦  «        }n%t	          ¦   «                              ||||¬¦  «        }|S )a  Return a controlled-X gate with more control lines.

        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.

        Returns:
            ControlledGate: controlled version of this gate.
        r   r>   r@   ©r   r9   rA   r   r   rB   ©r"   r7   r   r9   r;   Únew_ctrl_staterD   r#   s          €r$   rB   zCXGate.controlø   ó‡   ø€ ð( ð 	Ý+¨J¸ÑHÔHˆJØ"œo°Ñ@ÀJÑNˆNÝØ /°!Ñ 3ØØ)Ø œJð	ñ ô ˆDˆDõ ‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr%   c                ó,   — t          | j        ¬¦  «        S )a¬  Return inverted CX 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:
            CXGate: inverse gate (self-inverse).
        ©r9   )r]   r9   rF   s     r$   rG   zCXGate.inverse  s   € õ  ¤Ð1Ñ1Ô1Ð1r%   c                óL   — t          |t          ¦  «        o| j        |j        k    S rI   )rJ   r]   r9   rK   s     r$   rM   zCXGate.__eq__,  s!   € Ý˜%¥Ñ(Ô(ÐP¨T¬_ÀÔ@PÒ-PÐPr%   ©NN©r   r   r9   r:   rO   rP   rQ   rR   )rS   rT   rU   rV   r   r]   rW   r    r   rX   rB   rG   rM   rY   rZ   s   @r$   r]   r]   œ   së   ø€ € € € € ð=ð =ð~ "Ô(€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð. 1Ð0ÀÐCÑCÔCÐð  !Ø#Ø04Øð$ð $ð $ð $ð $ð $ð $ðL2ð 2ð 2ð 2ð 2ðQð Qð Qð Qð Qð Qð Qr%   r]   ra   )é   )r7   Úcached_statesc                  ó†   ‡ — 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ˆ fd„Zddd„Zd„ Zˆ xZS )ÚCCXGateu®  CCX gate, also known as Toffoli gate.

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

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â”€â– â”€â”€
               â”‚
        q_1: â”€â”€â– â”€â”€
             â”Œâ”€â”´â”€â”�
        q_2: â”¤ X â”œ
             â””â”€â”€â”€â”˜

    **Matrix representation:**

    .. math::

        CCX q_0, q_1, q_2 =
            I \otimes I \otimes |0 \rangle \langle 0| + CX \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 & 0 & 0 & 1\\
                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 & 1 & 0 & 0 & 0 & 0
            \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 and q_1. Thus a textbook matrix for this
        gate will be:

        .. code-block:: text

                 â”Œâ”€â”€â”€â”�
            q_0: â”¤ X â”œ
                 â””â”€â”¬â”€â”˜
            q_1: â”€â”€â– â”€â”€
                   â”‚
            q_2: â”€â”€â– â”€â”€

        .. math::

            CCX\ q_2, q_1, q_0 =
                |0 \rangle \langle 0| \otimes I \otimes I + |1 \rangle \langle 1| \otimes CX =
                \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 & 1 & 0 & 0\\
                    0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\
                    0 & 0 & 0 & 0 & 0 & 0 & 1 & 0
                \end{pmatrix}

    Nr   r^   r   r   r9   r:   c               óx   •— t          ¦   «                              ddg d||t          |¬¦  «        ||¬¦	  «	         dS )zCreate new CCX gate.Úccxrp   ra   rb   ©r7   r   r9   rc   r   r   Nrd   re   s         €r$   r    zCCXGate.__init__x  óV   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r%   ra   r[   c                ó‚  — ddl m} ddlm} ddlm}m} t          dd¦  «        } ||| j        ¬¦  «        } |¦   «         |d	         gg ft          ¦   «         |d         |d	         gg f |¦   «         |d	         gg ft          ¦   «         |d         |d	         gg f |¦   «         |d	         gg ft          ¦   «         |d         |d	         gg f |¦   «         |d	         gg ft          ¦   «         |d         |d	         gg f |¦   «         |d         gg f |¦   «         |d	         gg f |¦   «         |d	         gg ft          ¦   «         |d         |d         gg f |¦   «         |d         gg f |¦   «         |d         gg ft          ¦   «         |d         |d         gg fg}|D ]\  }}	}
| 
                    ||	|
¦  «         Œ|| _        d
S )z®
        gate ccx a,b,c
        {
        h c; cx b,c; tdg c; cx a,c;
        t c; cx b,c; tdg c; cx a,c;
        t b; t c; h c; cx a,b;
        t a; tdg b; cx a,b;}
        r   r'   r   ©ÚHGate)ÚTGateÚTdgGaterp   r*   r+   ra   N)r-   r(   Úhrz   Útr{   r|   r   r,   r]   r/   r0   )r"   r(   rz   r{   r|   r*   r1   r2   r3   r4   r5   s              r$   r6   zCCXGate._define�  s  € ð 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØ%Ð%Ð%Ð%Ð%Ð%Ð%Ð%õ ˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆW‰YŒY˜˜1œ˜ Ð#Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆW‰YŒY˜˜1œ˜ Ð#Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW‰YŒY˜˜1œ˜ Ð#Ý‰XŒX˜˜!œ˜a œd�| RÐ(ð
ˆð" $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   r   Fr7   r8   r;   r<   c                óÈ   •— |s9t          ||¦  «        }| j        |z  |z  }t          |dz   ||| j        ¬¦  «        }n%t	          ¦   «                              ||||¬¦  «        }|S )á  Controlled version of this 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.

        Returns:
            ControlledGate: controlled version of this gate.
        ra   r>   r@   rg   rh   s          €r$   rB   zCCXGate.control½  rj   r%   c                ó,   — t          | j        ¬¦  «        S )aµ  Return an inverted CCX gate (also a CCX).

        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:
            CCXGate: inverse gate (self-inverse).
        rl   )rs   r9   rF   s     r$   rG   zCCXGate.inverseã  ó   € õ  $¤/Ð2Ñ2Ô2Ð2r%   c                óL   — t          |t          ¦  «        o| j        |j        k    S rI   )rJ   rs   r9   rK   s     r$   rM   zCCXGate.__eq__ñ  ó!   € Ý˜%¥Ñ)Ô)ÐQ¨d¬oÀÔAQÒ.QÐQr%   rn   ro   rO   rP   rQ   rR   )rS   rT   rU   rV   r   rs   rW   r    r   rX   r6   rB   rG   rM   rY   rZ   s   @r$   rs   rs   0  sý   ø€ € € € € ðBð BðH "Ô)€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐð+ð +ð +ð^  !Ø#Ø04Øð$ð $ð $ð $ð $ð $ð $ðL3ð 3ð 3ð 3ð 3ðRð Rð Rð Rð Rð Rð Rr%   rs   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   ù       €      ð¿)r   r   r   r   r   r   r   r   )r   r   r   r   r   éÿÿÿÿr   r   )r   r   r   r   r   r   r   r   )r   r   r   ù              ð?r   r   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	„ Zˆ xZS )ÚRCCXGatea¤  The simplified Toffoli gate, also referred to as Margolus gate.

    The simplified Toffoli gate implements the Toffoli gate up to relative phases.
    This implementation requires three CX gates which is the minimal amount possible,
    as shown in https://arxiv.org/abs/quant-ph/0312225.
    Note, that the simplified Toffoli is not equivalent to the Toffoli. But can be used in places
    where the Toffoli gate is uncomputed again.

    This concrete implementation is from https://arxiv.org/abs/1508.03273, the dashed box
    of Fig. 3.

    Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
    with the :meth:`~qiskit.circuit.QuantumCircuit.rccx` method.
    Nr   r   r   r   c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )z!Create a new simplified CCX gate.Úrccxrp   r   Nr   r!   s       €r$   r    zRCCXGate.__init__  s.   ø€ å‰Œ×Ò˜  B¨e¸hÈTÐÑRÔRÐRÐRÐRr%   c                óÀ  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        ¬¦  «        } |dt          ¦  «        |d	         gg f |t          d
z  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t           d
z  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t          d
z  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t           d
z  ¦  «        |d	         gg f |dt          ¦  «        |d	         gg fg	}|D ]\  }}}	| 
                    |||	¦  «         Œ|| _        dS )zê
        gate rccx a,b,c
        { u2(0,pi) c;
          u1(pi/4) c;
          cx b, c;
          u1(-pi/4) c;
          cx a, c;
          u1(pi/4) c;
          cx b, c;
          u1(-pi/4) c;
          u2(0,pi) c;
        }
        r   r'   r   ©ÚU1Gate©ÚU2Gaterp   r*   r+   ra   é   N©r-   r(   Úu1rŽ   Úu2r�   r   r,   r   r]   r/   r0   ©
r"   r(   rŽ   r�   r*   r1   r2   r3   r4   r5   s
             r$   r6   zRCCXGate._define  s™  € ð 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)ØˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'ð

ˆð $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   c                ó,   — t          |t          ¦  «        S rI   )rJ   r‰   rK   s     r$   rM   zRCCXGate.__eq__>  ó   € Ý˜%¥Ñ*Ô*Ð*r%   rI   rN   )rS   rT   rU   rV   r   r‰   rW   r    r   rX   r6   rM   rY   rZ   s   @r$   r‰   r‰   õ  s�   ø€ € € € € ðð ð "Ô*€NðSÀÈ4ð Sð Sð Sð Sð Sð Sð Sð Sð 1Ð0Ñ2Ô2Ðð#ð #ð #ðJ+ð +ð +ð +ð +ð +ð +r%   r‰   rp   )é   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 )ÚC3SXGatez»The 3-qubit controlled sqrt-X gate.

    This implementation is based on Page 17 of [1].

    References:
        [1] Barenco et al., 1995. https://arxiv.org/pdf/quant-ph/9503016.pdf
    Nr   r^   r   r   r9   r:   c               ó|   •— ddl m} t          ¦   «                              ddg d|| ||¬¦  «        ||¬¦	  «	         dS )	a  Create a new 3-qubit controlled sqrt-X gate.

        Args:
            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.
        r   )ÚSXGateÚc3sxr‘   rp   rb   rv   N)Úsxrœ   r   r    )r"   r   r9   r   r   r?   rœ   r#   s          €r$   r    zC3SXGate.__init__N  sj   ø€ ð  	ÐÐÐÐÐå‰Œ×ÒØØØØØØ!Ø�f ;Ð/Ñ/Ô/ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r%   rp   r[   c                óÎ  — ddl m} ddlm} ddlm} t          j        dz  }t          dd¬	¦  «        } |¦   «         |d
         gg f ||¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f || ¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f ||¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f || ¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f ||¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f || ¦  «        |d         |d
         gg f |¦   «         |d
         gg ft          ¦   «         |d         |d         gg f |¦   «         |d
         gg f ||¦  «        |d         |d
         gg f |¦   «         |d
         gg fg} ||¦  «        }|D ]\  }}	}
| 
                    ||	|
¦  «         Œ|| _        dS )a¸  
        gate c3sqrtx a,b,c,d
        {
            h d; cu1(pi/8) a,d; h d;
            cx a,b;
            h d; cu1(-pi/8) b,d; h d;
            cx a,b;
            h d; cu1(pi/8) b,d; h d;
            cx b,c;
            h d; cu1(-pi/8) c,d; h d;
            cx a,c;
            h d; cu1(pi/8) c,d; h d;
            cx b,c;
            h d; cu1(-pi/8) c,d; h d;
            cx a,c;
            h d; cu1(pi/8) c,d; h d;
        }
        r   r'   r   ©ÚCU1Gatery   é   r‘   r*   r+   rp   ra   N)r-   r(   r“   r¡   r}   rz   Únumpyr   r   r]   r/   r0   )r"   r(   r¡   rz   Úangler*   r2   r1   r3   r4   r5   s              r$   r6   zC3SXGate._definen  sR  € ð( 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå”˜1‘ˆÝ˜A CÐ(Ñ(Ô(ˆàˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�U‰^Œ^˜a œd A a¤D˜\¨2Ð.ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�e�V‰_Œ_˜q œt Q q¤T˜l¨BÐ/ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�U‰^Œ^˜a œd A a¤D˜\¨2Ð.ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�e�V‰_Œ_˜q œt Q q¤T˜l¨BÐ/ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�U‰^Œ^˜a œd A a¤D˜\¨2Ð.ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�e�V‰_Œ_˜q œt Q q¤T˜l¨BÐ/ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW�U‰^Œ^˜a œd A a¤D˜\¨2Ð.ØˆU‰WŒW�q˜”t�f˜bÐ!ð7
ˆð: ˆ^˜AÑÔˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   c                óL   — t          |t          ¦  «        o| j        |j        k    S rI   )rJ   rš   r9   rK   s     r$   rM   zC3SXGate.__eq__«  s!   € Ý˜%¥Ñ*Ô*ÐR¨t¬À%ÔBRÒ/RÐRr%   rn   ro   )rS   rT   rU   rV   r   rš   rW   r    r   rX   r6   rM   rY   rZ   s   @r$   rš   rš   B  s¯   ø€ € € € € ðð ð "Ô*€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð< 1Ð0ÀÐCÑCÔCÐð;ð ;ð ;ðzSð Sð Sð Sð Sð Sð Sr%   rš   c                  ó†   ‡ — 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ˆ fd„Zddd„Zd„ Zˆ xZS )ÚC3XGateziThe X gate controlled on 3 qubits.

    This implementation uses :math:`\sqrt{T}` and 14 CNOT gates.
    Nr   )r?   r   r   r   r   r9   r:   c               óx   •— t          ¦   «                              ddg d||t          |¬¦  «        ||¬¦	  «	         dS )z'Create a new 3-qubit controlled X gate.Úmcxr‘   rp   rb   rv   Nrd   )r"   r   r9   r?   r   r   r#   s         €r$   r    zC3XGate.__init__¸  rw   r%   rp   r[   c                ó  — ddl m} t          dd¬¦  «        } ||| j        ¬¦  «        }|                     d¦  «         |                     t          dz  g d¢¦  «         |                     dd	¦  «         |                     t           dz  d	¦  «         |                     dd	¦  «         |                     d	d
¦  «         |                     t           dz  d
¦  «         |                     dd
¦  «         |                     t          dz  d
¦  «         |                     d	d
¦  «         |                     t           dz  d
¦  «         |                     dd
¦  «         |                     d
d¦  «         |                     t           dz  d¦  «         |                     d	d¦  «         |                     t          dz  d¦  «         |                     d
d¦  «         |                     t           dz  d¦  «         |                     dd¦  «         |                     t          dz  d¦  «         |                     d
d¦  «         |                     t           dz  d¦  «         |                     d	d¦  «         |                     t          dz  d¦  «         |                     d
d¦  «         |                     t           dz  d¦  «         |                     dd¦  «         |                     d¦  «         || _        dS )aÞ  
        gate c3x a,b,c,d
        {
            h d;
            p(pi/8) a;
            p(pi/8) b;
            p(pi/8) c;
            p(pi/8) d;
            cx a, b;
            p(-pi/8) b;
            cx a, b;
            cx b, c;
            p(-pi/8) c;
            cx a, c;
            p(pi/8) c;
            cx b, c;
            p(-pi/8) c;
            cx a, c;
            cx c, d;
            p(-pi/8) d;
            cx b, d;
            p(pi/8) d;
            cx c, d;
            p(-pi/8) d;
            cx a, d;
            p(pi/8) d;
            cx c, d;
            p(-pi/8) d;
            cx b, d;
            p(pi/8) d;
            cx c, d;
            p(-pi/8) d;
            cx a, d;
            h d;
        }
        r   r'   r‘   r*   r+   rp   r¢   )r   r   ra   rp   r   ra   N)	r-   r(   r   r,   r}   Úpr   r`   r0   )r"   r(   r*   r1   s       r$   r6   zC3XGate._defineÑ  s}  € ðJ 	AÐ@Ð@Ð@Ð@Ð@å˜A CÐ(Ñ(Ô(ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ
�ŠˆQ‰ŒˆØ
�Š�R�!‰V�\�\�\Ñ"Ô"Ð"Ø
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Š�R�!‰V�Q‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Š�R�!‰V�Q‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Š�R�!‰V�Q‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�Š�R�!‰V�Q‰ŒˆØ
�Šˆa�‰ŒˆØ
�Š�bˆS�1‰W�aÑÔÐØ
�Šˆa�‰ŒˆØ
�ŠˆQ‰ŒˆàˆŒˆˆr%   r   Fr7   r8   r;   r<   c                óÈ   •— |s9t          ||¦  «        }| j        |z  |z  }t          |dz   ||| j        ¬¦  «        }n%t	          ¦   «                              ||||¬¦  «        }|S )r€   rp   r>   r@   rg   rh   s          €r$   rB   zC3XGate.control  rj   r%   c                ó,   — t          | j        ¬¦  «        S )a¹  Invert this gate. The C3X is its own inverse.

        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:
            C3XGate: inverse gate (self-inverse).
        rl   )r§   r9   rF   s     r$   rG   zC3XGate.inverse?  r‚   r%   c                óL   — t          |t          ¦  «        o| j        |j        k    S rI   )rJ   r§   r9   rK   s     r$   rM   zC3XGate.__eq__M  r„   r%   rn   ro   rO   rP   rQ   rR   )rS   rT   rU   rV   r   r§   rW   r    r   rX   r6   rB   rG   rM   rY   rZ   s   @r$   r§   r§   ¯  sý   ø€ € € € € ðð ð
 "Ô)€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð, 1Ð0ÀÐCÑCÔCÐðFð Fð FðT  !Ø#Ø04Øð$ð $ð $ð $ð $ð $ð $ðL3ð 3ð 3ð 3ð 3ðRð Rð Rð Rð Rð Rð Rr%   r§   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r‡   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r…   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r†   r   r   r   r   r   r   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	„ Zˆ xZS )ÚRC3XGatea  The simplified 3-controlled Toffoli gate.

    The simplified Toffoli gate implements the Toffoli gate up to relative phases.
    Note, that the simplified Toffoli is not equivalent to the Toffoli. But can be used in places
    where the Toffoli gate is uncomputed again.

    This concrete implementation is from https://arxiv.org/abs/1508.03273, the complete circuit
    of Fig. 4.

    Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
    with the :meth:`~qiskit.circuit.QuantumCircuit.rcccx` method.
    Nr   r   r   r   c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate a new RC3X gate.Úrcccxr‘   r   Nr   r!   s       €r$   r    zRC3XGate.__init__u  s.   ø€ å‰Œ×Ò˜ ! R¨u¸xÈdÐÑSÔSÐSÐSÐSr%   c                óÀ  — ddl m} ddlm} ddlm} t          dd¦  «        } ||| j        ¬¦  «        } |dt          ¦  «        |d	         gg f |t          dz  ¦  «        |d	         gg ft          ¦   «         |d
         |d	         gg f |t           dz  ¦  «        |d	         gg f |dt          ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t          dz  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t           dz  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t          dz  ¦  «        |d	         gg ft          ¦   «         |d         |d	         gg f |t           dz  ¦  «        |d	         gg f |dt          ¦  «        |d	         gg f |t          dz  ¦  «        |d	         gg ft          ¦   «         |d
         |d	         gg f |t           dz  ¦  «        |d	         gg f |dt          ¦  «        |d	         gg fg}|D ]\  }}}	| 
                    |||	¦  «         Œ|| _        dS )a¥  
        gate rc3x a,b,c,d
        { u2(0,pi) d;
          u1(pi/4) d;
          cx c,d;
          u1(-pi/4) d;
          u2(0,pi) d;
          cx a,d;
          u1(pi/4) d;
          cx b,d;
          u1(-pi/4) d;
          cx a,d;
          u1(pi/4) d;
          cx b,d;
          u1(-pi/4) d;
          u2(0,pi) d;
          u1(pi/4) d;
          cx c,d;
          u1(-pi/4) d;
          u2(0,pi) d;
        }
        r   r'   r   r�   r�   r‘   r*   r+   rp   ra   Nr’   r•   s
             r$   r6   zRC3XGate._define{  s�  € ð0 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)ØˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)ØˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'ØˆV•B˜‘F‰^Œ^˜a œd˜V RÐ(Ý‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV•R�C˜!‘G‰_Œ_˜q œt˜f bÐ)ØˆV�A•r‰]Œ]˜Q˜qœT˜F BÐ'ð%
ˆð( $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   c                ó,   — t          |t          ¦  «        S rI   )rJ   r°   rK   s     r$   rM   zRC3XGate.__eq__²  r—   r%   rI   rN   )rS   rT   rU   rV   r   r°   rW   r    r   rX   r6   rM   rY   rZ   s   @r$   r°   r°   Q  s�   ø€ € € € € ð*ð ð "Ô*€NðTÀÈ4ð Tð Tð Tð Tð Tð Tð Tð Tð 1Ð0Ñ2Ô2Ðð5ð 5ð 5ðn+ð +ð +ð +ð +ð +ð +r%   r°   r‘   )é   c                  óx   ‡ — e Zd ZdZ	 	 dddddœdˆ fd	„Z ed
¬¦  «        Zd„ Z	 	 	 	 ddˆ fd„Zddd„Z	d„ Z
ˆ xZS )ÚC4XGatea@  The 4-qubit controlled X gate.

    This implementation is based on Page 21, Lemma 7.5, of [1], with the use
    of the relative phase version of c3x, the rc3x [2].

    References:
        1. Barenco et al., 1995. https://arxiv.org/pdf/quant-ph/9503016.pdf
        2. Maslov, 2015. https://arxiv.org/abs/1508.03273
    Nr   r^   r   r   r9   r:   c               ó€   •— |€d}t          ¦   «                              ddg d||t          |¬¦  «        ||¬¦	  «	         dS )z'Create a new 4-qubit controlled X gate.Nr   r©   é   r‘   rb   rv   rd   re   s         €r$   r    zC4XGate.__init__Â  s`   ø€ ð ˆ<ØˆDÝ‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØð 	ñ 
	
ô 
	
ð 
	
ð 
	
ð 
	
r%   r‘   r[   c                ó(  — ddl m} ddlm} ddlm} t          dd¬¦  «        } ||| j        ¬¦  «        } |¦   «         |d	         gg f |t          j	        d
z  ¦  «        |d         |d	         gg f |¦   «         |d	         gg ft          ¦   «         |d         |d         |d
         |d         gg f |¦   «         |d	         gg f |t          j	         d
z  ¦  «        |d         |d	         gg f |¦   «         |d	         gg ft          ¦   «                              ¦   «         |d         |d         |d
         |d         gg ft          ¦   «         |d         |d         |d
         |d	         gg fg	}|D ]\  }}}	|                     |||	¦  «         Œ|| _        dS )aƒ  
        gate c3sqrtx a,b,c,d
        {
            h d; cu1(pi/8) a,d; h d;
            cx a,b;
            h d; cu1(-pi/8) b,d; h d;
            cx a,b;
            h d; cu1(pi/8) b,d; h d;
            cx b,c;
            h d; cu1(-pi/8) c,d; h d;
            cx a,c;
            h d; cu1(pi/8) c,d; h d;
            cx b,c;
            h d; cu1(-pi/8) c,d; h d;
            cx a,c;
            h d; cu1(pi/8) c,d; h d;
        }
        gate c4x a,b,c,d,e
        {
            h e; cu1(pi/2) d,e; h e;
            rc3x a,b,c,d;
            h e; cu1(-pi/2) d,e; h e;
            rc3x a,b,c,d;
            c3sqrtx a,b,c,e;
        }
        r   r'   r   r    ry   r¹   r*   r+   r‘   ra   rp   N)r-   r(   r“   r¡   r}   rz   r   r,   r£   r   r°   rG   rš   r/   r0   )
r"   r(   r¡   rz   r*   r1   r2   r3   r4   r5   s
             r$   r6   zC4XGate._defineÝ  sÍ  € ð8 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐå˜A CÐ(Ñ(Ô(ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆU‰WŒW�q˜”t�f˜bÐ!ØˆW•U”X ‘\Ñ"Ô" Q q¤T¨1¨Q¬4 L°"Ð5ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰ZŒZ˜!˜Aœ$  !¤ a¨¤d¨A¨a¬DÐ1°2Ð6ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆW•e”h�Y ‘]Ñ#Ô# a¨¤d¨A¨a¬D \°2Ð6ØˆU‰WŒW�q˜”t�f˜bÐ!Ý‰ZŒZ×ÒÑ!Ô! A a¤D¨!¨A¬$°°!´°a¸´dÐ#;¸RÐ@Ý‰ZŒZ˜!˜Aœ$  !¤ a¨¤d¨A¨a¬DÐ1°2Ð6ð

ˆð $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr%   r   Fr7   r8   r;   r<   c                óÈ   •— |s9t          ||¦  «        }| j        |z  |z  }t          |dz   ||| j        ¬¦  «        }n%t	          ¦   «                              ||||¬¦  «        }|S )r€   r‘   r>   r@   rg   rh   s          €r$   rB   zC4XGate.control  rj   r%   c                ó,   — t          | j        ¬¦  «        S )a¹  Invert this gate. The C4X is its own inverse.

        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:
            C4XGate: inverse gate (self-inverse).
        rl   )r·   r9   rF   s     r$   rG   zC4XGate.inverse5  r‚   r%   c                óL   — t          |t          ¦  «        o| j        |j        k    S rI   )rJ   r·   r9   rK   s     r$   rM   zC4XGate.__eq__C  r„   r%   rn   ro   rO   rP   rQ   rR   )rS   rT   rU   rV   r    r   rX   r6   rB   rG   rM   rY   rZ   s   @r$   r·   r·   ¶  sð   ø€ € € € € ðð ð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð0 1Ð0ÀÐCÑCÔCÐð0ð 0ð 0ðh  !Ø#Ø04Øð$ð $ð $ð $ð $ð $ð $ðL3ð 3ð 3ð 3ð 3ðRð Rð Rð Rð Rð Rð Rr%   r·   c                  óÒ   ‡ — e Zd ZdZ	 	 	 d!ddddœd"ˆ fd„Z	 	 d#dddddœd$ˆ fd„Zd%d&d„Ze eddd¬¦  «        d'd(d„¦   «         ¦   «         Z	d„ Z
ed„ ¦   «         Z	 	 	 	 d)d*ˆ fd „Zˆ xZS )+rA   z«The general, multi-controlled X gate.

    Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
    with the :meth:`~qiskit.circuit.QuantumCircuit.mcx` method.
    Nr   r^   r7   úOptional[int]r   r   r9   r:   c               óþ   •— t           t          dœ}|                     |d¦  «        }|�5|                     ||||¬¦  «        }	|	                     |||||¬¦  «         |	S t          ¦   «                              | ¦  «        S )zÀCreate a new MCX instance.

        Depending on the number of controls and which mode of the MCX, this creates an
        explicit CX, CCX, C3X or C4X instance or a generic MCX gate.
        )r   ra   N©r   r9   r?   ©r   r9   r?   r   r   )r]   rs   ÚgetÚ__new__r    r   ©Úclsr7   r   r9   r   r   r?   ÚexplicitÚ
gate_classrD   r#   s             €r$   rÄ   zMCXGate.__new__N  s—   ø€ õ" 9?Å7Ð4KÐ4KˆØ—\’\ /°4Ñ8Ô8ˆ
ØÐ!Ø×%Ò%Ø %°JÈKð &ñ ô ˆDð �MŠMØØ%Ø'Ø!Øð ñ ô ð ð ˆKÝ‰wŒw�Š˜sÑ#Ô#Ð#r%   r©   )r   r   Ú_namer?   r8   c               ó´   •— | j                              |¦  «        }t          ¦   «                              ||dz   |z   g |||t	          |¬¦  «        ¬¦  «         dS )zCreate new MCX gate.r   rb   )r7   r   r9   rc   N)r#   Úget_num_ancilla_qubitsr   r    r   )
r"   r7   r   r9   r   r   rÉ   r?   Únum_ancilla_qubitsr#   s
            €r$   r    zMCXGate.__init__p  sq   ø€ ð "œ^×BÒBÀ?ÑSÔSÐÝ‰Œ×ÒØØ˜aÑÐ"4Ñ4ØØ+ØØ!Ý +Ð.Ñ.Ô.ð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r%   Fr;   r<   c                ó8   — t          | j        | j        ¬¦  «        S )a¹  Invert this gate. The MCX is its own inverse.

        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:
            MCXGate: inverse gate (self-inverse).
        ©r7   r9   )rA   r7   r9   rF   s     r$   rG   zMCXGate.inverse‡  s   € õ  tÔ';ÈÌÐXÑXÔXÐXr%   aæ  For an MCXGate it is no longer possible to know the number of ancilla qubits that would be eventually used by the transpiler when the gate is created. Instead, it is recommended to use MCXGate and let HighLevelSynthesis choose the best synthesis method depending on the number of ancilla qubits available. However, if a specific synthesis method using a specific number of ancilla qubits is require, one can create a custom gate by calling the corresponding synthesis function directly.ú1.3T©Úadditional_msgÚsinceÚpendingÚ	noancillaÚmodeÚstrÚreturnc                óÄ   — |dk    rdS |dv rt          | dk    ¦  «        S |dd…         dk    s|dd…         d	k    rt          d| d
z
  ¦  «        S t          d|› d�¦  «        ‚)zûGet the number of required ancilla qubits without instantiating the class.

        This staticmethod might be necessary to check the number of ancillas before
        creating the gate, or to use the number of ancillas in the initialization.
        rÔ   r   )Ú	recursionÚadvancedr‘   Nr˜   úv-chainr¹   Úbasicra   zUnsupported mode (z) specified!)r8   ÚmaxÚAttributeError©r7   rÕ   s     r$   rË   zMCXGate.get_num_ancilla_qubits•  s‡   € ð( �;ÒÐØ�1ØÐ,Ð,Ð,Ý�¨Ò*Ñ+Ô+Ð+Ø���Œ8�yÒ Ð  D¨¨!¨¤H°Ò$7Ð$7Ý�q˜/¨AÑ-Ñ.Ô.Ð.ÝÐD°$ÐDÐDÐDÑEÔEÐEr%   c                ó@   — ddl m}  || j        ¦  «        }|| _        dS )z7This definition is based on MCPhaseGate implementation.r   )Úsynth_mcx_noaux_v24N)Ú!qiskit.synthesis.multi_controlledrá   r7   r0   )r"   rá   r1   s      r$   r6   zMCXGate._define±  ó5   € ð 	JÐIÐIÐIÐIÐIà Ð  Ô!5Ñ6Ô6ˆØˆŒˆˆr%   c                ó@   — | j                              | j        ¦  «        S )zThe number of ancilla qubits.)r#   rË   r7   )r"   s    r$   rÌ   zMCXGate.num_ancilla_qubits¹  s   € ð Œ~×4Ò4°TÔ5IÑJÔJÐJr%   r   c                ó¦   •— |s)|€'|                       | j        |z   ||| j        ¬¦  «        }n$t          ¦   «                              |||¬¦  «        }|S )a!  Return a multi-controlled-X gate with more control lines.

        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.

        Returns:
            ControlledGate: controlled version of this gate.
        NrÁ   )r   r9   )r#   r7   r   r   rB   rC   s         €r$   rB   zMCXGate.control¾  se   ø€ ð( ð 		X˜ZÐ/à—>’>ØÔ$ Ñ6ØØ%Ø œJð	 "ñ ô ˆDˆDõ ‘7”7—?’? ?¸%ÈJ�?ÑWÔWˆDØˆr%   ©NNN©r7   r¿   r   r   r9   r:   rn   ©r7   r8   r   r   r9   r:   rQ   rR   )rÔ   )r7   r8   rÕ   rÖ   r×   r8   rO   rP   )rS   rT   rU   rV   rÄ   r    rG   Ústaticmethodr   rË   r6   ÚpropertyrÌ   rB   rY   rZ   s   @r$   rA   rA   G  s�  ø€ € € € € ðð ð *.Ø#Ø04ð	 $ð ØØð $ð  $ð  $ð  $ð  $ð  $ð  $ð  $ðJ  $Ø04ð	
ð ØØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð.Yð Yð Yð Yð Yð Ø€^ð+ð Øðñ ô ðFð Fð Fð Fñô ñ „\ðFðð ð ð ðKð Kñ „XðKð  !Ø#Ø04Øðð ð ð ð ð ð ð ð ð ð r%   rA   c                  ó€   ‡ — e Zd ZdZ	 	 	 dddddœdˆ fd„Z eddd¬¦  «        	 	 ddˆ fd„¦   «         Zddd„Zd„ Zˆ xZ	S )ÚMCXGrayCodez£Implement the multi-controlled X gate using the Gray code.

    This delegates the implementation to the MCU1 gate, since :math:`X = H \cdot U1(\pi) \cdot H`.
    Nr   r^   r7   r¿   r   r   r9   r:   c               ó  •— t           t          t          t          dœ}|                     |d¦  «        }|�6|                     ||||||¬¦  «        }	|	                     ||||¬¦  «         |	S t          ¦   «                              | ¦  «        S )z!Create a new MCXGrayCode instance)r   ra   rp   r‘   NrÂ   )r   r9   r   r   )r]   rs   r§   r·   rÃ   rÄ   r    r   rÅ   s             €r$   rÄ   zMCXGrayCode.__new__å  s¡   ø€ õ ¥'­g½'ÐBÐBˆØ—\’\ /°4Ñ8Ô8ˆ
ØÐ!Ø×%Ò%ØØØ%Ø'Ø!Øð &ñ ô ˆDð �MŠMØØ%Ø!Øð	 ñ ô ð ð ˆKÝ‰wŒw�Š˜sÑ#Ô#Ð#r%   ag  It is recommended to use MCXGate and let HighLevelSynthesis choose the best synthesis method depending on the number of ancilla qubits available. If this specific synthesis method is required, one can specify it using the high-level-synthesis plugin `gray_code` for MCX gates, or, alternatively, one can use synth_mcx_gray_code to construct the gate directly.rÏ   TrÐ   r8   c                óR   •— t          ¦   «                              |||d¬¦  «         d S )NÚmcx_gray©r   r9   rÉ   r   )r"   r7   r   r9   r#   s       €r$   r    zMCXGrayCode.__init__  s-   ø€ õ" 	‰Œ×Ò˜°À*ÐT^ÐÑ_Ô_Ð_Ð_Ð_r%   Fr;   r<   c                ó8   — t          | j        | j        ¬¦  «        S )a½  Invert this gate. The MCX is its own inverse.

        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:
            MCXGrayCode: inverse gate (self-inverse).
        rÎ   )rì   r7   r9   rF   s     r$   rG   zMCXGrayCode.inverse  s   € õ ¨4Ô+?ÈDÌOÐ\Ñ\Ô\Ð\r%   c                ó@   — ddl m}  || j        ¦  «        }|| _        dS )z(Define the MCX gate using the Gray code.r   )Úsynth_mcx_gray_codeN)râ   ró   r7   r0   )r"   ró   r1   s      r$   r6   zMCXGrayCode._define'  rã   r%   ræ   rç   rn   rè   rQ   rR   )
rS   rT   rU   rV   rÄ   r   r    rG   r6   rY   rZ   s   @r$   rì   rì   ß  sú   ø€ € € € € ðð ð *.Ø#Ø04ð	$ð ØØð$ð $ð $ð $ð $ð $ð $ð $ðB €^ðNð Øð
ñ 
ô 
ð  $Ø04ð	`ð `ð `ð `ð `ð `ñ
ô 
ð`ð]ð ]ð ]ð ]ð ]ðð ð ð ð ð ð r%   rì   c                  ó†   ‡ — e Zd ZdZ eddd¬¦  «        	 	 dddddœdˆ fd„¦   «         Zeddd„¦   «         Zddd„Zd„ Z	ˆ xZ
S )ÚMCXRecursivea¹  Implement the multi-controlled X gate using recursion.

    Using a single clean ancilla qubit, the multi-controlled X gate is split into
    four sub-registers, each one of them uses the V-chain method.

    The method is based on Lemma 9 of [2], first shown in Lemma 7.3 of [1].

    References:
        1. Barenco et al., 1995. https://arxiv.org/pdf/quant-ph/9503016.pdf
        2. Iten et al., 2015. https://arxiv.org/abs/1501.06911
    ag  It is recommended to use MCXGate and let HighLevelSynthesis choose the best synthesis method depending on the number of ancilla qubits available. If this specific synthesis method is required, one can specify it using the high-level-synthesis plugin '1_clean_b95' for MCX gates, or, alternatively, one can use synth_mcx_1_clean to construct the gate directly.rÏ   TrÐ   Nr   r^   r7   r8   r   r   r9   r:   c          	     óX   •— t          ¦   «                              |||d||d ¬¦  «         d S )NÚmcx_recursive)r   r9   rÉ   r   r   r?   r   )r"   r7   r   r9   r   r   r?   r#   s          €r$   r    zMCXRecursive.__init__=  sE   ø€ õ* 	‰Œ×ÒØØØ!Ø!ØØØð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r%   rÙ   rÕ   rÖ   c                ó8   — t                                | |¦  «        S ©z*Get the number of required ancilla qubits.©rA   rË   rß   s     r$   rË   z#MCXRecursive.get_num_ancilla_qubits\  ó   € õ ×-Ò-¨o¸tÑDÔDÐDr%   Fr;   r<   c                ó8   — t          | j        | j        ¬¦  «        S )a¾  Invert this gate. The MCX is its own inverse.

        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:
            MCXRecursive: inverse gate (self-inverse).
        rÎ   )rõ   r7   r9   rF   s     r$   rG   zMCXRecursive.inversea  s   € õ ¨DÔ,@ÈTÌ_Ð]Ñ]Ô]Ð]r%   c                ó@   — ddl m}  || j        ¦  «        }|| _        dS )z$Define the MCX gate using recursion.r   )Úsynth_mcx_1_clean_b95N)râ   rþ   r7   r0   )r"   rþ   r1   s      r$   r6   zMCXRecursive._defineo  s5   € ð 	LÐKÐKÐKÐKÐKà"Ð" 4Ô#7Ñ8Ô8ˆØˆŒˆˆr%   rn   rè   )rÙ   ©r7   r8   rÕ   rÖ   rQ   rR   )rS   rT   rU   rV   r   r    ré   rË   rG   r6   rY   rZ   s   @r$   rõ   rõ   0  sî   ø€ € € € € ð
ð 
ð €^ðLð Øð
ñ 
ô 
ð  $Ø04ð	
ð ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ñ
ô 
ð
ð( ðEð Eð Eð Eñ „\ðEð^ð ^ð ^ð ^ð ^ðð ð ð ð ð ð r%   rõ   c                  ó°   ‡ — e Zd ZdZ	 	 	 	 dddddddœdˆ fd„Z eddd¬¦  «        	 	 	 d ddddddœd!ˆ fd„¦   «         Zd"d#d„Zed$d%d„¦   «         Z	d„ Z
ˆ xZS )&Ú	MCXVChainzBImplement the multi-controlled X gate using a V-chain of CX gates.NFr   )r   r   r?   Úrelative_phaseÚaction_onlyr7   r¿   Údirty_ancillasr<   r   r   r9   r:   r  r  c          	     óT   •— t          ¦   «                              | ||||||¬¦  «        S )z}Create a new MCX instance.

        This must be defined anew to include the additional argument ``dirty_ancillas``.
        rÂ   )r   rÄ   )rÆ   r7   r  r   r9   r   r   r?   r  r  r#   s             €r$   rÄ   zMCXVChain.__new__|  s9   ø€ õ" ‰wŒw�ŠØØØØ!Ø#ØØð ñ 
ô 
ð 	
r%   aÁ  It is recommended to use MCXGate and let HighLevelSynthesis choose the best synthesis method depending on the number of ancilla qubits available. If this specific synthesis method is required, one can specify it using the high-level-synthesis plugins `n_clean_m15` (using clean ancillas) or `n_dirty_i15` (using dirty ancillas) for MCX gates. Alternatively, one can use synth_mcx_n_dirty_i15 and synth_mcx_n_clean_m15 to construct the gate directly.rÏ   TrÐ   r8   c          	     óÌ   •— t          ¦   «                              |||d|||¬¦  «         || _        || _        |	| _        t          ¦   «                              |||d¬¦  «         dS )aj  
        Args:
            dirty_ancillas: when set to ``True``, the method applies an optimized multicontrolled-X gate
                up to a relative phase using dirty ancillary qubits with the properties of lemmas 7 and 8
                from arXiv:1501.06911, with at most 8*k - 6 CNOT gates.
                For k within the range {1, ..., ceil(n/2)}. And for n representing the total number of
                qubits.
            relative_phase: when set to ``True``, the method applies the optimized multicontrolled-X gate
                up to a relative phase, in a way that, by lemma 7 of arXiv:1501.06911, the relative
                phases of the ``action part`` cancel out with the phases of the ``reset part``.

            action_only: when set to ``True``, the method applies only the action part of lemma 8
                from arXiv:1501.06911.

        Ú
mcx_vchain)r   r9   rÉ   r?   r   r   rð   N)r   r    Ú_dirty_ancillasÚ_relative_phaseÚ_action_only)r"   r7   r  r   r9   r   r   r?   r  r  r#   s             €r$   r    zMCXVChain.__init__—  s~   ø€ õP 	‰Œ×ÒØØØ!ØØ#ØØð 	ñ 	
ô 	
ð 	
ð  .ˆÔØ-ˆÔØ'ˆÔÝ‰Œ×Ò˜°À*ÐT`ÐÑaÔaÐaÐaÐar%   r;   c                ó\   — t          | j        | j        | j        | j        | j        ¬¦  «        S )a»  Invert this gate. The MCX is its own inverse.

        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:
            MCXVChain: inverse gate (self-inverse).
        )r7   r  r9   r  r  )r  r7   r  r9   r	  r
  rF   s     r$   rG   zMCXVChain.inverseÍ  s8   € õ Ø Ô0ØÔ/Ø”ØÔ/ØÔ)ð
ñ 
ô 
ð 	
r%   rÛ   rÕ   rÖ   c                ó8   — t                                | |¦  «        S rù   rú   rß   s     r$   rË   z MCXVChain.get_num_ancilla_qubitsá  rû   r%   c                ó”   — | j         r#ddlm}  || j        | j        | j        ¦  «        }nddlm}  || j        ¦  «        }|| _        dS )z0Define the MCX gate using a V-chain of CX gates.r   )Úsynth_mcx_n_dirty_i15)Úsynth_mcx_n_clean_m15N)r  râ   r  r7   r	  r
  r  r0   )r"   r  r1   r  s       r$   r6   zMCXVChain._defineæ  sz   € ð Ôð 	=àOÐOÐOÐOÐOÐOà&Ð&ØÔ$ØÔ$ØÔ!ñô ˆBˆBð PÐOÐOÐOÐOÐOà&Ð& tÔ';Ñ<Ô<ˆBàˆŒˆˆr%   )NFNN)r7   r¿   r  r<   r   r   r9   r:   r  r<   r  r<   )FNN)r7   r8   r  r<   r   r   r9   r:   r  r<   r  r<   rQ   rR   )rÛ   rÿ   )rS   rT   rU   rV   rÄ   r   r    rG   ré   rË   r6   rY   rZ   s   @r$   r  r  y  sD  ø€ € € € € ØLÐLð *.Ø$Ø#Ø04ð
ð ØØØ$Ø!ð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð6 €^ðbð Øðñ ô ð  %Ø#Ø04ð(bð ØØØ$Ø!ð(bð (bð (bð (bð (bð (bð (bñô ð(bðT
ð 
ð 
ð 
ð 
ð( ðEð Eð Eð Eñ „\ðEðð ð ð ð ð ð r%   r  )(rV   Ú
__future__r   Útypingr   r   r   Úmathr   r£   Úqiskit.circuit.controlledgater   Úqiskit.circuit.singletonr	   r
   r   Úqiskit.circuit.quantumregisterr   Úqiskit.circuit._utilsr   r   r   Úqiskit._accelerate.circuitr   Úqiskit.utils.deprecationr   Ú_X_ARRAYÚ	_SX_ARRAYr   r]   rs   r‰   rš   r§   r°   r·   rA   rì   rõ   r  © r%   r$   ú<module>r     sb  ðð /Ð .Ø "Ð "Ð "Ð "Ð "Ð "Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð Ø €€€Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ :Ð :Ð :Ð :Ð :Ð :Ø aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ 3Ð 3Ð 3Ð 3Ð 3Ð 3Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3à�ˆF�Q˜�FÐ€Ø˜*Ð%¨
°JÐ'?Ð@€	ð €�ÑÔð{(ð {(ð {(ð {(ð {(ˆMñ {(ô {(ñ Ôð{(ð| Ð˜H°aÐ8Ñ8Ô8ðPQð PQð PQð PQð PQÐ$ñ PQô PQñ 9Ô8ðPQðf Ð˜H°aÀtÐLÑLÔLðARð ARð ARð ARð ARÐ%ñ ARô ARñ MÔLðARðH €à Ð Ð Ø Ð Ð Ø Ð Ð Ø"Ð"Ð"Ø Ð Ð Ø!Ð!Ð!Ø Ð Ð Ø!Ð!Ð!ð	ñô ð>+ð >+ð >+ð >+ð >+ˆ}ñ >+ô >+ñô ð>+ðB Ð˜I°qÈÐMÑMÔMðiSð iSð iSð iSð iSÐ&ñ iSô iSñ NÔMðiSðX Ð˜H°aÀtÐLÑLÔLð^Rð ^Rð ^Rð ^Rð ^RÐ%ñ ^Rô ^Rñ MÔLð^RðB €à8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø9Ð9Ð9Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø:Ð:Ð:Ø8Ð8Ð8Ø8Ð8Ð8Ø8Ð8Ð8Ø9Ð9Ð9ð!ñô ð(N+ð N+ð N+ð N+ð N+ˆ}ñ N+ô N+ñ)ô ð(N+ðb Ð˜H°aÀuÐMÑMÔMðMRð MRð MRð MRð MRÐ%ñ MRô MRñ NÔMðMRð`Uð Uð Uð Uð Uˆnñ Uô Uð UðpNð Nð Nð Nð N�'ñ Nô Nð NðbFð Fð Fð Fð F�7ñ Fô Fð FðR@ð @ð @ð @ð @�ñ @ô @ð @ð @ð @r%   