§
    ¹³Ùg—   ã                  óz   — d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ  G d	„ d
e¦  «        ZdS )zTwo-qubit ZX-rotation gate.é    )ÚannotationsN)ÚOptional)ÚGate)ÚQuantumRegister)ÚParameterValueTypeÚParameterExpression)ÚStandardGatec                  ó|   ‡ — e Zd ZdZej        Z	 ddddœdˆ fd	„Zd
„ Z	 	 	 	 ddˆ fd„Z	d d!d„Z
d"d„Zd d#d„Zd„ Zˆ xZS )$ÚRZXGateuq  A parametric 2-qubit :math:`Z \otimes X` interaction (rotation about ZX).

    This gate is maximally entangling at :math:`\theta = \pi/2`.

    The cross-resonance gate (CR) for superconducting qubits implements
    a ZX interaction (however other terms are also present in an experiment).

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

    **Circuit Symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
        q_0: â”¤0        â”œ
             â”‚  Rzx(Î¸) â”‚
        q_1: â”¤1        â”œ
             â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

    **Matrix Representation:**

    .. math::

        \newcommand{\rotationangle}{\frac{\theta}{2}}

        R_{ZX}(\theta)\ q_0, q_1 = \exp\left(-i \frac{\theta}{2} X{\otimes}Z\right) =
            \begin{pmatrix}
                \cos\left(\rotationangle\right) & 0 & -i\sin\left(\rotationangle\right) & 0 \\
                0 & \cos\left(\rotationangle\right) & 0 & i\sin\left(\rotationangle\right) \\
                -i\sin\left(\rotationangle\right) & 0 & \cos\left(\rotationangle\right) & 0 \\
                0 & i\sin\left(\rotationangle\right) & 0 & \cos\left(\rotationangle\right)
            \end{pmatrix}

    .. note::

        In Qiskit's convention, higher qubit indices are more significant
        (little endian convention). In the above example we apply the gate
        on (q_0, q_1) which results in the :math:`X \otimes Z` tensor order.
        Instead, if we apply it on (q_1, q_0), the matrix will
        be :math:`Z \otimes X`:

        .. code-block:: text

                 â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
            q_0: â”¤1        â”œ
                 â”‚  Rzx(Î¸) â”‚
            q_1: â”¤0        â”œ
                 â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜

        .. math::

            \newcommand{\rotationangle}{\frac{\theta}{2}}

            R_{ZX}(\theta)\ q_1, q_0 = exp(-i \frac{\theta}{2} Z{\otimes}X) =
                \begin{pmatrix}
                    \cos(\rotationangle)   & -i\sin(\rotationangle) & 0           & 0          \\
                    -i\sin(\rotationangle) & \cos(\rotationangle)   & 0           & 0          \\
                    0           & 0           & \cos(\rotationangle)   & i\sin(\rotationangle) \\
                    0           & 0           & i\sin(\rotationangle)  & \cos(\rotationangle)
                \end{pmatrix}

        This is a direct sum of RX rotations, so this gate is equivalent to a
        uniformly controlled (multiplexed) RX gate:

        .. math::

            R_{ZX}(\theta)\ q_1, q_0 =
                \begin{pmatrix}
                    RX(\theta) & 0 \\
                    0 & RX(-\theta)
                \end{pmatrix}

    **Examples:**

        .. math::

            R_{ZX}(\theta = 0)\ q_0, q_1 = I

        .. math::

            R_{ZX}(\theta = 2\pi)\ q_0, q_1 = -I

        .. math::

            R_{ZX}(\theta = \pi)\ q_0, q_1 = -i X \otimes Z

        .. math::

            R_{ZX}(\theta = \frac{\pi}{2})\ q_0, q_1 = \frac{1}{\sqrt{2}}
                                    \begin{pmatrix}
                                        1  & 0 & -i & 0 \\
                                        0  & 1 & 0  & i \\
                                        -i & 0 & 1  & 0 \\
                                        0  & i & 0  & 1
                                    \end{pmatrix}
    NÚdt)ÚdurationÚunitÚthetar   ÚlabelúOptional[str]c               óX   •— t          ¦   «                              dd|g|||¬¦  «         dS )zCreate new RZX gate.Úrzxé   )r   r   r   N)ÚsuperÚ__init__)Úselfr   r   r   r   Ú	__class__s        €ú_/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/rzx.pyr   zRZXGate.__init__~   s3   ø€ õ 	‰Œ×Ò˜  E 7°%À(ÐQUÐÑVÔVÐVÐVÐVó    c                óÂ  — ddl m} ddlm} ddlm} ddlm} | j        d         }t          dd¦  «        } ||| j
        ¬	¦  «        } |¦   «         |d         gg f |¦   «         |d         |d         gg f ||¦  «        |d         gg f |¦   «         |d         |d         gg f |¦   «         |d         gg fg}|D ]\  }	}
}|                     |	|
|¦  «         Œ|| _        d
S )zR
        gate rzx(theta) a, b { h b; cx a, b; u1(theta) b; cx a, b; h b;}
        r   )ÚQuantumCircuité   )ÚHGate)ÚCXGate)ÚRZGater   Úq)ÚnameN)Úqiskit.circuit.quantumcircuitr   Úhr   Úxr   Úrzr    Úparamsr   r"   Ú_appendÚ
definition)r   r   r   r   r    r   r!   ÚqcÚrulesÚinstrÚqargsÚcargss               r   Ú_definezRZXGate._define„   s>  € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØÐÐÐÐÐØÐÐÐÐÐð ”˜A”ˆÝ˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆU‰WŒW�q˜”t�f˜bÐ!ØˆV‰XŒX˜˜!œ˜a œd�| RÐ(ØˆV�E‰]Œ]˜Q˜qœT˜F BÐ'ØˆV‰XŒX˜˜!œ˜a œd�| RÐ(ØˆU‰WŒW�q˜”t�f˜bÐ!ð
ˆð $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr   r   Únum_ctrl_qubitsÚintú
str | NoneÚ
ctrl_stateústr | int | NoneÚ	annotatedúbool | Nonec                ó’   •— |€t          d„ | j        D ¦   «         ¦  «        }t          ¦   «                              ||||¬¦  «        }|S )a£  Return a (multi-)controlled-RZX 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 set to ``True`` if
                the gate contains free parameters, in which case it cannot
                yet be synthesized.

        Returns:
            ControlledGate: controlled version of this gate.
        Nc              3  ó@   K  — | ]}t          |t          ¦  «        V — Œd S ©N)Ú
isinstancer   )Ú.0Úps     r   ú	<genexpr>z"RZXGate.control.<locals>.<genexpr>¸   s-   è è € ÐTÐTÀ1�J qÕ*=Ñ>Ô>ÐTÐTÐTÐTÐTÐTr   )r0   r   r3   r5   )Úanyr'   r   Úcontrol)r   r0   r   r3   r5   Úgater   s         €r   r?   zRZXGate.control¡   sX   ø€ ð, ÐÝÐTÐTÈÌÐTÑTÔTÑTÔTˆIå‰wŒw�ŠØ+ØØ!Øð	 ñ 
ô 
ˆð ˆr   FÚboolc                ó8   — t          | j        d          ¦  «        S )aü  Return inverse RZX gate (i.e. with the negative rotation angle).

        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:`.RZXGate` with an inverted parameter value.

         Returns:
            RZXGate: inverse gate.
        r   )r   r'   )r   r5   s     r   ÚinversezRZXGate.inverseÂ   s   € õ ˜œ Aœ�Ñ'Ô'Ð'r   c           	     ó  — ddl }|du rt          d¦  «        ‚t          | j        d         ¦  «        dz  }t	          j        |¦  «        }dt	          j        |¦  «        z  }|                     |d| dgd|d|g| d|dgd|d|gg|¬¦  «        S )z&Return a numpy.array for the RZX gate.r   NFz9unable to avoid copy while creating an array as requestedr   y              ð?)Údtype)ÚnumpyÚ
ValueErrorÚfloatr'   ÚmathÚcosÚsinÚarray)r   rE   ÚcopyrF   Ú
half_thetarJ   Úisins          r   Ú	__array__zRZXGate.__array__Ð   s²   € àˆˆˆà�5ˆ=ˆ=ÝÐXÑYÔYÐYÝ˜4œ; qœ>Ñ*Ô*¨QÑ.ˆ
ÝŒh�zÑ"Ô"ˆØ•D”H˜ZÑ(Ô(Ñ(ˆØ�{Š{Ø�1�t�e˜QÐ ! S¨!¨TÐ!2°d°U¸A¸sÀAÐ4FÈÈDÐRSÐUXÐHYÐZØð ñ 
ô 
ð 	
r   ÚexponentrH   c                ó8   — | j         \  }t          ||z  ¦  «        S r9   )r'   r   )r   rQ   r5   r   s       r   ÚpowerzRZXGate.powerÞ   s   € Ø”;‰ˆÝ�x %Ñ'Ñ(Ô(Ð(r   c                óZ   — t          |t          ¦  «        r|                      |¦  «        S dS )NF)r:   r   Ú_compare_parameters)r   Úothers     r   Ú__eq__zRZXGate.__eq__â   s-   € Ý�e�WÑ%Ô%ð 	3Ø×+Ò+¨EÑ2Ô2Ð2Øˆur   r9   )r   r   r   r   )r   NNN)r0   r1   r   r2   r3   r4   r5   r6   )F)r5   rA   )NN)rQ   rH   r5   rA   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   Ú_standard_gater   r/   r?   rC   rP   rS   rW   Ú__classcell__)r   s   @r   r   r      s  ø€ € € € € ð`ð `ðD "Ô)€Nð AEðWØRVÐ]aðWð Wð Wð Wð Wð Wð Wð Wðð ð ð>  !Ø Ø'+Ø!%ðð ð ð ð ð ð ðB(ð (ð (ð (ð (ð
ð 
ð 
ð 
ð)ð )ð )ð )ð )ðð ð ð ð ð ð r   r   )r[   Ú
__future__r   rI   Útypingr   Úqiskit.circuit.gater   Úqiskit.circuit.quantumregisterr   Ú"qiskit.circuit.parameterexpressionr   r   Úqiskit._accelerate.circuitr	   r   © r   r   ú<module>re      sÆ   ðð "Ð !à "Ð "Ð "Ð "Ð "Ð "à €€€Ø Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø :Ð :Ð :Ð :Ð :Ð :Ø VÐ VÐ VÐ VÐ VÐ VÐ VÐ VØ 3Ð 3Ð 3Ð 3Ð 3Ð 3ðLð Lð Lð Lð Lˆdñ Lô Lð Lð Lð Lr   