
    z	i                        S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJrJr  \" S
5      r\" S5      r S       SS jjrSS jrg)z;Utility functions shared between permutation functionality.    )annotations)Iterable)TypeVarMutableMapping)QuantumRegister)
DAGCircuit)SwapGate   )SwapPermutationCircuit_K_Vc                    U  Ho  nU Hf  u  pESnSnU(       a%  UR                  US5      nUR                  US5      nO!UR                  U5      UR                  U5      pvUb  XaU'   Uc  Mb  XqU'   Mh     Mq     g)a   Given a circuit of swaps, apply them to the permutation (in-place).

Args:
  swaps: param mapping: A mapping of Keys to Values, where the Keys are being swapped.
  mapping: The permutation to have swaps applied to.
  allow_missing_keys: Whether to allow swaps of missing keys in mapping.
N)pop)swapsmappingallow_missing_keys	swap_stepsw1sw2val1val2s           j/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/routing/algorithms/util.pyswap_permutationr   ,   s|     	!HC"D"D!{{3-{{3- %[[-w{{3/?d## "     c                   [        5       n[        U 5      nU VVVs1 s H  o3  H  oD  H  oUiM     M     M     nnnnU Vs0 s H  ow[        S5      _M     nnUR                  5        H  n	UR	                  U	5        M     UR                  5        VV
s0 s H
  u  pzXzS   _M     nnn
U H-  nU H$  u  pUR                  [        5       X   X   4SS9  M&     M/     [        X5      $ s  snnnf s  snf s  sn
nf )ak  Produce a circuit description of a list of swaps.
    With a given permutation and permuter you can compute the swaps using the permuter function
    then feed it into this circuit function to obtain a circuit description.
Args:
  swaps: An iterable of swaps to perform.
Returns:
  A MappingCircuit with the circuit and a mapping of node to qubit in the circuit.
r
   r   F)check)	r   listr   valuesadd_qregitemsapply_operation_backr	   r   )r   dag	swap_listr   
swap_nodes	swap_nodenodesnode
node_qargsqubitqinputmapswap0swap1s                 r   permutation_circuitr/   J   s     ,CUI $-#,iyZdY	Zd	y	9 
  8==ut**uJ=""$U % +5*:*:*<=*<wtd
*<H= 	%LE$$XZ(/8?1S[`$a &  c,, > >s   C%C,C1N)F)r   zIterable[Iterable[Swap[_K]]]r   zMutableMapping[_K, _V]r   boolreturnNone)r   zIterable[list[Swap[_V]]]r1   r   )__doc__
__future__r   collections.abcr   typingr   r   qiskit.circuitr   qiskit.dagcircuitr   %qiskit.circuit.library.standard_gatesr	   typesr   r   r   r   r   r/    r   r   <module>r<      se   6 B " $ * * ( : +T]T]  %$'$#$ $ 
	$<-r   