§
    º³ÙgÉZ  ã                   óP  — d Z ddlZddlZddlmZ ddlZddlmZm	Z	 ddl
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 ddlmZ ddlmZmZmZmZ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,  ej-        e.¦  «        Z/ G d„ de¦  «        Z0de!fd„Z1d„ Z2dS )z;Map a DAGCircuit onto a ``coupling_map`` adding swap gates.é    N)Úinf)Údag_to_circuitÚcircuit_to_dag)ÚexprÚtypes)ÚQuantumRegister)ÚTransformationPass)ÚTranspilerError)Ú
DAGCircuit)ÚSwapGate)ÚLayout)ÚTarget)ÚClbitÚIfElseOpÚWhileLoopOpÚ	ForLoopOpÚSwitchCaseOpÚControlFlowOpÚCASE_DEFAULT)Ústochastic_swap)Únlayout)Údisjoint_utils)Údeprecate_funcé   )Úget_swap_map_dagc                   óx   ‡ — e Zd ZdZ eddd¬¦  «        dˆ fd	„	¦   «         Zd
„ Zd„ Zd„ Zdd„Z	d„ Z
d„ Zd„ Zˆ xZS )ÚStochasticSwapaí  Map a DAGCircuit onto a `coupling_map` adding swap gates.

    Uses a randomized algorithm.

    Notes:
        1. Measurements may occur and be followed by swaps that result in repeated
           measurement of the same qubit. Near-term experiments cannot implement
           these circuits, so some care is required when using this mapper
           with experimental backend targets.

        2. We do not use the fact that the input state is zero to simplify
           the circuit.
    z1.3zin the 2.0 releasezvThe StochasticSwap transpilation pass is a suboptimal routing algorithm and has been superseded by the SabreSwap pass.)ÚsinceÚremoval_timelineÚadditional_msgé   NFc                 ó<  •— t          ¦   «                              ¦   «          t          |t          ¦  «        r&|| _        | j                             ¦   «         | _        nd| _        || _        || _        || _        d| _	        || _
        d| _        || _        d| _        dS )aY  StochasticSwap initializer.

        The coupling map is a connected graph

        If these are not satisfied, the behavior is undefined.

        Args:
            coupling_map (Union[CouplingMap, Target]): Directed graph representing a coupling
                map.
            trials (int): maximum number of iterations to attempt
            seed (int): seed for random number generator
            fake_run (bool): if true, it will only pretend to do routing, i.e., no
                swap is effectively added.
            initial_layout (Layout): starting layout at beginning of pass.
        N)ÚsuperÚ__init__Ú
isinstancer   ÚtargetÚbuild_coupling_mapÚcoupling_mapÚtrialsÚseedÚrngÚfake_runÚqregsÚinitial_layoutÚ_int_to_qubit)Úselfr(   r)   r*   r,   r.   Ú	__class__s         €úf/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/routing/stochastic_swap.pyr$   zStochasticSwap.__init__?   s•   ø€ õ, 	‰Œ×ÒÑÔÐå�l¥FÑ+Ô+ð 	-Ø&ˆDŒKØ $¤× >Ò >Ñ @Ô @ˆDÔÐàˆDŒKØ ,ˆDÔØˆŒØˆŒ	ØˆŒØ ˆŒØˆŒ
Ø,ˆÔØ!ˆÔÐÐó    c                 ó.  — | j         €t          d¦  «        ‚t          |j        ¦  «        dk    s|j                             dd¦  «        €t          d¦  «        ‚t          |j        ¦  «        t          | j         j        ¦  «        k    rt          d¦  «        ‚t          j        || j	        €| j         n| j	        ¦  «         t          j                             | j        ¦  «        | _        |j        d         }| j        €t!          j        |¦  «        | _        t%          |j        ¦  «        | _        |j        | _        t(                               d| j        ¦  «         | j                              ¦   «          |                      || j         | j        ¬¦  «        }|S )	a8  Run the StochasticSwap pass on `dag`.

        Args:
            dag (DAGCircuit): DAG to map.

        Returns:
            DAGCircuit: A mapped DAG.

        Raises:
            TranspilerError: if the coupling map or the layout are not
            compatible with the DAG, or if the coupling_map=None
        Nz0StochasticSwap cannot run with coupling_map=Noner   Úqz-StochasticSwap runs on physical circuits onlyz9The layout does not match the amount of qubits in the DAGz&StochasticSwap rng seeded with seed=%s)r)   )r(   r
   Úlenr-   ÚgetÚqubitsÚphysical_qubitsr   Ú$require_layout_isolated_to_componentr&   ÚnpÚrandomÚdefault_rngr*   r+   r.   r   Úgenerate_trivial_layoutÚtupler/   ÚloggerÚdebugÚcompute_distance_matrixÚ_mapperr)   )r0   ÚdagÚcanonical_registerÚnew_dags       r2   ÚrunzStochasticSwap.rune   s\  € ð ÔÐ$Ý!Ð"TÑUÔUÐUåˆsŒy‰>Œ>˜QÒÐ #¤)§-¢-°°TÑ":Ô":Ð"BÝ!Ð"QÑRÔRÐRåˆsŒz‰?Œ?�S Ô!2Ô!BÑCÔCÒCÐCÝ!Ð"]Ñ^Ô^Ð^ÝÔ;Ø d¤kÐ&9�Ô"Ð"¸t¼{ñ	
ô 	
ð 	
õ ”9×(Ò(¨¬Ñ3Ô3ˆŒà œY sœ^ÐØÔÐ&Ý"(Ô"@ÐASÑ"TÔ"TˆDÔõ # 3¤:Ñ.Ô.ˆÔà”YˆŒ
Ý�ŠÐ=¸t¼yÑIÔIÐIØÔ×1Ò1Ñ3Ô3Ð3Ø—,’,˜s DÔ$5¸d¼k�,ÑJÔJˆØˆr3   c                 ó–  ‡‡‡‡— t                                d|¦  «         t                                d‰                     ¦   «         ¦  «         t                                d|¦  «         t                                d|¦  «         t          t	          ‰¦  «        d¦  «        }g }|D ]Y}	t	          |	¦  «        dk    rt          d¦  «        ‚t	          |	¦  «        dk    r"|                     t          |	¦  «        ¦  «         ŒZt                                d|¦  «         t          ˆˆfd	„|D ¦   «         ¦  «        }
t                                d
|
¦  «         |
t	          |¦  «        k    rCt                                d¦  «         t          ¦   «         }| 
                    |¦  «         d|d‰fS t	          ‰¦  «        }t          }d}dŠd}‰j        dz  }t          j        ˆfd„|D ¦   «         t          j        t	          |¦  «        ¬¦  «        }t          j        ˆfd„|D ¦   «         t          j        dt	          |¦  «        z  ¬¦  «        }ˆfd„‰                     ¦   «                              ¦   «         D ¦   «         }t#          j        ||‰                     ¦   «         ¦  «        }t          ¦   «         }|                     t+          ‰                     ¦   «         ¦  «        ¦  «         t          j        ‰                     ¦   «         t          j        ¬¦  «                             ¦   «         }‰j        }t3          j        ||||||||| j        ¬¦	  «	        \  }}}|€t                                d¦  «         dS |                     ¦   «         }t;          t	          |¦  «        dz  ¦  «        D ]X}| j        |d|z                    }| j        |d|z  dz                     }|                     tA          ¦   «         ||fdd¬¦  «         ŒY|Št                                d¦  «         | !                    ¦   «         }tE          ˆfd„|D ¦   «         ¦  «        }d‰||fS )aË  Find a swap circuit that implements a permutation for this layer.

        The goal is to swap qubits such that qubits in the same two-qubit gates
        are adjacent.

        Based on S. Bravyi's algorithm.

        Args:
            layer_partition (list): The layer_partition is a list of (qu)bit
                lists and each qubit is a tuple (qreg, index).
            layout (Layout): The layout is a Layout object mapping virtual
                qubits in the input circuit to physical qubits in the coupling
                graph. It reflects the current positions of the data.
            qubit_subset (list): The qubit_subset is the set of qubits in
                the coupling graph that we have chosen to map into, as tuples
                (Register, index).
            coupling (CouplingMap): Directed graph representing a coupling map.
                This coupling map should be one that was provided to the
                stochastic mapper.
            trials (int): Number of attempts the randomized algorithm makes.

        Returns:
            Tuple: success_flag, best_circuit, best_depth, best_layout

        If success_flag is True, then best_circuit contains a DAGCircuit with
        the swap circuit, best_depth contains the depth of the swap circuit,
        and best_layout contains the new positions of the data qubits after the
        swap circuit has been applied.

        Raises:
            TranspilerError: if anything went wrong.
        z'layer_permutation: layer_partition = %szlayer_permutation: layout = %sz$layer_permutation: qubit_subset = %szlayer_permutation: trials = %sr5   é   zLayer contains > 2-qubit gateszlayer_permutation: gates = %sc              3   óz   •K  — | ]5}‰j         ‰j        |d                   ‰j        |d                  f         V — Œ6dS )r   r   N)Ú_dist_matrixÚ_v2p)Ú.0ÚgÚcouplingÚlayouts     €€r2   ú	<genexpr>z4StochasticSwap._layer_permutation.<locals>.<genexpr>Â   sG   øè è € Ð^Ð^ÐST�8Ô(¨¬°Q°q´TÔ):¸F¼KÈÈ!ÌÔ<MÐ)MÔNÐ^Ð^Ð^Ð^Ð^Ð^r3   z layer_permutation: distance = %sz layer_permutation: nothing to doTr   Nc              3   óL   •K  — | ]}‰                      |¦  «        j        V — Œd S ©N©Úfind_bitÚindex)rM   ÚbitrD   s     €r2   rQ   z4StochasticSwap._layer_permutation.<locals>.<genexpr>Ó   s2   øè è € Ð=Ð=¨ˆS�\Š\˜#ÑÔÔ$Ð=Ð=Ð=Ð=Ð=Ð=r3   )ÚdtypeÚcountc              3   óV   •K  — | ]#}|D ]}‰                      |¦  «        j        V — ŒŒ$d S rS   rT   )rM   ÚgaterW   rD   s      €r2   rQ   z4StochasticSwap._layer_permutation.<locals>.<genexpr>Ù   s?   øè è € ÐGÐG¨À$ÐGÐG¸3ˆS�\Š\˜#ÑÔÔ$ÐGÐGÐGÐGÐGÐGÐGr3   c                 óL   •— i | ] \  }}‰                      |¦  «        j        |“Œ!S © rT   )rM   ÚkÚvrD   s      €r2   ú
<dictcomp>z5StochasticSwap._layer_permutation.<locals>.<dictcomp>Þ   s,   ø€ ÐaÐaÐa±t°q¸!˜#Ÿ,š, q™/œ/Ô/°ÐaÐaÐar3   )rX   ©r*   zlayer_permutation: failed!)FNNNr   r]   F©Úcheckzlayer_permutation: success!c                 ó2   •— i | ]\  }}‰j         |         |“ŒS r]   )r8   )rM   r^   r_   Úbest_circuits      €r2   r`   z5StochasticSwap._layer_permutation.<locals>.<dictcomp>  s'   ø€ ÐRÐRÐR¹¸!¸Q˜<Ô.¨qÔ1°1ÐRÐRÐRr3   )#r@   rA   Úget_virtual_bitsr   r6   r
   Úappendr?   Úsumr   Úadd_qregr   rK   r;   ÚfromiterÚuint32Úitemsr   ÚNLayoutÚsizeÚ
add_qubitsÚlistÚasarrayÚ	get_edgesÚravelÚstochastic_swap_rsÚswap_trialsr*   ÚedgesÚranger/   Úapply_operation_backr   Úlayout_mappingr   )r0   rD   Úlayer_partitionrP   Úqubit_subsetrO   r)   rE   ÚgatesÚ	gate_argsÚdistÚcircÚ
num_qubitsÚ
best_depthÚ
best_edgesÚbest_layoutÚcdist2Úint_qubit_subsetÚ	int_gatesry   Ú
int_layoutÚtrial_circuitrv   ÚcdistÚidxÚswap_srcÚswap_tgtÚbest_layre   s    ` ` `                      @r2   Ú_layer_permutationz!StochasticSwap._layer_permutationŽ   s+  øøøø€ õB 	�ŠÐ>ÀÑPÔPÐPÝ�ŠÐ5°v×7NÒ7NÑ7PÔ7PÑQÔQÐQÝ�ŠÐ;¸\ÑJÔJÐJÝ�ŠÐ5°vÑ>Ô>Ð>õ -­S°©[¬[¸#Ñ>Ô>ÐàˆØ(ð 	/ð 	/ˆIÝ�9‰~Œ~ Ò!Ð!Ý%Ð&FÑGÔGÐGÝ�9‰~Œ~ Ò"Ð"Ø—’�U 9Ñ-Ô-Ñ.Ô.Ð.øÝ�ŠÐ4°eÑ<Ô<Ð<õ
 Ð^Ð^Ð^Ð^Ð^ÐX]Ð^Ñ^Ô^Ñ^Ô^ˆÝ�ŠÐ7¸Ñ>Ô>Ð>Ø•3�u‘:”:ÒÐÝ�LŠLÐ;Ñ<Ô<Ð<Ý‘<”<ˆDØ�MŠMÐ,Ñ-Ô-Ð-Ø˜˜q &Ð(Ð(õ ˜‘[”[ˆ
Ýˆ
Øˆ
ØˆØˆàÔ&¨Ñ)ˆÝœ;Ø=Ð=Ð=Ð=°Ð=Ñ=Ô=Ý”)Ý�lÑ#Ô#ð
ñ 
ô 
Ðõ ”KØGÐGÐGÐG°ÐGÑGÔGÝ”)Ø•c˜%‘j”j‘.ð
ñ 
ô 
ˆ	ð bÐaÐaÐa¸v×?VÒ?VÑ?XÔ?X×?^Ò?^Ñ?`Ô?`ÐaÑaÔaˆÝ”_ ^°ZÀÇÂÁÄÑQÔQˆ
å"™œˆØ× Ò ¥ f×&=Ò&=Ñ&?Ô&?Ñ!@Ô!@ÑAÔAÐAå”
˜8×-Ò-Ñ/Ô/µr´yÐAÑAÔA×GÒGÑIÔIˆØÔ%ˆÝ.@Ô.LØØØØØØØØØ”ð
/
ñ 
/
ô 
/
Ñ+ˆ
�K ð ÐÝ�LŠLÐ5Ñ6Ô6Ð6Ø*Ð*à× Ò Ñ"Ô"ˆÝ�˜U™œ q™Ñ)Ô)ð 	bð 	bˆCØÔ)¨%°°C±¬.Ô9ˆHØÔ)¨%°°C±¸!±Ô*<Ô=ˆHØ×.Ò.­x©z¬z¸HÀhÐ;OÐQSÐ[`Ð.ÑaÔaÐaÐaØ$ˆõ 	�ŠÐ2Ñ3Ô3Ð3Ø$×3Ò3Ñ5Ô5ˆåÐRÐRÐRÐRÀ>ÐRÑRÔRÑSÔSˆØ�\ :¨xÐ7Ð7r3   c                 ó´  — t                                d|¦  «         t                                d| j        ¦  «         |dk    rFt                                d|¦  «         |                     |t	          |j        ¦  «        d¬¦  «         nt                                d¦  «         |                     |d         |                     |j        ¦  «        d¬¦  «         d	S )
aæ  Add swaps followed by the now mapped layer from the original circuit.

        Args:
            dag (DAGCircuit): The DAGCircuit object that the _mapper method is building
            layer (DAGCircuit): A DAGCircuit layer from the original circuit
            best_layout (Layout): layout returned from _layer_permutation
            best_depth (int): depth returned from _layer_permutation
            best_circuit (DAGCircuit): swap circuit returned from _layer_permutation
        zlayer_update: layout = %sz&layer_update: self.initial_layout = %sr   z5layer_update: there are swaps in this layer, depth %dT©r8   Úinline_capturesz.layer_update: there are no swaps in this layerÚgraphN)r@   rA   r.   Úcomposerp   r8   Úreorder_bits)r0   rD   Úlayerrƒ   r�   re   s         r2   Ú_layer_updatezStochasticSwap._layer_update  sÍ   € õ 	�ŠÐ0°+Ñ>Ô>Ð>Ý�ŠÐ=¸tÔ?RÑSÔSÐSð ˜Š>ˆ>Ý�LŠLÐPÐR\Ñ]Ô]Ð]Ø�KŠK˜­T°,Ô2EÑ-FÔ-FÐX\ˆKÑ]Ô]Ð]Ð]å�LŠLÐIÑJÔJÐJà�ŠØ�'ŒN ;×#;Ò#;¸C¼JÑ#GÔ#GÐY]ð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r3   c           
      ó  — t          |                     ¦   «         ¦  «        }t                               d¦  «         t	          |¦  «        D ]'\  }}t                               d||d         ¦  «         Œ(| j                             ¦   «                              ¦   «         }| j                             ¦   «         }d}	| j	        s| 
                    ¦   «         }	t                               d|¦  «         t	          |¦  «        D �]õ\  }}
|
d                              t          ¬¦  «        sŽ|                      ||
d         ||||¦  «        \  }}}}t                               d|¦  «         t                               d	|t          |¦  «        ¦  «         |r#|}| j	        s|                      |	|
|||¦  «         Œµt                               d
|¦  «         t	          |
d                              ¦   «         ¦  «        D ]ý\  }}|d         }|                     ¦   «         d         }t#          |j        t          ¦  «        r|                      |	|||¦  «        }ŒZ|                      ||d         ||||¦  «        \  }}}}t                               d||¦  «         t                               d|t          |¦  «        ¦  «         |st)          d|› d|› �¦  «        ‚|}| j	        s|                      |	||||¦  «         Œþ�Œ÷t                               d| j        ¦  «         t                               d|¦  «         | j        d         €|| j        d<   n.|                     | j        d         |j        ¦  «        | j        d<   | j	        r|S |	S )a  Map a DAGCircuit onto a CouplingMap using swap gates.

        Args:
            circuit_graph (DAGCircuit): input DAG circuit
            coupling_graph (CouplingMap): coupling graph to map onto
            trials (int): number of trials.

        Returns:
            DAGCircuit: object containing a circuit equivalent to
                circuit_graph that respects couplings in coupling_graph

        Raises:
            TranspilerError: if there was any error during the mapping
                or with the parameters.
        z	schedule:z
    %d: %sÚ	partitionNzlayout = %sr’   )Úopzmapper: layer %dz%mapper: success_flag=%s,best_depth=%sz/mapper: failed, layer %d, retrying sequentiallyr   zmapper: layer %d, sublayer %dz&mapper: success_flag=%s,best_depth=%s,zswap mapper failed: layer z, sublayer z mapper: self.initial_layout = %szmapper: layout = %sÚfinal_layout)rp   Úlayersr@   rA   Ú	enumerater.   rf   ÚkeysÚcopyr,   Úcopy_empty_likeÚop_nodesr   rŽ   Ústrr–   Úserial_layersr%   r™   Ú_controlflow_layer_updater
   Úproperty_setr“   r8   )r0   Úcircuit_graphÚcoupling_graphr)   Ú	layerlistÚir_   r{   rP   Údagcircuit_outputr•   Úsuccess_flagre   r�   rƒ   ÚjÚserial_layerÚ	layer_dagÚop_nodes                      r2   rC   zStochasticSwap._mapper  sÇ  € õ" ˜×-Ò-Ñ/Ô/Ñ0Ô0ˆ	Ý�Š�[Ñ!Ô!Ð!Ý˜iÑ(Ô(ð 	:ð 	:‰DˆAˆqÝ�LŠL˜ q¨!¨K¬.Ñ9Ô9Ð9Ð9àÔ*×;Ò;Ñ=Ô=×BÒBÑDÔDˆð Ô$×)Ò)Ñ+Ô+ˆð !ÐØŒ}ð 	@Ø -× =Ò =Ñ ?Ô ?Ðå�Š�] FÑ+Ô+Ð+õ " )Ñ,Ô,ð ;	ñ ;	‰HˆAˆuà˜”>×*Ò*­mÐ*Ñ<Ô<ð ØFJ×F]ÒF]Ø! 5¨Ô#5°v¸|È^Ð]cñGô GÑC�˜l¨J¸õ —’Ð/°Ñ3Ô3Ð3Ý—’ÐDÀlÕTWÐXbÑTcÔTcÑdÔdÐdØð Ø(�Fð  œ=ð Ø×*Ò*Ø-¨u°kÀ:È|ñô ð ð õ �LŠLÐJÈAÑNÔNÐNå#,¨U°7¬^×-IÒ-IÑ-KÔ-KÑ#LÔ#Lð %ð %‘��<Ø(¨Ô1�	à#×,Ò,Ñ.Ô.¨qÔ1�Ý˜gœj­-Ñ8Ô8ð !Ø!×;Ò;Ø)¨9°f¸mñô �F�Fð MQ×LcÒLcØ%Ø$ [Ô1ØØ$Ø&ØñMô MÑI�\ <°¸[õ —L’LÐ!@À!ÀQÑGÔGÐGÝ—L’LØ@À,ÕPSÐT^ÑP_ÔP_ñô ð ð
 (ð ^Ý-Ð.\È1Ð.\Ð.\ÐYZÐ.\Ð.\Ñ]Ô]Ð]ð )�Fàœ=ð Ø×*Ò*Ø-Ø(Ø'Ø&Ø(ñô ð øñ?%õR 	�ŠÐ7¸Ô9LÑMÔMÐMÝ�ŠÐ*¨FÑ3Ô3Ð3ØÔ˜^Ô,Ð4Ø06ˆDÔ˜nÑ-Ð-à06·²ØÔ! .Ô1°=Ô3Gñ1ô 1ˆDÔ˜nÑ-ð Œ=ð 	!Ø Ð Ø Ð r3   c           
      óª  — |                      ¦   «         d         }t          |j        t          t          t
          t          f¦  «        st          d|› �¦  «        ‚g }g }|j        j        D ]€}|  	                    |¦  «        }	| 
                    |	                     t          |||¦  «        ¦  «        ¦  «         | 
                    |	j        d                              ¦   «         ¦  «         Œ�t          |j        ¦  «        r't!          t#          ||¦  «        d„ ¬¦  «        d         }
n|}
| j        r|
S t'          |j        ¦  «        }t#          ||¦  «        D ]…\  }}t+          || j        ||
|                      ¦   «         ¬¦  «        \  }}|                     d¬¦  «        r|                     ||d	¬
¦  «         |t'          |                     ¦   «         ¦  «        z  }Œ†g }|D ].} |j        |Ž  | 
                    t9          |¦  «        ¦  «         Œ/|j                             |¦  «        }|d         j        }|                     |||j        d¬¦  «         |
S )a]  
        Updates the new dagcircuit with a routed control flow operation.

        Args:
           dagcircuit_output (DAGCircuit): dagcircuit that is being built with routed operations.
           layer_dag (DAGCircuit): layer to route containing a single controlflow operation.
           current_layout (Layout): current layout coming into this layer.
           root_dag (DAGCircuit): root dag of pass

        Returns:
           Layout: updated layout after this layer has been routed.

        Raises:
            TranspilerError: if layer_dag does not contain a recognized ControlFlowOp.

        r   z$unsupported control flow operation: rš   c                 ó:   — | d                               d¬¦  «        S )Nr   T©Úrecurse)Údepth)Úxs    r2   ú<lambda>z:StochasticSwap._controlflow_layer_update.<locals>.<lambda>°  s   € ¸aÀ¼d¿jºjÐQU¸jÑ>VÔ>V€ r3   )Úkeyra   Fr±   Tr�   rb   ) r    r%   r™   r   r   r   r   r
   ÚblocksÚ_recursive_passrg   rG   Ú_dag_from_blockr¤   rž   Ú_controlflow_exhaustive_acyclicÚmaxÚzipr,   Úsetr8   r   r(   Ú	_new_seedrn   r“   Ú
idle_wiresÚremove_qubitsr   Úreplace_blocksrx   Úcargs)r0   r©   r­   Úcurrent_layoutÚroot_dagÚnodeÚ
block_dagsÚblock_layoutsÚblockÚ
inner_passrš   Úidle_qubitsrP   Úupdated_dag_blockÚswap_dagÚswap_qubitsÚblock_circuitsÚnew_opÚ	new_qargss                      r2   r£   z(StochasticSwap._controlflow_layer_updateŒ  s�  € ð" ×!Ò!Ñ#Ô# AÔ&ˆÝ˜$œ'¥H­i½ÅlÐ#SÑTÔTð 	QÝ!Ð"OÈÐ"OÐ"OÑPÔPÐPð ˆ
ØˆØ”W”^ð 	Qð 	QˆEØ×-Ò-¨nÑ=Ô=ˆJØ×Ò˜jŸnšn­_¸UÀDÈ(Ñ-SÔ-SÑTÔTÑUÔUÐUØ× Ò  Ô!8¸Ô!H×!MÒ!MÑ!OÔ!OÑPÔPÐPÐPõ +¨4¬7Ñ3Ô3ð 	*õ Ý�M :Ñ.Ô.Ð4VÐ4Vðñ ô àôˆLˆLð *ˆLØŒ=ð 	 ØÐõ
 ˜(œ/Ñ*Ô*ˆÝ),¨]¸JÑ)GÔ)Gð 	?ð 	?Ñ%ˆFÐ%Ý$4Ø˜$Ô+¨V°\ÈÏÊÑHXÔHXð%ñ %ô %Ñ!ˆH�kð �}Š} Uˆ}Ñ+Ô+ð ^Ø!×)Ò)¨(¸;ÐX\Ð)Ñ]Ô]Ð]Ø�3Ð0×;Ò;Ñ=Ô=Ñ>Ô>Ñ>ˆKˆKð ˆØ!+ð 	Eð 	EÐØ+ÐÔ+¨[Ð9Ð9Ø×!Ò!¥.Ð1BÑ"CÔ"CÑDÔDÐDÐDà”×'Ò'¨Ñ7Ô7ˆØ" 1Ô%Ô,ˆ	Ø×.Ò.¨v°yÀ$Ä*ÐTYÐ.ÑZÔZÐZØÐr3   c                 ó6   — | j                              d¦  «        S )z"Get a seed for a new RNG instance.l   ÿÿÿÿ )r+   Úintegers)r0   s    r2   r¾   zStochasticSwap._new_seedÏ  s   € àŒx× Ò Ð!6Ñ7Ô7Ð7r3   c                 óx   — |                       | j        | j        |                      ¦   «         | j        |¬¦  «        S )z±Get a new instance of this class to handle a recursive call for a control-flow block.

        Each pass starts with its own new seed, determined deterministically from our own.)r)   r*   r,   r.   )r1   r(   r)   r¾   r,   )r0   r.   s     r2   r¸   zStochasticSwap._recursive_passÓ  sA   € ð �~Š~ØÔð ”;Ø—’Ñ!Ô!Ø”]Ø)ð ñ 	
ô 	
ð 		
r3   )r!   NFN)r!   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   rG   rŽ   r–   rC   r£   r¾   r¸   Ú__classcell__)r1   s   @r2   r   r   0   sð   ø€ € € € € ðð ð €^ØØ-ðKðñ ô ð"ð "ð "ð "ð "ñô ð"ð@'ð 'ð 'ðRt8ð t8ð t8ðl
ð 
ð 
ð0n!ð n!ð n!ð n!ð`Að Að AðF8ð 8ð 8ð
ð 
ð 
ð 
ð 
ð 
ð 
r3   r   Ú	operationc                 ó4  — t          | t          ¦  «        rt          | j        ¦  «        dk    S t          | t          ¦  «        rÕ|                      ¦   «         }t          | j        t          j        ¦  «        rS| j        j	        }|j
        t          j        u rd}nd|j
        t          j        u rd|j        z  }nFt          d|› d�¦  «        ‚t          | j        t           ¦  «        rdndt          | j        ¦  «        z  }t"          |v pt          |¦  «        |k    S dS )z˜Return True if the entire control-flow operation represents a block that is guaranteed to be
    entered, and does not cycle back to the initial layout.rI   r   zunhandled target type: 'ú'F)r%   r   r6   r·   r   Úcasesr&   r   ÚExprÚtypeÚkindr   ÚBoolÚUintÚwidthÚRuntimeErrorr   r   )rÙ   rÜ   Útype_Úmax_matchess       r2   rº   rº   ã  s
  € õ �)�XÑ&Ô&ð *Ý�9Ô#Ñ$Ô$¨Ò)Ð)Ý�)�\Ñ*Ô*ð BØ—’Ñ!Ô!ˆÝ�iÔ&­¬	Ñ2Ô2ð 		cØÔ$Ô)ˆEØŒz�UœZÐ'Ð'Ø��Ø”�uœzÐ)Ð)Ø 5¤;Ñ.��å"Ð#F¸eÐ#FÐ#FÐ#FÑGÔGÐGå)¨)Ô*:½EÑBÔBÐb˜!˜!ÈÍSÐQZÔQaÑMbÔMbÑHbˆKÝ˜uÐ$ÐA­¨E©
¬
°kÒ(AÐAØˆ5r3   c           	      ó\  — t          ¦   «         }|j                             ¦   «         D ]}|                     |¦  «         Œ|                     |j        ¦  «         |                      ¦   «         D ]}|                     |¦  «         Œ|                      ¦   «         D ]}| 	                    |¦  «         Œ|  
                    ¦   «         D ]}|                     |¦  «         Œ|                     t          t          j        d¦  «        |                      d¬¦  «        ¦  «        |j        |j        d¬¦  «        }t%          t'          j        t+          | j        |j        ¦  «        t+          | j        |j        ¦  «        ¦  «        ¦  «        }|                     |t3          | ¦  «        |¬¦  «         |S )a  Get a :class:`DAGCircuit` that represents the :class:`.QuantumCircuit` ``block`` embedded
    within the ``root_dag`` for full-width routing purposes.  This means that all the qubits are in
    the output DAG, but only the necessary clbits and classical registers are.TÚcaptures)Ú	vars_modeFrb   )Úwires)r   r-   Úvaluesri   Ú
add_clbitsrÂ   Úiter_input_varsÚadd_input_varÚiter_captured_varsÚadd_captured_varÚiter_declared_varsÚadd_declared_varrx   r   r   ÚliftrŸ   ÚqargsÚdictÚ	itertoolsÚchainr¼   r8   ÚclbitsÚsubstitute_node_with_dagr   )rÈ   rÅ   rÄ   ÚoutÚqregÚvarÚdummyÚwire_maps           r2   r¹   r¹   ø  s™  € õ ‰,Œ,€Cà”×%Ò%Ñ'Ô'ð ð ˆØ�Š�TÑÔÐÐð
 ‡N‚N�4”:ÑÔÐØ×$Ò$Ñ&Ô&ð ð ˆØ×Ò˜#ÑÔÐÐØ×'Ò'Ñ)Ô)ð "ð "ˆØ×Ò˜SÑ!Ô!Ð!Ð!Ø×'Ò'Ñ)Ô)ð "ð "ˆØ×Ò˜SÑ!Ô!Ð!Ð!à×$Ò$Ý•”˜4‘” %×"7Ò"7À*Ð"7Ñ"MÔ"MÑNÔNØŒ
ØŒ
Øð	 %ñ ô €Eõ •I”O¥C¨¬°d´jÑ$AÔ$AÅ3ÀuÄ|ÐUYÔU_ÑC`ÔC`ÑaÔaÑbÔb€HØ× Ò  ­°uÑ(=Ô(=ÀXÐ ÑNÔNÐNØ€Jr3   )3r×   rõ   ÚloggingÚmathr   Únumpyr;   Úqiskit.convertersr   r   Úqiskit.circuit.classicalr   r   Úqiskit.circuit.quantumregisterr   Úqiskit.transpiler.basepassesr	   Úqiskit.transpiler.exceptionsr
   Úqiskit.dagcircuitr   Ú%qiskit.circuit.library.standard_gatesr   Úqiskit.transpiler.layoutr   Úqiskit.transpiler.targetr   Úqiskit.circuitr   r   r   r   r   r   r   Úqiskit._accelerater   rt   r   Úqiskit.transpiler.passes.layoutr   Úqiskit.utilsr   Úutilsr   Ú	getLoggerrÔ   r@   r   rº   r¹   r]   r3   r2   ú<module>r     s   ðð BÐ Aà Ð Ð Ð Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø :Ð :Ð :Ð :Ð :Ð :Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø (Ð (Ð (Ð (Ð (Ð (Ø :Ð :Ð :Ð :Ð :Ð :Ø +Ð +Ð +Ð +Ð +Ð +Ø +Ð +Ð +Ð +Ð +Ð +ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð EÐ DÐ DÐ DÐ DÐ DØ &Ð &Ð &Ð &Ð &Ð &Ø :Ð :Ð :Ð :Ð :Ð :Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à #Ð #Ð #Ð #Ð #Ð #à	ˆÔ	˜8Ñ	$Ô	$€ðp
ð p
ð p
ð p
ð p
Ð'ñ p
ô p
ð p
ðf¨}ð ð ð ð ð*ð ð ð ð r3   