§
    ¹³Ù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mZ erdd	lmZ  G d
„ de¦  «        Zd„ Zd„ ZdS )z0A gate to implement time-evolution of operators.é    )Úannotations)ÚTYPE_CHECKINGN)ÚGate)ÚParameterValueType)ÚParameterExpression)ÚPauliÚSparsePauliOp)ÚEvolutionSynthesisc                  óx   ‡ — e Zd ZdZ	 	 	 ddˆ fd„Zedd„¦   «         Zej        dd„¦   «         Zd„ Zdˆ fd„Z	ˆ xZ
S )ÚPauliEvolutionGateu$  Time-evolution of an operator consisting of Paulis.

    For an operator :math:`H` consisting of Pauli terms and (real) evolution time :math:`t`
    this gate implements

    .. math::

        U(t) = e^{-itH}.

    This gate serves as a high-level definition of the evolution and can be synthesized into
    a circuit using different algorithms.

    The evolution gates are related to the Pauli rotation gates by a factor of 2. For example
    the time evolution of the Pauli :math:`X` operator is connected to the Pauli :math:`X` rotation
    :math:`R_X` by

    .. math::

        U(t) = e^{-itX} = R_X(2t).

    **Examples:**

    .. code-block:: python

        from qiskit.circuit import QuantumCircuit
        from qiskit.circuit.library import PauliEvolutionGate
        from qiskit.quantum_info import SparsePauliOp

        X = SparsePauliOp("X")
        Z = SparsePauliOp("Z")
        I = SparsePauliOp("I")

        # build the evolution gate
        operator = (Z ^ Z) - 0.1 * (X ^ I)
        evo = PauliEvolutionGate(operator, time=0.2)

        # plug it into a circuit
        circuit = QuantumCircuit(2)
        circuit.append(evo, range(2))
        print(circuit.draw())

    The above will print (note that the ``-0.1`` coefficient is not printed!)::

             â”Œâ”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”�
        q_0: â”¤0                         â”œ
             â”‚  exp(-it (ZZ + XI))(0.2) â”‚
        q_1: â”¤1                         â”œ
             â””â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”€â”˜


    **References:**

    [1] G. Li et al. Paulihedral: A Generalized Block-Wise Compiler Optimization
    Framework For Quantum Simulation Kernels (2021).
    [`arXiv:2109.03371 <https://arxiv.org/abs/2109.03371>`_]
    ç      ð?NÚoperatorú3Pauli | SparsePauliOp | list[Pauli | SparsePauliOp]Útimer   Úlabelú
str | NoneÚ	synthesisúEvolutionSynthesis | NoneÚreturnÚNonec                ój  •— t          |t          ¦  «        rd„ |D ¦   «         }nt          |¦  «        }|€t          |¦  «        }t          |t          ¦  «        r|d         j        n|j        }t          ¦   «                              d||g|¬¦  «         || _        |€ddlm	}  |¦   «         }|| _
        dS )a:  
        Args:
            operator (Pauli | SparsePauliOp | list):
                The operator to evolve. Can also be provided as list of non-commuting
                operators where the elements are sums of commuting operators.
                For example: ``[XY + YX, ZZ + ZI + IZ, YY]``.
            time: The evolution time.
            label: A label for the gate to display in visualizations. Per default, the label is
                set to ``exp(-it <operators>)`` where ``<operators>`` is the sum of the Paulis.
                Note that the label does not include any coefficients of the Paulis. See the
                class docstring for an example.
            synthesis: A synthesis strategy. If None, the default synthesis is the Lie-Trotter
                product formula with a single repetition.
        c                ó,   — g | ]}t          |¦  «        ‘ŒS © )Ú_to_sparse_pauli_op©Ú.0Úops     ú\/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/pauli_evolution.pyú
<listcomp>z/PauliEvolutionGate.__init__.<locals>.<listcomp>m   s!   € ÐCÐCÐC°BÕ+¨BÑ/Ô/ÐCÐCÐCó    Nr   ÚPauliEvolution)ÚnameÚ
num_qubitsÚparamsr   )Ú
LieTrotter)Ú
isinstanceÚlistr   Ú_get_default_labelr#   ÚsuperÚ__init__r   Úqiskit.synthesis.evolutionr%   r   )Úselfr   r   r   r   r#   r%   Ú	__class__s          €r   r*   zPauliEvolutionGate.__init__W   sÈ   ø€ õ* �h¥Ñ%Ô%ð 	5ØCÐC¸(ÐCÑCÔCˆHˆHå*¨8Ñ4Ô4ˆHàˆ=Ý& xÑ0Ô0ˆEå/9¸(ÅDÑ/IÔ/IÐb�X˜a”[Ô+Ð+ÈxÔObˆ
Ý‰Œ×ÒÐ.¸:ÈtÈfÐ\aÐÑbÔbÐbØ ˆŒàÐà=Ð=Ð=Ð=Ð=Ð=à"˜
™œˆIà"ˆŒˆˆr    c                ó   — | j         d         S )zvReturn the evolution time as stored in the gate parameters.

        Returns:
            The evolution time.
        r   ©r$   ©r,   s    r   r   zPauliEvolutionGate.time€   s   € ð Œ{˜1Œ~Ðr    c                ó   — |g| _         dS )zUSet the evolution time.

        Args:
            time: The evolution time.
        Nr/   )r,   r   s     r   r   zPauliEvolutionGate.time‰   s   € ð �fˆŒˆˆr    c                óD   — | j                              | ¦  «        | _        dS )z4Unroll, where the default synthesis is matrix based.N)r   Ú
synthesizeÚ
definitionr0   s    r   Ú_definezPauliEvolutionGate._define’   s   € àœ.×3Ò3°DÑ9Ô9ˆŒˆˆr    Ú	parameterc                óŽ   •— t          |t          ¦  «        rt          |¦  «        }t          ¦   «                              |¦  «        S )z<Gate parameters should be int, float, or ParameterExpression)r&   ÚintÚfloatr)   Úvalidate_parameter)r,   r6   r-   s     €r   r:   z%PauliEvolutionGate.validate_parameter–   s:   ø€ å�i¥Ñ%Ô%ð 	)Ý˜iÑ(Ô(ˆIå‰wŒw×)Ò)¨)Ñ4Ô4Ð4r    )r   NN)
r   r   r   r   r   r   r   r   r   r   )r   r   )r   r   r   r   )r6   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   Úpropertyr   Úsetterr5   r:   Ú__classcell__)r-   s   @r   r   r      sÈ   ø€ € € € € ð7ð 7ðx $'Ø Ø/3ð'#ð '#ð '#ð '#ð '#ð '#ð '#ðR ðð ð ñ „Xðð 
„[ðð ð ñ „[ðð:ð :ð :ð5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5ð 5r    r   c                ó„  — t          | t          ¦  «        rt          | ¦  «        }n8t          | t          ¦  «        r| }n t          dt	          | ¦  «        › d�¦  «        ‚t          t          j        |j        ¦  «        ¦  «        rt          d¦  «        ‚t          d„ |j        D ¦   «         ¦  «        rt          d¦  «        ‚|S )z%Cast the operator to a SparsePauliOp.z)Unsupported operator type for evolution: ú.z@Operator contains complex coefficients, which are not supported.c              3  ó@   K  — | ]}t          |t          ¦  «        V — Œd S )N)r&   r   )r   Úcoeffs     r   ú	<genexpr>z&_to_sparse_pauli_op.<locals>.<genexpr>ª   s-   è è € Ð
SÐ
S°e�:�eÕ0Ñ1Ô1Ð
SÐ
SÐ
SÐ
SÐ
SÐ
Sr    z?Operator contains ParameterExpression, which are not supported.)	r&   r   r	   Ú
ValueErrorÚtypeÚanyÚnpÚ	iscomplexÚcoeffs)r   Úsparse_paulis     r   r   r   ž   sÅ   € õ �(�EÑ"Ô"ð XÝ$ XÑ.Ô.ˆˆÝ	�H�mÑ	,Ô	,ð XØˆˆåÐVÅTÈ(Á^Ä^ÐVÐVÐVÑWÔWÐWå
�2Œ<˜Ô+Ñ,Ô,Ñ-Ô-ð ]ÝÐ[Ñ\Ô\Ð\Ý
Ð
SÐ
S¸|Ô?RÐ
SÑ
SÔ
SÑSÔSð \ÝÐZÑ[Ô[Ð[àÐr    c                ó*  — t          | t          ¦  «        rdd„ | D ¦   «         › d�}nlt          | j        ¦  «        dk    r$d| j                             ¦   «         d         › d�}n0dd                     | j                             ¦   «         ¦  «        › d�}|S )	Nz	exp(-it (c                óf   — g | ].}d                       |j                             ¦   «         ¦  «        ‘Œ/S )ú + )ÚjoinÚpaulisÚ	to_labelsr   s     r   r   z&_get_default_label.<locals>.<listcomp>²   s2   € ÐRÐRÐRÀ2˜UŸZšZ¨¬	×(;Ò(;Ñ(=Ô(=Ñ>Ô>ÐRÐRÐRr    z))é   zexp(-it r   ú)rP   )r&   r'   ÚlenrR   rS   rQ   )r   r   s     r   r(   r(   °   s¢   € Ý�(�DÑ!Ô!ð LØVÐRÐRÈÐRÑRÔRÐVÐVÐVˆˆåˆxŒÑÔ 1Ò$Ð$Ø@˜xœ×8Ò8Ñ:Ô:¸1Ô=Ð@Ð@Ð@ˆEˆEð L §
¢
¨8¬?×+DÒ+DÑ+FÔ+FÑ GÔ GÐKÐKÐKˆEà€Lr    )r>   Ú
__future__r   Útypingr   ÚnumpyrJ   Úqiskit.circuit.gater   Úqiskit.circuit.quantumcircuitr   Ú"qiskit.circuit.parameterexpressionr   Úqiskit.quantum_infor   r	   r+   r
   r   r   r(   r   r    r   ú<module>r^      s   ðð 7Ð 6à "Ð "Ð "Ð "Ð "Ð "à  Ð  Ð  Ð  Ð  Ð  Ø Ð Ð Ð à $Ð $Ð $Ð $Ð $Ð $Ø <Ð <Ð <Ð <Ð <Ð <Ø BÐ BÐ BÐ BÐ BÐ BØ 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4àð >Ø=Ð=Ð=Ð=Ð=Ð=ð~5ð ~5ð ~5ð ~5ð ~5˜ñ ~5ô ~5ð ~5ðBð ð ð$
ð 
ð 
ð 
ð 
r    