§
    º³ÙgÄ  ã                   ó‚   — d Z ddlmZmZ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 ddlmZ  G d	„ d
e
¦  «        ZdS )zG
A generic InverseCancellation pass for any set of gate-inverse pairs.
é    )ÚListÚTupleÚUnion)ÚGate)Ú
DAGCircuit)ÚTransformationPass)ÚTranspilerError)Úcontrol_flow)Úinverse_cancellationc                   óz   ‡ — e Zd ZdZdeeeeeef         f                  fˆ fd„Ze	j
        defd„¦   «         Zˆ xZS )ÚInverseCancellationzYCancel specific Gates which are inverses of each other when they occur back-to-
    back.Úgates_to_cancelc                 óÀ  •— |D ]ó}t          |t          ¦  «        r1||                     ¦   «         k    rt          d|j        › d�¦  «        ‚ŒHt          |t
          ¦  «        rwt          |¦  «        dk    rt          d|› d�¦  «        ‚|d         |d                              ¦   «         k    r,t          d|d         j        › d|d         j        › d	�¦  «        ‚ŒÔt          d
t          |¦  «        › d�¦  «        ‚g | _        g | _	        t          ¦   «         | _        t          ¦   «         | _        |D ]�}t          |t          ¦  «        r:| j                             |¦  «         | j                             |j        ¦  «         ŒQ| j	                             |¦  «         | j                             d„ |D ¦   «         ¦  «         Œ�t!          ¦   «                              ¦   «          dS )aá  Initialize InverseCancellation pass.

        Args:
            gates_to_cancel: List describing the gates to cancel. Each element of the
                list is either a single gate or a pair of gates. If a single gate, then
                it should be self-inverse. If a pair of gates, then the gates in the
                pair should be inverses of each other.

        Raises:
            TranspilerError: Input is not a self-inverse gate or a pair of inverse gates.
        zGate z is not self-inverseé   zToo many or too few inputs: z. Only two are allowed.r   é   z and z are not inverse.z2InverseCancellation pass does not take input type z. Input must be a Gate.c              3   ó$   K  — | ]}|j         V — Œd S )N)Úname)Ú.0Úxs     úp/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/optimization/inverse_cancellation.pyú	<genexpr>z/InverseCancellation.__init__.<locals>.<genexpr>J   s$   è è € Ð4KÐ4KÀ°Q´VÐ4KÐ4KÐ4KÐ4KÐ4KÐ4Kó    N)Ú
isinstancer   Úinverser	   r   ÚtupleÚlenÚtypeÚself_inverse_gatesÚinverse_gate_pairsÚsetÚself_inverse_gate_namesÚinverse_gate_pairs_namesÚappendÚaddÚupdateÚsuperÚ__init__)Úselfr   ÚgatesÚ	__class__s      €r   r'   zInverseCancellation.__init__   s  ø€ ð %ð 	ð 	ˆEÝ˜%¥Ñ&Ô&ð Ø˜EŸMšM™OœOÒ+Ð+Ý)Ð*R°%´*Ð*RÐ*RÐ*RÑSÔSÐSð ,å˜E¥5Ñ)Ô)ð Ý�u‘:”: ’?�?Ý)ØU°uÐUÐUÐUñô ð ð ˜”8˜u Qœx×/Ò/Ñ1Ô1Ò1Ð1Ý)ØT  a¤¤ÐTÐT°E¸!´H´MÐTÐTÐTñô ð ð 2õ
 &ðÍÈeÉÌð ð ð ñô ð ð
 #%ˆÔØ"$ˆÔÝ'*¡u¤uˆÔ$Ý(+©¬ˆÔ%à$ð 	Lð 	LˆEÝ˜%¥Ñ&Ô&ð LØÔ'×.Ò.¨uÑ5Ô5Ð5ØÔ,×0Ò0°´Ñ<Ô<Ð<Ð<àÔ'×.Ò.¨uÑ5Ô5Ð5ØÔ-×4Ò4Ð4KÐ4KÀUÐ4KÑ4KÔ4KÑKÔKÐKÐKå‰Œ×ÒÑÔÐÐÐr   Údagc                 óT   — t          || j        | j        | j        | j        ¦  «         |S )z´Run the InverseCancellation pass on `dag`.

        Args:
            dag: the directed acyclic graph to run on.

        Returns:
            DAGCircuit: Transformed DAG.
        )r   r   r   r"   r!   )r(   r+   s     r   ÚrunzInverseCancellation.runN   s8   € õ 	ØØÔ#ØÔ#ØÔ)ØÔ(ñ	
ô 	
ð 	
ð ˆ
r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r'   r
   Útrivial_recurser   r-   Ú__classcell__)r*   s   @r   r   r      s’   ø€ € € € € ðð ð-¨¨U°4¸¸tÀT¸zÔ9JÐ3JÔ-KÔ(Lð -ð -ð -ð -ð -ð -ð^ Ô!ð�zð ð ð ñ "Ô!ðð ð ð ð r   r   N)r1   Útypingr   r   r   Úqiskit.circuitr   Úqiskit.dagcircuitr   Úqiskit.transpiler.basepassesr   Úqiskit.transpiler.exceptionsr	   Úqiskit.transpiler.passes.utilsr
   Ú'qiskit._accelerate.inverse_cancellationr   r   © r   r   ú<module>r<      sÚ   ððð ð &Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %à Ð Ð Ð Ð Ð Ø (Ð (Ð (Ð (Ð (Ð (Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7à HÐ HÐ HÐ HÐ HÐ HðDð Dð Dð Dð DÐ,ñ Dô Dð Dð Dð Dr   