§
    ¹³Ùg�  ã                  óª   — d Z ddlm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 dd	lmZ dd
lmZ  G d„ de¦  «        Z G d„ de¦  «        ZdS )u"   
Global MÃ¸lmerâ€“SÃ¸rensen gate.
é    )Úannotations)ÚSequenceN)ÚQuantumCircuit)ÚQuantumRegister)ÚParameterValueType)ÚRXXGate)ÚGate)Údeprecate_funcc                  óL   ‡ — e Zd ZdZ eddd¬¦  «        dˆ fd„¦   «         Zˆ xZS )ÚGMSu  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1.3zUse the MSGate instead.T)ÚsinceÚadditional_msgÚpendingÚ
num_qubitsÚintÚthetaúlist[list[float]] | np.ndarrayÚreturnÚNonec                óò  •— t          ¦   «                              |d¬¦  «         t          |t          ¦  «        s|gt	          |dz  dz
  dz  ¦  «        z  }t          |d¬¦  «        }t          | j        ¦  «        D ]N}t          |dz   | j        ¦  «        D ]3}|                     t          ||         |         ¦  «        ||g¦  «         Œ4ŒO|                      | 
                    ¦   «         | j        ¦  «         dS )u  Create a new Global MÃ¸lmerâ€“SÃ¸rensen (GMS) gate.

        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Úlistr   r   Úranger   Úappendr   Úto_gateÚqubits)Úselfr   r   r   ÚiÚjÚ	__class__s         €úb/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/generalized_gates/gms.pyr   zGMS.__init__Q   sô   ø€ õ 	‰Œ×Ò˜¨%ÐÑ0Ô0Ð0Ý˜%¥Ñ&Ô&ð 	;Ø�G�c :¨q¡=°1Ñ#4¸Ñ"9Ñ:Ô:Ñ:ˆEÝ˜Z¨eÐ4Ñ4Ô4ˆÝ�t”Ñ'Ô'ð 	9ð 	9ˆAÝ˜1˜q™5 $¤/Ñ2Ô2ð 9ð 9�Ø—
’
�7 5¨¤8¨A¤;Ñ/Ô/°!°Q°Ñ8Ô8Ð8Ð8ð9à�Š�C—K’K‘M”M 4¤;Ñ/Ô/Ð/Ð/Ð/ó    )r   r   r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Ú__classcell__©r'   s   @r(   r   r      si   ø€ € € € € ð0ð 0ðd €^˜%Ð0IÐSWÐXÑXÔXð0ð 0ð 0ð 0ð 0ñ YÔXð0ð 0ð 0ð 0ð 0r)   r   c                  ó8   ‡ — e Zd ZdZ	 ddˆ fd	„Zd
„ Zˆ fd„Zˆ xZS )ÚMSGateu(  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>`_
    Nr   r   r   ú;ParameterValueType | Sequence[Sequence[ParameterValueType]]Úlabelú
str | Nonec                óT   •— t          ¦   «                              d||g|¬¦  «         dS )aŒ  
        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)r3   N)r   r   )r$   r   r   r3   r'   s       €r(   r   zMSGate.__init__‹   s.   ø€ õ 	‰Œ×Ò˜˜z¨E¨7¸%ÐÑ@Ô@Ð@Ð@Ð@r)   c                ó˜  — | j         d         }t          | j        d¬¦  «        }t          || j        ¬¦  «        }t          | j        ¦  «        D ]t}t          |dz   | j        ¦  «        D ]Y}t          |t          ¦  «        s|n||         |         }|                     t          |¦  «        ||         ||         gg ¦  «         ŒZŒu|| _
        d S )Nr   Úqr   r   )Úparamsr   r   r   r   r    r   r   Ú_appendr   Ú
definition)r$   Úthetasr8   Úqcr%   r&   r   s          r(   Ú_definezMSGate._define›   sË   € Ø”˜Q”ˆÝ˜DœO°#Ð6Ñ6Ô6ˆÝ˜A D¤IÐ.Ñ.Ô.ˆÝ�t”Ñ'Ô'ð 	=ð 	=ˆAÝ˜1˜q™5 $¤/Ñ2Ô2ð =ð =�å&0°½Ñ&BÔ&BÐT˜˜ÈÈqÌ	ÐRSÌ�Ø—
’
�7 5™>œ>¨A¨a¬D°!°A´$¨<¸Ñ<Ô<Ð<Ð<ð=ð
 ˆŒˆˆr)   c                ó�   •‡ — t          |t          ¦  «        rˆˆ fd„|D ¦   «         S t          ¦   «                              |¦  «        S )Nc                ó.   •— g | ]}ˆˆfd „|D ¦   «         ‘ŒS )c                ó`   •— g | ]*}t          t          ‰¦  «                             |¦  «        ‘Œ+S © )r   r1   Úvalidate_parameter)Ú.0r   r'   r$   s     €€r(   ú
<listcomp>z8MSGate.validate_parameter.<locals>.<listcomp>.<listcomp>«   s1   ø€ ÐPÐPÐPÀ5••v˜tÑ$Ô$×7Ò7¸Ñ>Ô>ÐPÐPÐPr)   rB   )rD   Úrowr'   r$   s     €€r(   rE   z-MSGate.validate_parameter.<locals>.<listcomp>ª   sA   ø€ ð ð ð àð QÐPÐPÐPÐPÈCÐPÑPÔPðð ð r)   )r   r   r   rC   )r$   Ú	parameterr'   s   ` €r(   rC   zMSGate.validate_parameter§   s`   øø€ Ý�i¥Ñ*Ô*ð 	ðð ð ð ð à$ðñ ô ð õ
 ‰wŒw×)Ò)¨)Ñ4Ô4Ð4r)   )N)r   r   r   r2   r3   r4   )r*   r+   r,   r-   r   r>   rC   r.   r/   s   @r(   r1   r1   e   s�   ø€ € € € € ð#ð #ðR !ð	Að Að Að Að Að Að Að 
ð 
ð 
ð5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5r)   r1   )r-   Ú
__future__r   Úcollections.abcr   ÚnumpyÚnpÚqiskit.circuit.quantumcircuitr   Úqiskit.circuit.quantumregisterr   Ú"qiskit.circuit.parameterexpressionr   Ú%qiskit.circuit.library.standard_gatesr   Úqiskit.circuit.gater	   Úqiskit.utils.deprecationr
   r   r1   rB   r)   r(   ú<module>rR      s  ððð ð #Ð "Ð "Ð "Ð "Ð "Ø $Ð $Ð $Ð $Ð $Ð $à Ð Ð Ð Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø :Ð :Ð :Ð :Ð :Ð :Ø AÐ AÐ AÐ AÐ AÐ AØ 9Ð 9Ð 9Ð 9Ð 9Ð 9Ø $Ð $Ð $Ð $Ð $Ð $Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ðD0ð D0ð D0ð D0ð D0ˆ.ñ D0ô D0ð D0ðNJ5ð J5ð J5ð J5ð J5ˆTñ J5ô J5ð J5ð J5ð J5r)   