
    z	i`                    f    S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	J
r
  SSKJr   " S S	\5      rg)
zTwo-qubit ZX-rotation gate.    )annotationsN)Optional)Gate)ParameterValueTypeParameterExpression)StandardGatec                     ^  \ rS rSrSr\R                  rSSU 4S jjjrS r	    S       SU 4S jjjr
SSS jjrSS jrSSS jjrS	 rS
rU =r$ )RZXGate   u!  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}
c                (   > [         TU ]  SSU/US9  g)zQ
Args:
    theta: The rotation angle.
    label: An optional label for the gate.
rzx   )labelN)super__init__)selfthetar   	__class__s      c/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/rzx.pyr   RZXGate.__init__}   s     	E7%8    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   RZX_get_definitionparamsr   
definition)r   r   s     r   _defineRZXGate._define   sC     	2 );;,,T[[9TXT]T] < 
r   c                f   > Uc  [        S U R                   5       5      n[        TU ]  UUUUS9nU$ )aC  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.
c              3  B   #    U  H  n[        U[        5      v   M     g 7fN)
isinstancer   ).0ps     r   	<genexpr>"RZXGate.control.<locals>.<genexpr>   s     T1Jq*=>>s   )num_ctrl_qubitsr   
ctrl_state	annotated)anyr    r   control)r   r,   r   r-   r.   gater   s         r   r0   RZXGate.control   sE    , TTTIw+!	  
 r   c                4    [        U R                  S   * 5      $ )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   r.   s     r   inverseRZXGate.inverse   s     A''r   c           	     
   SSK nUSL a  [        S5      e[        U R                  S   5      S-  n[        R
                  " U5      nS[        R                  " U5      -  nUR                  USU* S/SUSU/U* SUS/SUSU//US9$ )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   r7   copyr8   
half_thetar<   isins          r   	__array__RZXGate.__array__   s    5=XYY4;;q>*Q.
hhz"DHHZ(({{1teQ!S!T!2dUAsA4FDRSUXHYZ  
 	
r   c                8    U R                   u  n[        X-  5      $ r&   )r    r
   )r   exponentr.   r   s       r   powerRZXGate.power   s    ;;x'((r   c                P    [        U[        5      (       a  U R                  U5      $ g)NF)r'   r
   _compare_parameters)r   others     r   __eq__RZXGate.__eq__   s#    eW%%++E22r   )r!   r&   )r   r   r   zOptional[str])   NNN)r,   intr   z
str | Noner-   zstr | int | Noner.   zbool | None)F)r.   bool)NN)rE   r:   r.   rO   )__name__
__module____qualname____firstlineno____doc__r   r   _standard_gater   r"   r0   r4   rB   rF   rK   __static_attributes____classcell__)r   s   @r   r
   r
      s~    `D "%%N9 9
   ! '+!%  %	
  B(
) r   r
   )rT   
__future__r   r;   typingr   qiskit.circuit.gater   "qiskit.circuit.parameterexpressionr   r   qiskit._accelerate.circuitr   r
    r   r   <module>r^      s*    " "   $ V 3d r   