§
    º³Ùgù[  ã                   óš  — d Z ddlZddlZddlZddlZddlZddlZddl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 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( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1  ej2        e3¦  «        Z4 G d„ de¦  «        Z5ej6         G d„ d¦  «        ¦   «         Z7dS )zNLayout selection using the SABRE bidirectional search approach from Li et al.
é    N)Údag_to_circuit)ÚQuantumRegister)Ú
DAGCircuit)Ú	SetLayout)ÚFullAncillaAllocation)ÚEnlargeWithAncilla)ÚApplyLayout)Údisjoint_utils)ÚPassManager)ÚLayout)ÚTransformationPass)ÚTranspilerError)ÚNLayout)Úsabre_layout_and_routingÚ	HeuristicÚNeighborTableÚ
SetScaling)Ú_build_sabre_dagÚ_apply_sabre_result)ÚTarget)ÚCouplingMap)Ú	CPU_COUNTc                   óP   ‡ — e Zd ZdZ	 	 	 	 	 	 dˆ fd„	Zd„ Zdd„Zd„ Zd	„ Zd
„ Z	ˆ xZ
S )ÚSabreLayouta  Choose a Layout via iterative bidirectional routing of the input circuit.

    Starting with a random initial `Layout`, the algorithm does a full routing
    of the circuit (via the `routing_pass` method) to end up with a
    `final_layout`. This final_layout is then used as the initial_layout for
    routing the reverse circuit. The algorithm iterates a number of times until
    it finds an initial_layout that reduces full routing cost.

    This method exploits the reversibility of quantum circuits, and tries to
    include global circuit information in the choice of initial_layout.

    By default, this pass will run both layout and routing and will transform the
    circuit so that the layout is applied to the input dag (meaning that the output
    circuit will have ancilla qubits allocated for unused qubits on the coupling map
    and the qubits will be reordered to match the mapped physical qubits) and then
    routing will be applied (inserting :class:`~.SwapGate`s to account for limited
    connectivity). This is unlike most other layout passes which are :class:`~.AnalysisPass`
    objects and just find an initial layout and set that on the property set. This is
    done because by default the pass will run parallel seed trials with different random
    seeds for selecting the random initial layout and then selecting the routed output
    which results in the least number of swap gates needed.

    You can use the ``routing_pass`` argument to have this pass operate as a typical
    layout pass. When specified this will use the specified routing pass to select an
    initial layout only and will not run multiple seed trials.

    In addition to starting with a random initial `Layout` the pass can also take in
    an additional list of starting layouts which will be used for additional
    trials. If the ``sabre_starting_layouts`` is present in the property set
    when this pass is run, that will be used for additional trials. There will still
    be ``layout_trials`` of full random starting layouts run and the contents of
    ``sabre_starting_layouts`` will be run in addition to those. The output which results
    in the lowest amount of swap gates (whether from the random trials or the property
    set starting point) will be used. The value for this property set field should be a
    list of :class:`.Layout` objects representing the starting layouts to use. If a
    virtual qubit is missing from an :class:`.Layout` object in the list a random qubit
    will be selected.

    Property Set Fields Read
    ------------------------

    ``sabre_starting_layouts`` (``list[Layout]``)
        An optional list of :class:`~.Layout` objects to use for additional layout trials. This is
        in addition to the full random trials specified with the ``layout_trials`` argument.

    Property Set Values Written
    ---------------------------

    ``layout`` (:class:`.Layout`)
        The chosen initial mapping of virtual to physical qubits, including the ancilla allocation.

    ``final_layout`` (:class:`.Layout`)
        A permutation of how swaps have been applied to the input qubits at the end of the circuit.

    **References:**

    [1] Henry Zou and Matthew Treinish and Kevin Hartman and Alexander Ivrii and Jake Lishman.
    "LightSABRE: A Lightweight and Enhanced SABRE Algorithm"
    `arXiv:2409.08368 <https://doi.org/10.48550/arXiv.2409.08368>`__
    [2] Li, Gushu, Yufei Ding, and Yuan Xie. "Tackling the qubit mapping problem
    for NISQ-era quantum devices." ASPLOS 2019.
    `arXiv:1809.02573 <https://arxiv.org/pdf/1809.02573.pdf>`_
    Né   Fc                 óÒ  •— t          ¦   «                              ¦   «          t          |t          ¦  «        r&|| _        | j                             ¦   «         | _        nd| _        || _        d| _        |�|€|�t          d¦  «        ‚|| _	        || _
        || _        || _        |€t          | _        n|| _        |€t          | _        n|| _        || _        | j        �Š| j        j        sLt          |t$          ¦  «        rt'          j        | j        ¦  «        | _        | j                             ¦   «          t-          t/          j        | j        j        ¦  «        ¦  «        | _        dS dS )a  SabreLayout initializer.

        Args:
            coupling_map (Union[CouplingMap, Target]): directed graph representing a coupling map.
            routing_pass (BasePass): the routing pass to use while iterating.
                If specified this pass operates as an :class:`~.AnalysisPass` and
                will only populate the ``layout`` field in the property set and
                the input dag is returned unmodified. This argument is mutually
                exclusive with the ``swap_trials`` and the ``layout_trials``
                arguments and if this is specified at the same time as either
                argument an error will be raised.
            seed (int): seed for setting a random first trial layout.
            max_iterations (int): number of forward-backward iterations.
            swap_trials (int): The number of trials to run of
                :class:`~.SabreSwap` for each iteration. This is equivalent to
                the ``trials`` argument on :class:`~.SabreSwap`. If this is not
                specified (and ``routing_pass`` isn't set) by default the number
                of physical CPUs on your local system will be used. For
                reproducibility between environments it is best to set this
                to an explicit number because the output will potentially depend
                on the number of trials run. This option is mutually exclusive
                with the ``routing_pass`` argument and an error will be raised
                if both are used.
            layout_trials (int): The number of random seed trials to run
                layout with. When > 1 the trial that results in the output with
                the fewest swap gates will be selected. If this is not specified
                (and ``routing_pass`` is not set) then the number of local
                physical CPUs will be used as the default value. This option is
                mutually exclusive with the ``routing_pass`` argument and an error
                will be raised if both are used. An additional 3 or 4 trials
                depending on the ``coupling_map`` value are run with common layouts
                on top of the random trial count specified by this value.
            skip_routing (bool): If this is set ``True`` and ``routing_pass`` is not used
                then routing will not be applied to the output circuit.  Only the layout
                will be set in the property set. This is a tradeoff to run custom
                routing with multiple layout trials, as using this option will cause
                SabreLayout to run the routing stage internally but not use that result.

        Raises:
            TranspilerError: If both ``routing_pass`` and ``swap_trials`` or
            both ``routing_pass`` and ``layout_trials`` are specified
        Nz?Both routing_pass and swap_trials can't be set at the same time)ÚsuperÚ__init__Ú
isinstancer   ÚtargetÚbuild_coupling_mapÚcoupling_mapÚ_neighbor_tabler   Úrouting_passÚseedÚmax_iterationsÚtrialsr   Úswap_trialsÚlayout_trialsÚskip_routingÚis_symmetricr   ÚcopyÚdeepcopyÚmake_symmetricr   ÚrxÚadjacency_matrixÚgraph)	Úselfr"   r$   r%   r&   r(   r)   r*   Ú	__class__s	           €úb/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/layout/sabre_layout.pyr   zSabreLayout.__init__p   sa  ø€ õh 	‰Œ×ÒÑÔÐÝ�l¥FÑ+Ô+ð 	-Ø&ˆDŒKØ $¤× >Ò >Ñ @Ô @ˆDÔÐàˆDŒKØ ,ˆDÔØ#ˆÔØÐ#¨Ð)@ÀMÐD]Ý!Ð"cÑdÔdÐdØ(ˆÔØˆŒ	Ø,ˆÔØ!ˆŒØÐÝ(ˆDÔÐà*ˆDÔØÐ Ý!*ˆDÔÐà!.ˆDÔØ(ˆÔØÔÐ(ØÔ$Ô1ð 3õ ˜l­KÑ8Ô8ð IÝ(,¬°dÔ6GÑ(HÔ(H�DÔ%ØÔ!×0Ò0Ñ2Ô2Ð2Ý#0µÔ1DÀTÔEVÔE\Ñ1]Ô1]Ñ#^Ô#^ˆDÔ Ð Ð ð )Ð(ó    c                 ó4  ‡‡‡‡‡— t          ‰j        ¦  «        | j                             ¦   «         k    rt	          d¦  «        ‚| j        ��6| j                             ¦   «         st	          d¦  «        ‚| j        €Bt          j	         
                    dt          j        t          j        ¦  «        j        ¦  «        }n| j        }t          j	                             |¦  «        }|                     | j                             ¦   «         t          ‰j        ¦  «        d¬¦  «        }|                     |¦  «        }t#          ˆfd„t%          |¦  «        D ¦   «         ¦  «        }d| j        _        t)          ‰¦  «        }|                     ¦   «         }t-          | j        ¦  «        D ]”}d	D ][}|                      |¦  «        }	|	                     |¦  «        }
|	j        d
         }|                      |||
j        ¦  «        }|}||}}Œ\t:                               d¦  «         t:                               |¦  «         Œ•‰j                             ¦   «         D ]}|                      |¦  «         Œ|| j        d<   d| j        _        ‰S | j!        �0| j!         "                    d¬¦  «        }| #                    ¦   «          n| j        }| j$        }d| j        v r&tK          j&        | j$        | j        d         ¬¦  «        }tO          j(        ‰||¦  «        }t#          d„ |D ¦   «         ¦  «        | j        d<   ‰j                             ¦   «         D ]"}| j        d                               |¦  «         Œ#| j)        st          |¦  «        dk    r‰S |  *                    ‰¦  «        Š| j        d         ŠtW          | j                             ¦   «         d¦  «        }tY          ¦   «         Š‰ -                    |¦  «         ‰ .                    ‰j/        ¦  «         ‰j0                             ¦   «         D ]}‰ 1                    |¦  «         Œ‰ 2                    ¦   «         D ]}‰ 3                    |¦  «         Œ‰ 4                    ¦   «         D ]}‰ 5                    |¦  «         Œ‰ 6                    ¦   «         D ]}‰ 7                    |¦  «         Œ‰j8        ‰_8        d„ t%          ‰j        ¦  «        D ¦   «         | j        d<   t#          ˆfd„|D ¦   «         ¦  «        }t          |¦  «        t          |¦  «        k    r+d„ |D ¦   «         }t%          |¦  «        D ]\  }}||v rŒ
|||<   Œ| j        d
         €|| j        d
<   n.| 9                    | j        d
         ‰j        ¦  «        | j        d
<   |D ]áŠ‰j                             ¦   «         }‰j:         ;                    ¦   «         }||k    reˆfd„‰j:        j        D ¦   «         Š‰j:         <                    ˆˆˆfd„t-          ‰j:         ;                    ¦   «         |¦  «        D ¦   «         ¦  «         t{          ‰‰j:        ‰j>        ‰j?        ˆˆfd„t-          |¦  «        D ¦   «         ‰j@        ¦  «        ŠŒâtO          jA        ‰d¬¦  «         ‰S )aP  Run the SabreLayout pass on `dag`.

        Args:
            dag (DAGCircuit): DAG to find layout for.

        Returns:
           DAGCircuit: The output dag if swap mapping was run
            (otherwise the input dag is returned unmodified).

        Raises:
            TranspilerError: if dag wider than self.coupling_map
        z(More virtual qubits exist than physical.NzEThe routing_pass argument cannot be used with disjoint coupling maps.r   F)Úreplacec                 ó2   •— i | ]\  }}|‰j         |         “ŒS © )Úqubits)Ú.0ÚiÚqÚdags      €r4   ú
<dictcomp>z#SabreLayout.run.<locals>.<dictcomp>ã   s%   ø€ Ð$]Ð$]Ð$]¹$¸!¸Q Q¨¬
°1¬Ð$]Ð$]Ð$]r5   T)ÚforwardÚbackwardÚfinal_layoutznew initial layoutÚlayout)Úfilter_idle_qubitsÚsabre_starting_layouts)Ústarting_layoutsc                 óÌ   — i | ]a}|j                              ¦   «         D ]E\  }}|t          |j        j        ¦  «        k     ¯"|j        j        |         |j        j        |         “ŒFŒbS r9   )Úinitial_layoutÚlayout_mappingÚlenr>   r:   r"   r1   )r;   Ú	componentÚlogicÚphyss       r4   r?   z#SabreLayout.run.<locals>.<dictcomp>  s}   € ð ð ð àØ#,Ô#;×#JÒ#JÑ#LÔ#Lðð ñ  �E˜4ð �3˜yœ}Ô3Ñ4Ô4Ò4Ð4ð ”Ô$ UÔ+¨YÔ-CÔ-IÈ$Ô-Oð 5Ð4Ð4Ð4r5   é   r=   c                 ó   — i | ]\  }}||“Œ	S r9   r9   ©r;   ÚindexÚbits      r4   r?   z#SabreLayout.run.<locals>.<dictcomp>?  s+   € ð 7
ð 7
ð 7
Ù%˜5 #ˆC�ð7
ð 7
ð 7
r5   Úoriginal_qubit_indicesc                 ó    •— i | ]J}t          |j        ¦  «        D ]3\  }}‰j        |j        j        |                  |j        j        |         “Œ4ŒKS r9   )Ú	enumerateÚfinal_permutationr:   r"   r1   )r;   rK   ÚinitialÚfinalÚ
mapped_dags       €r4   r?   z#SabreLayout.run.<locals>.<dictcomp>C  su   ø€ ð ð ð ð Ý&/°	Ô0KÑ&LÔ&Lðð ñ
 #�G˜Uð	 Ô!ØÔ*Ô0°Ô9ôàÔ)Ô/°Ô6ðð ð ð r5   c                 óT   — h | ]%}|j         j                             ¦   «         D ]}|’ŒŒ&S r9   )r"   r1   Únodes)r;   rK   Úqubits      r4   ú	<setcomp>z"SabreLayout.run.<locals>.<setcomp>P  sK   € ð ð ð Ø#¸yÔ?UÔ?[×?aÒ?aÑ?cÔ?cðð Ø6;�ðð ð ð r5   c                 ó    •— h | ]
}‰|         ’ŒS r9   r9   )r;   rL   Úfull_initial_layouts     €r4   r]   z"SabreLayout.run.<locals>.<setcomp>f  s   ø€ Ð ^Ð ^Ð ^ÀÐ!4°UÔ!;Ð ^Ð ^Ð ^r5   c                 óh   •— g | ].}‰j         j        |         ‰v¯‰‰j         j        |                  ‘Œ/S r9   )r"   r1   )r;   rM   rK   r_   Úused_physicals     €€€r4   ú
<listcomp>z#SabreLayout.run.<locals>.<listcomp>h  sI   ø€ ð ð ð à Ø$Ô1Ô7¸Ô=À]ÐRÐRð ,¨IÔ,BÔ,HÈÔ,NÔOàRÐRÐRr5   c                 óJ   •— g | ]}‰j         ‰j        j        |                  ‘Œ S r9   )r:   r"   r1   )r;   rM   rK   rY   s     €€r4   rb   z#SabreLayout.run.<locals>.<listcomp>s  s<   ø€ ð ð ð àð Ô% iÔ&<Ô&BÀ4Ô&HÔIðð ð r5   )Úretain_uuid)BrJ   r:   r"   Úsizer   r$   Úis_connectedr%   ÚnpÚrandomÚrandintÚiinfoÚint32ÚmaxÚdefault_rngÚchoiceÚpermutationr   rU   Úfake_runr   Úreverse_opsÚranger&   Ú_layout_and_route_passmanagerÚrunÚproperty_setÚ_compose_layoutsÚqregsÚloggerÚinfoÚvaluesÚadd_registerr    r!   r.   Ú
_inner_runÚ	functoolsÚpartialr
   Ú"run_pass_over_connected_componentsr*   Ú#_ancilla_allocation_no_pass_managerr   r   Úadd_qregÚ
add_clbitsÚclbitsÚcregsÚadd_cregÚiter_input_varsÚadd_input_varÚiter_captured_varsÚadd_captured_varÚiter_declared_varsÚadd_declared_varÚglobal_phaseÚcomposer>   Ú
num_qubitsÚ
add_qubitsr   Úsabre_resultrH   Úcircuit_to_dag_dictÚcombine_barriers)r2   r>   r%   ÚrngÚphysical_qubitsrH   ÚcircÚrev_circÚ_ÚpmÚnew_circÚpass_final_layoutrB   Úqregr    Ú	inner_runÚ
componentsÚcregÚvarÚused_qubitsrQ   r\   Úcomponent_sizeÚdag_sizerK   r_   rY   ra   s    `                      @@@@r4   rt   zSabreLayout.runÅ   s6  øøøøø€ õ ˆsŒz‰?Œ?˜TÔ.×3Ò3Ñ5Ô5Ò5Ð5Ý!Ð"LÑMÔMÐMð ÔÑ(ØÔ$×1Ò1Ñ3Ô3ð Ý%Ø[ñô ð ð ŒyÐ Ý”y×(Ò(¨­B¬HµR´XÑ,>Ô,>Ô,BÑCÔC��à”y�Ý”)×'Ò'¨Ñ-Ô-ˆCà!Ÿjšj¨Ô):×)?Ò)?Ñ)AÔ)AÅ3ÀsÄzÁ?Ä?Ð\a˜jÑbÔbˆOØ!Ÿošo¨oÑ>Ô>ˆOÝ#Ð$]Ð$]Ð$]Ð$]Å)ÈOÑB\ÔB\Ð$]Ñ$]Ô$]Ñ^Ô^ˆNà)-ˆDÔÔ&õ " #Ñ&Ô&ˆDØ×'Ò'Ñ)Ô)ˆHÝ˜4Ô.Ñ/Ô/ð ,ð ,�Ø0ð 
4ð 
4�AØ×;Ò;¸NÑKÔK�BØ!Ÿvšv d™|œ|�Hð )+¬¸Ô(GÐ%Ø#'×#8Ò#8Ø&Ð(9¸8¼>ñ$ô $�Lð &2�NØ%-¨t˜(�D�Dõ —’Ð0Ñ1Ô1Ð1Ý—’˜NÑ+Ô+Ð+Ð+àœ	×(Ò(Ñ*Ô*ð 2ð 2�Ø×+Ò+¨DÑ1Ô1Ð1Ð1Ø*8ˆDÔ˜hÑ'Ø).ˆDÔÔ&ØˆJàŒ;Ð"ð ”[×3Ò3ÀtÐ3ÑLÔLˆFØ×!Ò!Ñ#Ô#Ð#Ð#àÔ&ˆFØ”Oˆ	Ø# tÔ'8Ð8Ð8Ý!Ô)Ø”°$Ô2CÐD\Ô2]ðñ ô ˆIõ $ÔFÀsÈFÐT]Ñ^Ô^ˆ
Ý&,ðð à!+ðñ ô ñ
'
ô 
'
ˆÔ˜(Ñ#ð ”I×$Ò$Ñ&Ô&ð 	;ð 	;ˆDØÔ˜hÔ'×4Ò4°TÑ:Ô:Ð:Ð:ð Ôð 	¥ J¡¤°!Ò 3Ð 3ØˆJð
 ×6Ò6°sÑ;Ô;ˆà"Ô/°Ô9Ðõ
 *¨$Ô*;×*@Ò*@Ñ*BÔ*BÀCÑHÔHˆÝ‘\”\ˆ
Ø×Ò˜OÑ,Ô,Ð,Ø×Ò˜cœjÑ)Ô)Ð)Ø”I×$Ò$Ñ&Ô&ð 	&ð 	&ˆDØ×Ò Ñ%Ô%Ð%Ð%Ø×&Ò&Ñ(Ô(ð 	*ð 	*ˆCØ×$Ò$ SÑ)Ô)Ð)Ð)Ø×)Ò)Ñ+Ô+ð 	-ð 	-ˆCØ×'Ò'¨Ñ,Ô,Ð,Ð,Ø×)Ò)Ñ+Ô+ð 	-ð 	-ˆCØ×'Ò'¨Ñ,Ô,Ð,Ð,Ø"%Ô"2ˆ
Ôð7
ð 7
Ý)2°3´:Ñ)>Ô)>ð7
ñ 7
ô 7
ˆÔÐ2Ñ3õ ðð ð ð ð ",ð	ñ ô ñ
ô 
ˆõ ˆ|ÑÔ¥ OÑ 4Ô 4Ò4Ð4ðð Ø'1ðñ ô ˆKõ !*¨/Ñ :Ô :ð ,ð ,‘��uØ˜KÐ'Ð'ØØ&+�˜UÑ#Ð#àÔ˜^Ô,Ð4Ø0<ˆDÔ˜nÑ-Ð-à0<×0DÒ0DØÔ! .Ô1°3´:ñ1ô 1ˆDÔ˜nÑ-ð $ð 	ð 	ˆIð
 'Ô3×8Ò8Ñ:Ô:ˆNØ ”}×/Ò/Ñ1Ô1ˆHØ Ò(Ð(Ø ^Ð ^Ð ^Ð ^ÈÌÔI]Ð ^Ñ ^Ô ^�Ø”×(Ò(ðð ð ð ð ð å$)¨)¬-×*BÒ*BÑ*DÔ*DÀnÑ$UÔ$Uðñ ô ñô ð õ -ØØ”ØÔ&ØÔ(ðð ð ð ð å % nÑ 5Ô 5ðñ ô ð Ô-ñ
ô 
ˆJˆJõ 	Ô'¨
ÀÐFÑFÔFÐFØÐr5   c                 ó˜  ‡— ‰j         s(t          j        ‰¦  «        Š‰                     ¦   «          t	          t          j        ‰j        ¦  «        ¦  «        }‰j        }d„ t          |j
        ¦  «        D ¦   «         }g }|�©ˆfd„‰j                             ¦   «         D ¦   «         }|D ]�}	|	                     ¦   «         }
d gt          |j
        ¦  «        z  }|
                     ¦   «         D ])\  }}|                     |d ¦  «        }|€Œ||         ||<   Œ*|                     |¦  «         Œ‚t#          |‰                     ¦   «         |¦  «        \  }}t'          d‰                     ¦   «         z  ¬¦  «                             dt*          j        ¦  «                             ddt*          j        ¦  «                             dd	¦  «        }t3          j        ¦   «         }t7          ||||| j        | j        | j        | j        |¦	  «	        \  }}}t3          j        ¦   «         }t@           !                    d
||z
  ¦  «         tE          |‰||||¦  «        S )Nc                 ó   — i | ]\  }}||“Œ	S r9   r9   rP   s      r4   r?   z*SabreLayout._inner_run.<locals>.<dictcomp>…  s   € Ð!UÐ!UÐ!U±°¸ # uÐ!UÐ!UÐ!Ur5   c                 ó,   •— i | ]}‰j         |         |“ŒS r9   )r1   )r;   Úxr"   s     €r4   r?   z*SabreLayout._inner_run.<locals>.<dictcomp>ˆ  s0   ø€ ð ,ð ,ð ,Ø-.�Ô" 1Ô% qð,ð ,ð ,r5   é
   )Úattempt_limitg      ð?g      à?é   gü©ñÒMbP?é   zOSabre layout algorithm execution for a connected component complete in: %s sec.)#r+   r,   r-   r.   r   r/   r0   r1   Údistance_matrixrU   r:   Únode_indicesÚget_virtual_bitsrJ   ÚitemsÚgetÚappendr   re   r   Ú
with_basicr   ÚSizeÚwith_lookaheadÚ
with_decayÚtimeÚperf_counterr   r&   r(   r)   r%   rx   ÚdebugÚ_DisjointComponent)r2   r>   r"   rF   Úneighbor_tableÚdist_matrixrS   Úpartial_layoutsÚcoupling_map_reverse_mappingrC   Úvirtual_bitsÚ
out_layoutrR   rM   ÚposÚ	sabre_dagr‘   Ú	heuristicÚsabre_startrH   rV   r�   Ú
sabre_stops     `                    r4   r|   zSabreLayout._inner_run|  sw  ø€ ØÔ(ð 	*õ  œ=¨Ñ6Ô6ˆLØ×'Ò'Ñ)Ô)Ð)Ý&¥rÔ':¸<Ô;MÑ'NÔ'NÑOÔOˆØ"Ô2ˆØ!UÐ!U½yÈÌÑ?TÔ?TÐ!UÑ!UÔ!UÐØˆØÐ'ð,ð ,ð ,ð ,Ø2>Ô2D×2QÒ2QÑ2SÔ2Sð,ñ ,ô ,Ð(ð +ð 3ð 3�Ø%×6Ò6Ñ8Ô8�Ø"˜V¥c¨#¬*¡o¤oÑ5�
Ø!-×!3Ò!3Ñ!5Ô!5ð Ið I‘I�C˜Ø0×4Ò4°S¸$Ñ?Ô?�CØ�{Ø Ø&BÀ4Ô&H�J˜s‘O�OØ×&Ò& zÑ2Ô2Ð2Ð2å)9ØØ×ÒÑÔØ"ñ*
ô *
Ñ&ˆ	Ð&õ  B¨×):Ò):Ñ)<Ô)<Ñ$<Ð=Ñ=Ô=ßŠZ˜�Zœ_Ñ-Ô-ßŠ^˜C ¥Z¤_Ñ5Ô5ßŠZ˜˜qÑ!Ô!ð	 	õ Ô'Ñ)Ô)ˆÝ<TØØØØØÔØÔØÔØŒIØñ
=
ô 
=
Ñ9ˆÐ*¨Lõ Ô&Ñ(Ô(ˆ
Ý�ŠØ]Ø˜Ñ$ñ	
ô 	
ð 	
õ "ØØØØØØñ
ô 
ð 	
r5   c                 óæ   — t          | j        ¦  «        }| j        |_        |                     |¦  «        }t	          ¦   «         }|j        |_        |                     |¦  «        }|j        | _        |S )z°Run the ancilla-allocation and -enlargement passes on the DAG chained onto our
        ``property_set``, skipping the DAG-to-circuit conversion cost of using a ``PassManager``.)r   r"   ru   rt   r   )r2   r>   Úancilla_passÚenlarge_passs       r4   r€   z/SabreLayout._ancilla_allocation_no_pass_managerº  sk   € õ -¨TÔ->Ñ?Ô?ˆØ$(Ô$5ˆÔ!Ø×Ò˜sÑ#Ô#ˆÝ)Ñ+Ô+ˆØ$0Ô$=ˆÔ!Ø×Ò˜sÑ#Ô#ˆØ(Ô5ˆÔØˆ
r5   c                 óª   — t          |¦  «        t          | j        ¦  «        t          ¦   «         t	          ¦   «         | j        g}t          |¦  «        }|S )z‚Return a passmanager for a full layout and routing.

        We use a factory to remove potential statefulness of passes.
        )r   r   r"   r   r	   r$   r   )r2   rH   Úlayout_and_router˜   s       r4   rs   z)SabreLayout._layout_and_route_passmanagerÆ  sP   € õ �nÑ%Ô%Ý! $Ô"3Ñ4Ô4ÝÑ Ô Ý‰MŒMØÔð
Ðõ Ð)Ñ*Ô*ˆØˆ	r5   c                 ó’   ‡‡— t          j        |Ž }t          j        ||¦  «        Šˆˆfd„|j        D ¦   «         }t          |¦  «        S )aš  Return the real final_layout resulting from the composition
        of an initial_layout with the final_layout reported by a pass.

        The routing passes internally start with a trivial layout, as the
        layout gets applied to the circuit prior to running them. So the
        ``"final_layout"`` they report must be amended to account for the actual
        initial_layout that was selected.
        c                 ó8   •— i | ]}|‰j         ‰|                  “ŒS r9   )Ú_v2p)r;   Úvrš   Ú	qubit_maps     €€r4   r?   z0SabreLayout._compose_layouts.<locals>.<dictcomp>à  s(   ø€ Ð]Ð]Ð]ÀA˜Ð,Ô1°)¸A´,Ô?Ð]Ð]Ð]r5   )r   Úgenerate_trivial_layoutÚcombine_into_edge_maprË   )r2   rH   rš   rw   Útrivial_layoutrB   rÍ   s     `   @r4   rv   zSabreLayout._compose_layoutsÕ  sR   øø€ õ  Ô7¸Ð?ˆÝÔ0°ÀÑPÔPˆ	Ø]Ð]Ð]Ð]Ð]ÈÔI\Ð]Ñ]Ô]ˆÝ�lÑ#Ô#Ð#r5   )NNr   NNF)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   rt   r|   r€   rs   rv   Ú__classcell__)r3   s   @r4   r   r   /   s¾   ø€ € € € € ð>ð >ðF ØØØØØðS_ð S_ð S_ð S_ð S_ð S_ðjuð uð uðn<
ð <
ð <
ð <
ð|
ð 
ð 
ðð ð ð$ð $ð $ð $ð $ð $ð $r5   r   c                   óP   — e Zd ZU dZeed<   eed<   eed<   ded<   ded<   d	ed
<   dS )r¸   )r>   r"   rH   rV   r�   r‘   r>   r"   rH   z	list[int]rV   z/tuple[SwapMap, Sequence[int], NodeBlockResults]r�   zdict[int, DAGCircuit]r‘   N)rÑ   rÒ   rÓ   Ú	__slots__r   Ú__annotations__r   r   r9   r5   r4   r¸   r¸   ä  s`   € € € € € € ð€Ið 
€O€O�OØÐÐÑØÐÐÑØ"Ð"Ð"Ñ"ØCÐCÐCÑCØ0Ð0Ð0Ñ0Ð0Ð0r5   r¸   )8rÔ   r,   ÚdataclassesÚloggingr}   rµ   Únumpyrg   Ú	rustworkxr/   Úqiskit.convertersr   Úqiskit.circuitr   Úqiskit.dagcircuitr   Ú*qiskit.transpiler.passes.layout.set_layoutr   Ú7qiskit.transpiler.passes.layout.full_ancilla_allocationr   Ú4qiskit.transpiler.passes.layout.enlarge_with_ancillar   Ú,qiskit.transpiler.passes.layout.apply_layoutr	   Úqiskit.transpiler.passes.layoutr
   Úqiskit.transpiler.passmanagerr   Úqiskit.transpiler.layoutr   Úqiskit.transpiler.basepassesr   Úqiskit.transpiler.exceptionsr   Úqiskit._accelerate.nlayoutr   Úqiskit._accelerate.sabrer   r   r   r   Ú+qiskit.transpiler.passes.routing.sabre_swapr   r   Úqiskit.transpiler.targetr   Úqiskit.transpiler.couplingr   Úqiskit.utils.parallelr   Ú	getLoggerrÑ   rx   r   Ú	dataclassr¸   r9   r5   r4   ú<module>rñ      s@  ððð ð €€€Ø Ð Ð Ð Ø €€€Ø Ð Ð Ð Ø €€€à Ð Ð Ð Ø Ð Ð Ð à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *Ø (Ð (Ð (Ð (Ð (Ð (Ø @Ð @Ð @Ð @Ð @Ð @Ø YÐ YÐ YÐ YÐ YÐ YØ SÐ SÐ SÐ SÐ SÐ SØ DÐ DÐ DÐ DÐ DÐ DØ :Ð :Ð :Ð :Ð :Ð :Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø +Ð +Ð +Ð +Ð +Ð +Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø .Ð .Ð .Ð .Ð .Ð .Ø cÐ cÐ cÐ cÐ cÐ cÐ cÐ cÐ cÐ cÐ cÐ cØ ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ð ]Ø +Ð +Ð +Ð +Ð +Ð +Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø +Ð +Ð +Ð +Ð +Ð +à	ˆÔ	˜8Ñ	$Ô	$€ðr$ð r$ð r$ð r$ð r$Ð$ñ r$ô r$ð r$ðj Ôð1ð 1ð 1ð 1ð 1ñ 1ô 1ñ Ôð1ð 1ð 1r5   