
    z	iF              3          S r SSKrSSKJr  SSKJrJrJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJrJr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!  \RD                  " \#5      r$\
" S\\\\   4   S9r%                       S/S\%S\	\   S\	\\&      S\	\\\\\'      4      S\	\\\\4      S\	\&   S\	\&   S\	\&   S\	\&   S\	\(   S\	\(   S\	\'   S\	\'   S\	\\\\(\\'/\4      S\	\\&\\&   4      S \&S!\	\)   S"\	\!   S#\	\   S$\	\&   S%\	\&   S&\*S'\	\'   S(\*S)\%42S* jjr+S+ r,S, r-S- r.S. r/g)0zCircuit transpile function    N)time)ListUnionDictCallableAnyOptionalTypeVar)user_config)QuantumCircuit)
DAGCircuit)Backend)LayoutCouplingMapPropertySet)BasePass)TranspilerErrorCircuitTooWideForTarget)	HLSConfig)generate_preset_pass_manager)Target	_CircuitT)boundcircuitsbackendbasis_gatescoupling_mapinitial_layoutlayout_methodrouting_methodtranslation_methodscheduling_methoddtapproximation_degreeseed_transpileroptimization_levelcallbackoutput_nameunitary_synthesis_methodunitary_synthesis_plugin_configtarget
hls_configinit_methodoptimization_method'ignore_backend_supplied_default_methodsnum_processesqubits_initially_zeroreturnc                    [        U [        5      nU(       a  U OU /n U (       d  / $ [        5       nUc'  [        R                  " 5       nUR                  SS5      nU(       dH  Uc!  [        US5      (       a  UR                  5       nUc!  [        US5      (       a  UR                  5       n[        X5      n[        U5      n[        XU5        [        U40 SU_SU_SU_SU_S	U_S
U_SU_SU_SU_SU
_SU_SU_SU_SU_SU_SU_SU	_SU_6nUR                  XUS9n[        UU5       H  u  nnUUl        M     [        5       n[!        UU5        U(       a  U$ US   $ )a%  Transpile one or more circuits, according to some desired transpilation targets.

Transpilation is potentially done in parallel using multiprocessing when ``circuits``
is a list with > 1 :class:`~.QuantumCircuit` object, depending on the local environment
and configuration.

The prioritization of transpilation target constraints works as follows: if a ``target``
input is provided, it will take priority over any ``backend`` input or loose constraints
(``basis_gates``, ``coupling_map``, or ``dt``). If a ``backend`` is provided
together with any loose constraint
from the list above, the loose constraint will take priority over the corresponding backend
constraint. This behavior is summarized in the table below. The first column
in the table summarizes the potential user-provided constraints, and each cell shows whether
the priority is assigned to that specific constraint input or another input
(`target`/`backend(V2)`).

============================ ========= ========================
User Provided                target    backend(V2)
============================ ========= ========================
**basis_gates**              target    basis_gates
**coupling_map**             target    coupling_map
**dt**                       target    dt
============================ ========= ========================

Args:
    circuits: Circuit(s) to transpile
    backend: If set, the transpiler will compile the input circuit to this target
        device. If any other option is explicitly set (e.g., ``coupling_map``), it
        will override the backend's.
    basis_gates: List of basis gate names to unroll to
        (e.g: ``['u1', 'u2', 'u3', 'cx']``). If ``None``, do not unroll.
    coupling_map: Directed coupling map (perhaps custom) to target in mapping. If
        the coupling map is symmetric, both directions need to be specified.

        Multiple formats are supported:

        #. ``CouplingMap`` instance
        #. List, must be given as an adjacency matrix, where each entry
           specifies all directed two-qubit interactions supported by backend,
           e.g: ``[[0, 1], [0, 3], [1, 2], [1, 5], [2, 5], [4, 1], [5, 3]]``
    initial_layout: Initial position of virtual qubits on physical qubits.
        If this layout makes the circuit compatible with the coupling_map
        constraints, it will be used. The final layout is not guaranteed to be the same,
        as the transpiler may permute qubits through swaps or other means.
        Multiple formats are supported:

        #. ``Layout`` instance
        #. Dict
           * virtual to physical::

                {qr[0]: 0,
                 qr[1]: 3,
                 qr[2]: 5}

           * physical to virtual::

                {0: qr[0],
                 3: qr[1],
                 5: qr[2]}

        #. List

           * virtual to physical::

                [0, 3, 5]  # virtual qubits are ordered (in addition to named)

           * physical to virtual::

                [qr[0], None, None, qr[1], None, qr[2]]

    layout_method: Name of layout selection pass ('trivial', 'dense', 'sabre').
        This can also be the external plugin name to use for the ``layout`` stage.
        You can see a list of installed plugins by using :func:`~.list_stage_plugins` with
        ``"layout"`` for the ``stage_name`` argument.
    routing_method: Name of routing pass
        ('basic', 'lookahead', 'stochastic', 'sabre', 'none'). Note
        This can also be the external plugin name to use for the ``routing`` stage.
        You can see a list of installed plugins by using :func:`~.list_stage_plugins` with
        ``"routing"`` for the ``stage_name`` argument.
    translation_method: Name of translation pass (``"default"``, ``"translator"`` or
        ``"synthesis"``). This can also be the external plugin name to use for the
        ``translation`` stage.  You can see a list of installed plugins by using
        :func:`~.list_stage_plugins` with ``"translation"`` for the ``stage_name`` argument.
    scheduling_method: Name of scheduling pass.
        * ``'as_soon_as_possible'``: Schedule instructions greedily, as early as possible
        on a qubit resource. (alias: ``'asap'``)
        * ``'as_late_as_possible'``: Schedule instructions late, i.e. keeping qubits
        in the ground state when possible. (alias: ``'alap'``)
        If ``None``, no scheduling will be done. This can also be the external plugin name
        to use for the ``scheduling`` stage. You can see a list of installed plugins by
        using :func:`~.list_stage_plugins` with ``"scheduling"`` for the ``stage_name``
        argument.
    dt: Backend sample time (resolution) in seconds.
        If ``None`` (default), ``backend.dt`` is used.
    approximation_degree (float): heuristic dial used for circuit approximation
        (1.0=no approximation, 0.0=maximal approximation)
    seed_transpiler: Sets random seed for the stochastic parts of the transpiler
    optimization_level: How much optimization to perform on the circuits.
        Higher levels generate more optimized circuits,
        at the expense of longer transpilation time.

        * 0: no optimization
        * 1: light optimization
        * 2: heavy optimization
        * 3: even heavier optimization

        If ``None``, level 2 will be chosen as default.
    callback: A callback function that will be called after each
        pass execution. The function will be called with 5 keyword
        arguments,
        | ``pass_``: the pass being run.
        | ``dag``: the dag output of the pass.
        | ``time``: the time to execute the pass.
        | ``property_set``: the property set.
        | ``count``: the index for the pass execution.
        The exact arguments passed expose the internals of the pass manager,
        and are subject to change as the pass manager internals change. If
        you intend to reuse a callback function over multiple releases, be
        sure to check that the arguments being passed are the same.
        To use the callback feature, define a function that will
        take in kwargs dict and access the variables. For example::

            def callback_func(**kwargs):
                pass_ = kwargs['pass_']
                dag = kwargs['dag']
                time = kwargs['time']
                property_set = kwargs['property_set']
                count = kwargs['count']
                ...
            transpile(circ, callback=callback_func)

    output_name: A list with strings to identify the output circuits. The length of
        the list should be exactly the length of the ``circuits`` parameter.
    unitary_synthesis_method (str): The name of the unitary synthesis
        method to use. By default ``'default'`` is used. You can see a list of installed
        plugins with :func:`.unitary_synthesis_plugin_names`.
    unitary_synthesis_plugin_config: An optional configuration dictionary
        that will be passed directly to the unitary synthesis plugin. By
        default this setting will have no effect as the default unitary
        synthesis method does not take custom configuration. This should
        only be necessary when a unitary synthesis plugin is specified with
        the ``unitary_synthesis_method`` argument. As this is custom for each
        unitary synthesis plugin refer to the plugin documentation for how
        to use this option.
    target: A backend transpiler target. Normally this is specified as part of
        the ``backend`` argument, but if you have manually constructed a
        :class:`~qiskit.transpiler.Target` object you can specify it manually here.
        This will override the target from ``backend``.
    hls_config: An optional configuration class
        :class:`~qiskit.transpiler.passes.synthesis.HLSConfig` that will be passed directly
        to :class:`~qiskit.transpiler.passes.synthesis.HighLevelSynthesis` transformation pass.
        This configuration class allows to specify for various high-level objects the lists of
        synthesis algorithms and their parameters.
    init_method: The plugin name to use for the ``init`` stage. By default an external
        plugin is not used. You can see a list of installed plugins by
        using :func:`~.list_stage_plugins` with ``"init"`` for the stage
        name argument.
    optimization_method: The plugin name to use for the
        ``optimization`` stage. By default an external
        plugin is not used. You can see a list of installed plugins by
        using :func:`~.list_stage_plugins` with ``"optimization"`` for the
        ``stage_name`` argument.
    ignore_backend_supplied_default_methods: If set to ``True`` any default methods specified by
        a backend will be ignored. Some backends specify alternative default methods
        to support custom compilation target-specific passes/plugins which support
        backend-specific compilation techniques. If you'd prefer that these defaults were
        not used this option is used to disable those backend-specific defaults.
    num_processes: The maximum number of parallel processes to launch for this call to
        transpile if parallel execution is enabled. This argument overrides
        ``num_processes`` in the user configuration file, and the ``QISKIT_NUM_PROCS``
        environment variable. If set to ``None`` the system default or local user configuration
        will be used.
    qubits_initially_zero: Indicates whether the input circuit is zero-initialized.

Returns:
    The transpiled circuit(s).

Raises:
    TranspilerError: in case of bad inputs to transpiler (like conflicting parameters)
        or errors in passes
transpile_optimization_level   get_scheduling_stage_pluginget_translation_stage_pluginr+   r   r   r   r   r   r    r!   r"   r$   r%   r)   r*   r,   r-   r.   r#   r1   )r'   r0   r   )
isinstancelistr   r   
get_configgethasattrr6   r7   _parse_output_name_parse_coupling_map_check_circuits_coupling_mapr   runzipname_log_transpile_time) r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   arg_circuits_list
start_timeconfigpmout_circuitsrB   circend_times                                    T/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/compiler/transpiler.py	transpilerL   $   s   ^ #8T2,x8*H	J!'')#ZZ(FJ2$:W)X)X ' C C E%'';Y*Z*Z!(!E!E!G$[;K&|4L A
 
&

 
  	

 "
 &
 $
 &
 .
 ,
 2
 (
 ":
 )H
 
   !
" 0#
$ %
& 4'
B, 66(]6SL+|4
d	 5vH
H-A    c           
          S nUb  UR                  5       nOUb  UR                  nU  HA  n[        UR                  5      nUc  M  XS:  d  M$  [	        SU SUR
                   SU S35      e   g )NzNumber of qubits (z) in z is greater than maximum (z) in the coupling_map)size
num_qubitslenqubitsr   rB   )r   cmapr   
max_qubitscircuitrP   s         rK   r?   r?   /  s~    JYY[
		''
(
!z'>)$ZLgll^ D,,6<7LN 	 rM   c                 F    SX-
  S-  S S3n[         R                  U5        g )NzTotal Transpile Time - i  z.5fz (ms))loggerinfo)rE   rJ   log_msgs      rK   rC   rC   A  s'    '(*?4)G'MUSG
KKrM   c                     [        U [        5      (       a"  [        S U  5       5      (       a  [        U 5      $ [        U [        5      (       a  [	        S5      eU $ )Nc              3   l   #    U  H*  n[        U[        5      =(       a    [        U5      S :H  v   M,     g7f)r5   N)r8   r9   rQ   ).0is     rK   	<genexpr>&_parse_coupling_map.<locals>.<genexpr>H  s*      .5A
1d+A!+\s   24zOnly a single input coupling map can be used with transpile() if you need to target different coupling maps for different circuits you must call transpile() multiple times)r8   r9   allr   r   )r   s    rK   r>   r>   F  s\    ,%%# .5A. + + <((	L$	'	'
 	
 rM   c                    U b  [        U [        5      (       a  [        U5      S:X  a  U /$ [        S5      e[        U [        5      (       a<  [        U5      [        U 5      :X  a  [        S U  5       5      (       a  U $ [        S5      e[        S[        U 5       S35      eU Vs/ s H  o"R                  PM     sn$ s  snf )N   zYExpected a list object of length equal to that of the number of circuits being transpiledc              3   B   #    U  H  n[        U[        5      v   M     g 7f)N)r8   str)r\   rB   s     rK   r^   %_parse_output_name.<locals>.<genexpr>f  s      92=$
4%%+s   z}The length of output_name list must be equal to the number of transpiled circuits and the output_name list should be strings.zBThe parameter output_name should be a string or alist of strings: z
 was used.)r8   rd   rQ   r   r9   r`   typerB   )r(   r   rU   s      rK   r=   r=   V  s     k3''8}!#}$ &) 
 T**8}K 00S 92=9 6 6 #"%.  "$$($5#6jB 
 -55HH555s   #B;)NNNNNNNNNg      ?NNNNdefaultNNNNNFNT)0__doc__loggingr   typingr   r   r   r   r   r	   r
   qiskitr   qiskit.circuit.quantumcircuitr   qiskit.dagcircuitr   qiskit.providers.backendr   qiskit.transpilerr   r   r   qiskit.transpiler.basepassesr   qiskit.transpiler.exceptionsr   r   7qiskit.transpiler.passes.synthesis.high_level_synthesisr   %qiskit.transpiler.preset_passmanagersr   qiskit.transpiler.targetr   	getLogger__name__rW   r   rd   intfloatdictboolrL   r?   rC   r>   r=    rM   rK   <module>r|      ss   !   F F F  8 ( , > > 1 Q M N +			8	$Ku^T.=Q-Q'RS	
 "&'+BF:>#'$((,'+,/%)(,Y]37$-6:#&*!%)-49#'"&1HHgH $s)$H 5d49o!=>?	H
 U64#567H C=H SMH !H  }H 	H #5/H c]H !H x:uk3 OQT TUVH %T#Y/0H  "!H" &.d^#H$ V%H& #'H( #)H* "#+H, .2-H. C=/H0  1H2 3HV$
 !6rM   