
    z	i                     n    S r SSKrSSKJr  SSKJr  SSKJr  \R                  " \
5      r " S S\5      rg)zTRemove any swap gates in the circuit by pushing it through into a qubit permutation.    N)TransformationPass)Layout)elide_permutationsc                       \ rS rSrSrS rSrg)ElidePermutations   a  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                    U R                   S   b  [        R                  S5        U$ [        R                  " U5      nUc  U$ Uu  p4[        UR                  5       VVs0 s H  u  pVXe_M	     nnn[        U5      U R                   S'   U R                   S   c  XpR                   S'   [        [        U5       VV	s0 s H  u  pUR                  U	   U_M     sn	n5      n
U R                   S   =n(       aO  U
R                  UR                  UR                  UR                  5      UR                  5      U R                   S'   U$ XR                   S'   U$ s  snnf s  sn	nf )zRun the ElidePermutations pass on ``dag``.

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

Returns:
    DAGCircuit: the optimized DAG.
layoutzpElidePermutations is not valid after a layout has been set. This indicates an invalid pass manager construction.original_layoutoriginal_qubit_indicesvirtual_permutation_layout)
property_setloggerwarningelide_permutations_rsrun	enumeratequbitsr   composeinverse)selfdagresultnew_dagqubit_mappingindexqubitinput_qubit_mappingidxout
new_layoutcurrent_layouts               r/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/optimization/elide_permutations.pyr   ElidePermutations.run5   sY    X&2NN8 J&**3/ >J $* @I#**@UV@Uu|@UV/56I/J+,56>:M67)MBZ[BZhcSZZ_c1BZ[\
!../KLL>L>H>P>P&&szz3::>

?D:;
  ?I:; W
 \s   E9E
 N)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__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      s6    [  ; + J			8	$B* Br,   