
    z	i7                        S r SSK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  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  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  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  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!  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&  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/  SS&K0J1r1  SS'K2J3r3  SS(K4J5r5  \Rl                  " S)S*5      r7\7" 1 S+k\8" 5       S*9\7" 1 S,kS-S.1S*9\7" 1 S/k\8" 5       S*9\7" S01\8" 5       S*9\7" \8" 5       S1S21S*9S3.r9S4 r:S5 r; " S6 S75      r<       SRS8 jr=S9 r>S: r?SSS0SSS;\1R                  4S< jrAS= rBS> rCS? rD      SSS@ jrE\3" SASBSCSD9STSE j5       rF        SUSF jrGSVSG jrH\Rl                  " SHSI5      rI   STSJ\JSK\\K   SL\\/   SM\LSN\I4
SO jjrM\8" \55      R                  1 SPkR                  \5      5      rOSWSN\L4SQ jjrPg)Xz%Common preset passmanager generators.    N)Optional)SessionEquivalenceLibrary)CONTROL_FLOW_OP_NAMES)ConditionalController)PassManager)Error)BasisTranslator)Unroll3qOrMore)ConsolidateBlocks)Collect1qRuns)Collect2qBlocks)UnitarySynthesis)HighLevelSynthesis)CheckMap)GateDirection)BarrierBeforeFinalMeasurements)CheckGateDirection)TimeUnitConversion)ALAPScheduleAnalysis)ASAPScheduleAnalysis)FullAncillaAllocation)EnlargeWithAncilla)ApplyLayout)RemoveResetInZeroState)FilterOpNodes)PadDelay)InstructionDurationCheck)ConstrainedReschedule)ContainsInstruction)VF2PostLayout)VF2LayoutStopReason)VF2PostLayoutStopReason)
WrapAngles)TranspilerError)Layout)OptimizationMetric)deprecate_func)_CLIFFORD_GATE_NAMES_ControlFlowState)workingnot_working>   densesabredefaulttrivial>   noner-   r.   
stochastic	lookaheadbasic>   r.   	synthesis
translatorr.   alapasap)layout_methodrouting_methodtranslation_methodoptimization_methodscheduling_methodc                 6   ^  [        U 4S j[         5       5      $ )Nc              3   4   >#    U  H  nTS U 3   v   M     g7f	contains_N .0xproperty_sets     f/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/preset_passmanagers/common.py	<genexpr>$_has_control_flow.<locals>.<genexpr>P   s     L6K|isO,6K   anyr   rE   s   `rF   _has_control_flowrM   O   s    L6KLLL    c                 @   ^  [        U 4S j[         5       5      (       + $ )Nc              3   4   >#    U  H  nTS U 3   v   M     g7fr?   rA   rB   s     rF   rG   (_without_control_flow.<locals>.<genexpr>T   s     P:OQ<)A30:OrI   rJ   rL   s   `rF   _without_control_flowrR   S   s    P:OPPPPrN   c                   *    \ rS rSrSS jrS rS rSrg)_InvalidControlFlowForBackendW   Nc                 (   Ub=  [        UR                  5      S:  a$  [         Vs/ s H  o3U;  d  M
  UPM     snU l        g Ub>  [        U5      S:  a/  [	        U5      n[         Vs/ s H  o3U;  d  M
  UPM     snU l        g / U l        g s  snf s  snf )Nr   )lenoperation_namesr   unsupportedset)selfbasis_gatestargetops       rF   __init__&_InvalidControlFlowForBackend.__init__Z   s    #f&<&<"="A-BW-BrPVFV-BWD$[)9A)=k*K-B\-BrP[F[-B\D  "D  X  ]s   	B
B
&	B3Bc                     U R                    Vs/ s H  o!SU 3   (       d  M  UPM     nn[        U5      S:X  a	  SUS    S3$ SSR                  S U 5       5       S	3$ s  snf )
z3Create an error message for the given property set.r@      zThe control-flow construct 'r   z"' is not supported by the backend.zThe control-flow constructs [z, c              3   8   #    U  H  n[        U5      v   M     g 7fN)repr)rC   r^   s     rF   rG   8_InvalidControlFlowForBackend.message.<locals>.<genexpr>j   s     5O2d2hhs   z#] are not supported by the backend.)rY   rW   join)r[   rE   rD   failss       rF   message%_InvalidControlFlowForBackend.messaged   su     ,,N,qy_0M,Nu:?1%(;]^^+DII5O5O,O+P Q1 1	
 Os
   AAc                 B   ^ [        U4S jU R                   5       5      $ )z/Checkable condition for the given property set.c              3   4   >#    U  H  nTS U 3   v   M     g7fr?   rA   rB   s     rF   rG   :_InvalidControlFlowForBackend.condition.<locals>.<genexpr>p   s     K:JQ<)A30:JrI   )rK   rY   )r[   rE   s    `rF   	condition'_InvalidControlFlowForBackend.conditionn   s    K$:J:JKKKrN   )rY   )rA   N)__name__
__module____qualname____firstlineno__r_   ri   rn   __static_attributes__rA   rN   rF   rT   rT   W   s    "
LrN   rT   c           
      \   / nSnSU 4SU4SU4SU4SU44 H}  u  pU	S-   n[         U   nU
c  M  XR                  ;   d  M)  UR                  (       a#  USU S	U
 S
[        UR                  5       S3-  nOUSU S	U
 SU	 S3-  nUR	                  U5        M     [        5       nUR	                  [        [        SS95        U(       a&  UR	                  [        [        U5      [        S95        [        XV5      nUR	                  [        [        UR                  5      UR                  S95        U$ )a  Generate a pass manager that, when run on a DAG that contains control flow, fails with an
error message explaining the invalid options, and what could be used instead.

Returns:
    PassManager: a pass manager that populates the ``contains_x`` properties for each of the
    control-flow operations, and raises an error if any of the given options do not support
    control flow, but a circuit with control flow is given.
z.Some options cannot be used with control flow.layoutroutingtranslationoptimization
scheduling_methodz Got z='z', but valid values are .z', but the entire z stage is not supported.Frecursern   )_CONTROL_FLOW_STATESr+   r*   listappendr   r   r   r   r   rM   rT   ri   rn   )r8   r9   r:   r;   r<   r\   r]   bad_optionsri   stagegivenoptionmethod_statesoutbackend_controls                  rF   #generate_control_flow_options_checkr   s   sO   " K>G	=!	N#	*+	,-	() ",V4*C*C!C$$F82eW,DT-J_J_E`Daabc F82eW,>ugE]^ v&%& -CJJ"#8%HI

(wCTUV3KHOJJeO$;$;<HaHab JrN   c                     [        5       nUR                  [        [        SS95        UR                  [	        [        U 5      [        S95        U$ )z]Get a pass manager that always raises an error if control flow is present in a given
circuit.Fr}   r   )r   r   r   r   r   r   rM   )ri   r   s     rF   generate_error_on_control_flowr      s>     -CJJ"#8%HIJJ$U7^?PQRJrN   c                 \   [        U [        5      (       a  U R                  5       n [        U[        5      (       a  UR                  5       n[        5       nUR                  [	        [
        SS95        UR                  [        U [        S95        UR                  [        U[        S95        U$ )zGenerate a pass manager that will run the passes in ``if_present`` if the given circuit
has control-flow operations in it, and those in ``if_absent`` if it doesn't.Fr}   r   )	
isinstancer   to_flow_controllerr   r   r   r   rM   rR   )
if_present	if_absentr   s      rF   if_has_control_flow_elser      s     *k**224
)[))002	
-CJJ"#8%HIJJ$Z;LMNJJ$Y:OPQJrN   Tc                    [        5       nUR                  [        UUUSUU S95        UR                  [        USU S[        USUUS9	5        Uc  U c  UR                  [        X5      5        U$ UR                  [        [        XSS95        U$ )a  Generate an unroll >3q :class:`~qiskit.transpiler.PassManager`

Args:
    target (Target): the :class:`~.Target` object representing the backend
    basis_gates (list): A list of str gate names that represent the basis
        gates on the backend target
    approximation_degree (Optional[float]): The heuristic approximation degree to
        use. Can be between 0 and 1.
    unitary_synthesis_method (str): The unitary synthesis method to use. You can see
        a list of installed plugins with :func:`.unitary_synthesis_plugin_names`.
    unitary_synthesis_plugin_config (dict): The optional dictionary plugin
        configuration, this is plugin specific refer to the specified plugin's
        documentation for how to use.
    hls_config (HLSConfig): An optional configuration class to use for
        :class:`~qiskit.transpiler.passes.HighLevelSynthesis` pass.
        Specifies how to synthesize various high-level objects.
    qubits_initially_zero (bool): Indicates whether the input circuit is
        zero-initialized.
    optimization_metric (OptimizationMetric): the :class:`~.OptimizationMetric` object
        that the metric used when optimizing the unrolling.

Returns:
    PassManager: The unroll 3q or more pass manager
   )approximation_degreemethod
min_qubitsplugin_configr]   NF)	
hls_configcoupling_mapr]   use_qubit_indicesequivalence_libraryr\   r   qubits_initially_zerooptimization_metric)r]   r   )r   r   r   r   selr
   r	   )	r]   r\   r   unitary_synthesis_methodunitary_synthesis_plugin_configr   r   r   	unroll_3qs	            rF   generate_unroll_3qr      s    D I!5+9	
	 !# ##"7 3
	
 v~<=  	kUVWXrN   c                 P    [        [        U 5      [        5       [        5       /5      $ )a  Generate a layout embedding :class:`~qiskit.transpiler.PassManager`

This is used to generate a :class:`~qiskit.transpiler.PassManager` object
that can be used to expand and apply an initial layout to a circuit

Args:
    coupling_map (Union[CouplingMap, Target): The coupling map for the backend to embed
        the circuit to.
Returns:
    PassManager: The embedding passmanager that assumes the layout property
        set has been set in earlier stages
)r   r   r   r   )r   s    rF   generate_embed_passmanagerr      s$     -l;=O=QS^S`abbrN   c                 2    U S   SL=(       a
    U S   (       + $ )zReturn ``True`` if the first attempt at layout has been checked and found to be imperfect.
In this case, perfection means "does not require any swap routing".is_swap_mappedNrA   rL   s    rF   _layout_not_perfectr     s#     ()5\lK[>\:\\rN   c                 H    U S   S L=(       a    U S   [         R                  L $ )NVF2PostLayout_stop_reason)r"   SOLUTION_FOUNDrL   s    rF   _apply_post_layout_conditionr     s2     	01= 	`459P9_9__rN   c                   ^ U4S jn[        5       n	Ub  U	R                  [        USS95        OU	R                  [        USS95        S n
U(       a#  U	R                  [        [	        SS9U /U
S95        OU	R                  [        X
S95        U=(       a    UnUbP  U(       aI  U	R                  [        [        UUUUSS	9US95        U	R                  [        [        5       [        S95        S
 nU	R                  [        U5      /5        U	$ )a  Generate a routing :class:`~qiskit.transpiler.PassManager`

Args:
    routing_pass (TransformationPass): The pass which will perform the
        routing
    target (Target): the :class:`~.Target` object representing the backend
    coupling_map (CouplingMap): The coupling map of the backend to route
        for
    vf2_call_limit (int): The internal call limit for the vf2 post layout
        pass. If this is ``None`` or ``0`` the vf2 post layout will not be
        run.
    seed_transpiler (int): Sets random seed for the stochastic parts of
        the transpiler. This is currently only used for :class:`.VF2PostLayout` and the
        default value of ``-1`` is strongly recommended (which is no randomization).
        If a value of ``None`` is provided this will seed from system
        entropy.
    check_trivial (bool): If set to true this will condition running the
        :class:`~.VF2PostLayout` pass after routing on whether a trivial
        layout was tried and was found to not be perfect. This is only
        needed if the constructed pass manager runs :class:`~.TrivialLayout`
        as a first layout attempt and uses it if it's a perfect layout
        (as is the case with preset pass manager level 1).
    use_barrier_before_measurement (bool): If true (the default) the
        :class:`~.BarrierBeforeFinalMeasurements` transpiler pass will be run prior to the
        specified pass in the ``routing_pass`` argument.
    vf2_max_trials (int): The maximum number of trials to run VF2 when
        evaluating the vf2 post layout
        pass. If this is ``None`` or ``0`` the vf2 post layout will not be run.
Returns:
    PassManager: The routing pass manager
c                 n   > T(       a  [        U 5      (       a  U S   nUb  U[        R                  :w  a  gg)NVF2Layout_stop_reasonTF)r   r!   r   )rE   vf2_stop_reasoncheck_trivials     rF   _run_post_layout_condition@generate_routing_passmanager.<locals>._run_post_layout_conditionG  s8      3L A A*+BCO&/=P=_=_*_rN   routing_not_needed)property_set_fieldc                     U S   (       + $ )Nr   rA   rL   s    rF   _swap_condition5generate_routing_passmanager.<locals>._swap_conditionV  s     4555rN   5qiskit.transpiler.internal.routing.protection.barrierlabelr   F)seed
call_limit
max_trialsstrict_directionc                      U R                   S:g  $ )Nr   r   )nodes    rF   	filter_fn/generate_routing_passmanager.<locals>.filter_fnx  s    zzTTTrN   )	r   r   r   r   r   r    r   r   r   )routing_passr]   r   vf2_call_limitseed_transpilerr   use_barrier_before_measurementvf2_max_trialsr   rw   r   is_vf2_fully_boundedr   s        `       rF   generate_routing_passmanagerr     s
   T mGx;OPQxAUVW6 &!2U !	 *
	
 	,\UV)<n2!(--%* 5		
 	,[]FbcdU NNM),-.NrN   z2.0zmTranslation plugins are now required to respect ISA directionality, so typically no replacement is necessary.zin Qiskit 3.0)sinceadditional_msgremoval_timelinec           	          [        5       nU(       a<  UR                  [        XS95        S nUR                  [        [	        XS9/US95        U(       a  UR                  [        5       5        U$ )a  Generate a pre-optimization loop :class:`~qiskit.transpiler.PassManager`

This pass manager will check to ensure that directionality from the coupling
map is respected.

Args:
    target (Target): the :class:`~.Target` object representing the backend
    coupling_map (CouplingMap): The coupling map to use
    remove_reset_in_zero (bool): If ``True`` include the remove reset in
        zero pass in the generated PassManager
Returns:
    PassManager: The pass manager

r]   c                     U S   (       + $ Nis_direction_mappedrA   rL   s    rF   _direction_condition9generate_pre_op_passmanager.<locals>._direction_condition      #$9:::rN   r   )r   r   r   r   r   r   )r]   r   remove_reset_in_zeropre_optr   s        rF   generate_pre_op_passmanagerr     sc    . mG),FG	; 	!|;<.	
 -/0NrN   c	                 f   Uc  U c  [        / 5      $ US:X  a7  [        [        X5      n	[        UUUUUU S9[	        UUU S[        UUS9U	/n
U	/nGO9US:X  a  [        U5      S/-   n[        UUUUUSS9[	        UUSS[        UU[        R                  S	9[        [        US5      [        5       [        SSUSS
9[        SSS0S9[        / SQUUUSSSS9[        [        X5      /n
[        [        X5      n	U	/nOUS:X  a}  [        UUUUUSU S9[	        UUU SUSUS9[        XS9[        5       [        5       [        XUS9[        UUUUUU S9[	        UUU SUUS9/n
[        5       [        XUS9[        UUUUUU S9/nO[        SU S35      eU(       a  UR                  (       a  U bS  U R                  SS9(       a?  U
R                  [!        X@S95        S nU
R                  [#        [%        X@S9/U-   US95        U b/  U R'                  5       (       a  U
R                  [)        U 5      5        [        U
5      $ )a  Generate a basis translation :class:`~qiskit.transpiler.PassManager`

Args:
    target (Target): the :class:`~.Target` object representing the backend
    basis_gates (list): A list of str gate names that represent the basis
        gates on the backend target
    method (str): The basis translation method to use
    approximation_degree (Optional[float]): The heuristic approximation degree to
        use. Can be between 0 and 1.
    coupling_map (CouplingMap): the coupling map of the backend
        in case synthesis is done on a physical circuit. The
        directionality of the coupling_map will be taken into
        account if pulse_optimize is True/None and natural_direction
        is True/None.
    unitary_synthesis_plugin_config (dict): The optional dictionary plugin
        configuration, this is plugin specific refer to the specified plugin's
        documentation for how to use.
    unitary_synthesis_method (str): The unitary synthesis method to use. You can
        see a list of installed plugins with :func:`.unitary_synthesis_plugin_names`.
    hls_config (HLSConfig): An optional configuration class to use for
        :class:`~qiskit.transpiler.passes.HighLevelSynthesis` pass.
        Specifies how to synthesize various high-level objects.
    qubits_initially_zero (bool): Indicates whether the input circuit is
        zero-initialized.

Returns:
    PassManager: The basis translation pass manager

Raises:
    TranspilerError: If the ``method`` kwarg is not a valid value
Nr5   )r   r   r   r   r]   T)r   r   r]   r   r   r\   r   
clifford_tu)r\   r   r   r   r   r]   )r   r   r]   r   r   r\   r   r   )r\   r]   r   force_consolidateclifford
max_qubitsrb   )r   r   )httdgsk)r\   r   r   r   r   r   r]   r4   r   )r   r   r   r   r   r]   )r   r   r]   r   r\   r   r   )r]   r\   )r\   r]   r   )r   r   r]   r   r\   r   zInvalid translation method r|   )r   r   c                     U S   (       + $ r   rA   rL   s    rF   r   >generate_translation_passmanager.<locals>._direction_conditiony  r   rN   r   )r   r	   r   r   r   r   r&   COUNT_Tr   r   r
   r   r$   is_symmetricget_non_global_operation_namesr   r   r   r   has_angle_boundsr#   )r]   r\   r   r   r   r   r   r   r   r5   unrollfix_1qextended_basis_gatesr   s                 rF    generate_translation_passmanagerr     s   T v~2$S+>
 %9)=/ %)"&$''&; )
, 	<	  $K0C58
 0%9)=/ %)"&$'0&;$6$>$>	  C!5t< O %9"&	 J|Q>OP -%9)= C5s:
z %S+>
	;	 %9)=/ %)"&'&; &BO'Ma '%9)=/ %)"&'&;G+
Z O'Ma '%9)=/
  ;F81EFF 	\66vDDVZD[(EF	; 	!|;<vE.	
 f5577j()vrN   c           
         [        5       nU(       aH  [        [        [        [        S.nUR                  [	        XS95         UR                  XQ   " XS95        ODU (       a=  S nUR                  [        S5      5        UR                  [        [	        XS9US95        UR                  S	:w  d0  UR                  S	:w  d   UR                  S	:w  d  UR                  S	:w  ag  S
 nUR                  [        UR                  UR                  US95        UR                  [        [        UR                  UR                  US9US95        U(       a  UR                  [        X0S95        U$ ! [
         a  n[        SU S35      UeSnAff = f)aq  Generate a post optimization scheduling :class:`~qiskit.transpiler.PassManager`

Args:
    instruction_durations (dict): The dictionary of instruction durations
    scheduling_method (str): The scheduling method to use, can either be
        ``'asap'``/``'as_soon_as_possible'`` or
        ``'alap'``/``'as_late_as_possible'``
    timing_constraints (TimingConstraints): Hardware time alignment restrictions.
    target (Target): The :class:`~.Target` object representing the backend

Returns:
    PassManager: The scheduling pass manager

Raises:
    TranspilerError: If the ``scheduling_method`` kwarg is not a valid value
)r6   as_late_as_possibler7   as_soon_as_possibler   zInvalid scheduling method r|   Nc                     U S   $ )Ncontains_delayrA   rL   s    rF   _contains_delay,generate_scheduling.<locals>._contains_delay  s     011rN   delayr   rb   c                     U S   $ )Nreschedule_requiredrA   rL   s    rF   _require_alignment/generate_scheduling.<locals>._require_alignment  s     566rN   )acquire_alignmentpulse_alignmentr]   )r]   	durations)r   r   r   r   r   KeyErrorr$   r   r   granularity
min_lengthr   r   r   r   r   )	instruction_durationsr<   timing_constraintsr]   rz   	schedulerexr   r   s	            rF   generate_schedulingr    s   " J )#7(#7	
	 	,-BRS	]i:;P`a 
	2 	-g67!"#8HTc	
 	&&!+((A-//14--2	7 	$"4"F"F 2 B B	
 	!%&8&J&J$6$F$F!
 -		
 (&RS[  	]!$>?P>QQR"STZ\\	]s   E& &
F0F  F	VF2Limits)r   r   optimization_levelr8   initial_layoutexact_matchreturnc                 .   [        SS5      nUc  Uc  U S;   a  [        SS5      nOU S:X  a  [        SS5      nU(       aV  [        UR                  b  UR                  S-  =(       d    S	OSUR                  b  UR                  S-  =(       d    S	OS5      nU$ )
zGet the VF2 limits for VF2-based layout passes.

Returns:
    VF2Limits: An namedtuple with optional elements
    ``call_limit`` and ``max_trials``.
N>   rb      iP  i	  r   ii d   rb   )r  r   r   )r  r8   r  r  limitss        rF   get_vf2_limitsr    s     tT"F!7'F  1$F 5;5F5F5R&##s*0qX\5;5F5F5R&##s*0qX\F MrN   >   r   r   r   resetbarriermeasurec                     Ub  [        UR                  5      nOU b  [        U 5      nO
[        5       nU b  SU ;  a  SU ;  a  gUR                  [        5      $ )a"  
Checks whether the given basis set can be considered as Clifford+T.

For this we require that:
1. The set only contains Clifford+T gates,
2. The set contains either T or Tdg gate or both.

In particular, these conditions guarantee that the empty basis set
is not considered as Clifford+T.
r   r   F)rZ   rX   issubset_CLIFFORD_T_BASIS)r\   r]   basiss      rF   is_clifford_t_basisr     sX     F**+		 K #["8uK?W>>+,,rN   )NNNNNrA   N)NNFTN)NNF)Nr5   NNr.   NNTrd   )NN)Q__doc__collectionstypingr   "qiskit.circuit.equivalence_libraryr   r   qiskit.circuit.controlflowr   #qiskit.passmanager.flow_controllersr   qiskit.transpiler.passmanagerr   qiskit.transpiler.passesr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    *qiskit.transpiler.passes.layout.vf2_layoutr!   /qiskit.transpiler.passes.layout.vf2_post_layoutr"   r#   qiskit.transpiler.exceptionsr$   qiskit.transpiler.layoutr%   %qiskit.transpiler.optimization_metricr&   qiskit.utilsr'   :qiskit.quantum_info.operators.symplectic.clifford_circuitsr(   
namedtupler)   rZ   r   rM   rR   rT   r   r   r   COUNT_2Qr   r   r   r   r   r   r   r  r  intstrboolr  unionr  r  rA   rN   rF   <module>r,     sf   ,   O < E 5 * 4 3 6 2 4 5 7 - 2 C 7 7 9 9 : 7 0 ; 2 - = : 8 2 J S / 8 + D ' [  **+>@Z[ 
 '8ce (:V]H^ ,6E -i[ceT*35vvFVW  MQL L: .b  &$(*33@Fc ] #'`F 
	5 %F &$([|JZ "";0LM	
 $('+	C= V$ 	
 H ,-338>>?TU 
-$ -rN   