
    z	i`                        S r SSKJ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  SSKJr  SS	KJr  SS
KJr   " S S\5      r " S S\5      rg)u"   
Global Mølmer–Sørensen gate.
    )annotations)SequenceN)QuantumCircuit)QuantumRegister)ParameterValueType)RXXGate)Gate)deprecate_funcc                  F   ^  \ rS rSrSr\" SSSS9S	U 4S jj5       rSrU =r$ )
GMS   ul  Global Mølmer–Sørensen gate.

Circuit symbol:

.. code-block:: text

         ┌───────────┐
    q_0: ┤0          ├
         │           │
    q_1: ┤1   GMS    ├
         │           │
    q_2: ┤2          ├
         └───────────┘

Expanded Circuit:

.. plot::
   :alt: Diagram illustrating the previously described circuit.

   from qiskit.circuit.library import GMS
   from qiskit.visualization.library import _generate_circuit_library_visualization
   import numpy as np
   circuit = GMS(num_qubits=3, theta=[[0, np.pi/4, np.pi/8],
                                      [0, 0, np.pi/2],
                                      [0, 0, 0]])
   _generate_circuit_library_visualization(circuit.decompose())

The Mølmer–Sørensen gate is native to ion-trap systems. The global MS
can be applied to multiple ions to entangle multiple qubits simultaneously [1].

In the two-qubit case, this is equivalent to an XX(theta) interaction,
and is thus reduced to the RXXGate. The global MS gate is a sum of XX
interactions on all pairs [2].

.. math::

    GMS(\chi_{12}, \chi_{13}, ..., \chi_{n-1 n}) =
    exp(-i \sum_{i=1}^{n} \sum_{j=i+1}^{n} X{\otimes}X \frac{\chi_{ij}}{2})

References:

[1] Sørensen, A. and Mølmer, K., Multi-particle entanglement of hot trapped ions.
Physical Review Letters. 82 (9): 1835–1838.
`arXiv:9810040 <https://arxiv.org/abs/quant-ph/9810040>`_

[2] Maslov, D. and Nam, Y., Use of global interactions in efficient quantum circuit
constructions. New Journal of Physics, 20(3), p.033018.
`arXiv:1707.06356 <https://arxiv.org/abs/1707.06356>`_
z2.1zUse the MSGate instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec                  > [         TU ]  USS9  [        U[        5      (       d  U/[	        US-  S-
  S-  5      -  n[        USS9n[        U R                  5       HD  n[        US-   U R                  5       H$  nUR                  [        X$   U   5      XE/5        M&     MF     U R                  UR                  5       U R                  5        g)z
Args:
    num_qubits: width of gate.
    theta: a num_qubits x num_qubits symmetric matrix of
        interaction angles for each qubit pair. The upper
        triangle is considered.
gmsname      N)super__init__
isinstancelistintr   range
num_qubitsappendr   to_gatequbits)selfr   thetar   ij	__class__s         f/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/generalized_gates/gms.pyr   GMS.__init__Q   s     	%0%&&Gc:q=1#4"9::EZe4t'A1q5$//2

758A;/!8 3 ( 	CKKM4;;/     )r   r   r"   zlist[list[float]] | np.ndarrayreturnNone)	__name__
__module____qualname____firstlineno____doc__r
   r   __static_attributes____classcell__r%   s   @r&   r   r      s+    0d 0(
0
0r(   r   c                  R   ^  \ rS rSrSr S     SU 4S jjjrS rU 4S jrSrU =r	$ )	MSGateh   u  The Mølmer–Sørensen gate.

The Mølmer–Sørensen gate is native to ion-trap systems. The global MS
can be applied to multiple ions to entangle multiple qubits simultaneously [1].

In the two-qubit case, this is equivalent to an XX interaction,
and is thus reduced to the :class:`.RXXGate`. The global MS gate is a sum of XX
interactions on all pairs [2].

.. math::

    MS(\chi_{12}, \chi_{13}, ..., \chi_{n-1 n}) =
    exp(-i \sum_{i=1}^{n} \sum_{j=i+1}^{n} X{\otimes}X \frac{\chi_{ij}}{2})

Example::

    import numpy as np
    from qiskit.circuit.library import MSGate
    from qiskit.quantum_info import Operator

    gate = MSGate(num_qubits=3, theta=[[0, np.pi/4, np.pi/8],
                                       [0, 0, np.pi/2],
                                       [0, 0, 0]])
    print(Operator(gate))


References:

[1] Sørensen, A. and Mølmer, K., Multi-particle entanglement of hot trapped ions.
Physical Review Letters. 82 (9): 1835–1838.
`arXiv:9810040 <https://arxiv.org/abs/quant-ph/9810040>`_

[2] Maslov, D. and Nam, Y., Use of global interactions in efficient quantum circuit
constructions. New Journal of Physics, 20(3), p.033018.
`arXiv:1707.06356 <https://arxiv.org/abs/1707.06356>`_
c                &   > [         TU ]  SX/US9  g)aT  
Args:
    num_qubits: The number of qubits the MS gate acts on.
    theta: The XX rotation angles. If a single value, the same angle is used on all
        interactions. Alternatively an upper-triangular, square matrix with width
        ``num_qubits`` can be provided with interaction angles for each qubit pair.
    label: A gate label.
ms)labelN)r   r   )r!   r   r"   r9   r%   s       r&   r   MSGate.__init__   s     	z7%@r(   c                t   U R                   S   n[        U R                  SS9n[        X R                  S9n[        U R                  5       Hc  n[        US-   U R                  5       HC  n[        U[        5      (       d  UOX   U   nUR                  [        U5      X$   X%   // 5        ME     Me     X0l
        g )Nr   qr   r   )paramsr   r   r   r   r   r   r   _appendr   
definition)r!   thetasr<   qcr#   r$   r"   s          r&   _defineMSGate._define   s    QDOO#6AII.t'A1q5$//2&0&B&B	RS

75>AD!$<< 3 ( r(   c           
        > [        U[        5      (       a7  U VVs/ s H'  nU Vs/ s H  n[        [        U ]  U5      PM     snPM)     snn$ [        TU ]  U5      $ s  snf s  snnf N)r   r   r   r5   validate_parameter)r!   	parameterrowr"   r%   s       r&   rF   MSGate.validate_parameter   sl    i** %$C MPPC5vt7>CP$ 
 w))44	 Qs   
A"AA"A")r?   rE   )r   r   r"   z;ParameterValueType | Sequence[Sequence[ParameterValueType]]r9   z
str | None)
r,   r-   r.   r/   r0   r   rB   rF   r1   r2   r3   s   @r&   r5   r5   h   sI    #R !	AA KA 	A A 
5 5r(   r5   )r0   
__future__r   collections.abcr   numpynpqiskit.circuit.quantumcircuitr   qiskit.circuitr   "qiskit.circuit.parameterexpressionr   %qiskit.circuit.library.standard_gatesr   qiskit.circuit.gater	   qiskit.utils.deprecationr
   r   r5   r)   r(   r&   <module>rT      sD    # $  8 * A 9 $ 3G0. G0TJ5T J5r(   