§
    º³Ùg×  ã                   ór   — d Z ddlZddlmZ ddlmZ ddlmZ  ej	        e
¦  «        Z G d„ de¦  «        ZdS )zTRemove any swap gates in the circuit by pushing it through into a qubit permutation.é    N)ÚTransformationPass)ÚLayout)Úelide_permutationsc                   ó   — e Zd ZdZd„ ZdS )ÚElidePermutationsa[  Remove permutation operations from a pre-layout circuit

    This pass is intended to be run before a layout (mapping virtual qubits
    to physical qubits) is set during the transpilation pipeline. This
    pass iterates over the :class:`~.DAGCircuit` and when a :class:`~.SwapGate`
    or :class:`~.PermutationGate` are encountered it permutes the virtual qubits in
    the circuit and removes the swap gate. This will effectively remove any
    :class:`~SwapGate`\s or :class:`~PermutationGate` in the circuit prior to running
    layout. If this pass is run after a layout has been set it will become a no-op
    (and log a warning) as this optimization is not sound after physical qubits are
    selected and there are connectivity constraints to adhere to.

    For tracking purposes this pass sets 3 values in the property set if there
    are any :class:`~.SwapGate` or :class:`~.PermutationGate` objects in the circuit
    and the pass isn't a no-op.

    * ``original_layout``: The trivial :class:`~.Layout` for the input to this pass being run
    * ``original_qubit_indices``: The mapping of qubit objects to positional indices for the state
        of the circuit as input to this pass.
    * ``virtual_permutation_layout``: A :class:`~.Layout` object mapping input qubits to the output
        state after eliding permutations.

    These three properties are needed for the transpiler to track the permutations in the out
    :attr:`.QuantumCircuit.layout` attribute. The elision of permutations is equivalent to a
    ``final_layout`` set by routing and all three of these attributes are needed in the case
    c                 ó2  ‡— | j         d         �t                               d¦  «         ‰S t          j        ‰¦  «        }|€‰S |\  }}d„ t          ‰j        ¦  «        D ¦   «         }t          |¦  «        | j         d<   | j         d         €
|| j         d<   t          ˆfd„t          |¦  «        D ¦   «         ¦  «        }| j         d         x}rB|                     | 	                    ‰j        ‰j        ¦  «        ‰j        ¦  «        | j         d<   n
|| j         d<   |S )	z¶Run the ElidePermutations pass on ``dag``.

        Args:
            dag (DAGCircuit): the DAG to be optimized.

        Returns:
            DAGCircuit: the optimized DAG.
        ÚlayoutNzpElidePermutations is not valid after a layout has been set. This indicates an invalid pass manager construction.c                 ó   — i | ]\  }}||“Œ	S © r   )Ú.0ÚindexÚqubits      ún/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/optimization/elide_permutations.pyú
<dictcomp>z)ElidePermutations.run.<locals>.<dictcomp>O   s   € ÐVÐVÐV±°°u˜u eÐVÐVÐVó    Úoriginal_layoutÚoriginal_qubit_indicesc                 ó2   •— i | ]\  }}‰j         |         |“ŒS r   )Úqubits)r   ÚidxÚoutÚdags      €r   r   z)ElidePermutations.run.<locals>.<dictcomp>T   s%   ø€ Ð[Ð[Ð[±h°c¸3˜SœZ¨œ_¨cÐ[Ð[Ð[r   Úvirtual_permutation_layout)
Úproperty_setÚloggerÚwarningÚelide_permutations_rsÚrunÚ	enumerater   r   ÚcomposeÚinverse)Úselfr   ÚresultÚnew_dagÚqubit_mappingÚinput_qubit_mappingÚ
new_layoutÚcurrent_layouts    `      r   r   zElidePermutations.run5   sB  ø€ ð Ô˜XÔ&Ð2Ý�NŠNð8ñô ð ð ˆJå&Ô*¨3Ñ/Ô/ˆð ˆ>ØˆJð $*Ñ ˆ�-àVÐVÅ	È#Ì*Ñ@UÔ@UÐVÑVÔVÐÝ/5Ð6IÑ/JÔ/JˆÔÐ+Ñ,ØÔÐ5Ô6Ð>Ø:MˆDÔÐ6Ñ7åÐ[Ð[Ð[Ð[Å)ÈMÑBZÔBZÐ[Ñ[Ô[Ñ\Ô\ˆ
Ø!Ô.Ð/KÔLÐLˆ>ð 	IØ>H×>PÒ>PØ×&Ò& s¤z°3´:Ñ>Ô>ÀÄ
ñ?ô ?ˆDÔÐ:Ñ;Ð;ð ?IˆDÔÐ:Ñ;Øˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s-   € € € € € ðð ð6&ð &ð &ð &ð &r   r   )r,   ÚloggingÚqiskit.transpiler.basepassesr   Úqiskit.transpiler.layoutr   Úqiskit._accelerater   r   Ú	getLoggerr)   r   r   r   r   r   ú<module>r2      sž   ðð [Ð Zà €€€à ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø +Ð +Ð +Ð +Ð +Ð +Ø JÐ JÐ JÐ JÐ JÐ Jà	ˆÔ	˜8Ñ	$Ô	$€ðBð Bð Bð Bð BÐ*ñ Bô Bð Bð Bð Br   