
    z	iw                        S r SSKJr  SSK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  SSKJr  SS	KJrJr  SS
KJrJrJr  SSKJr   " S S\R0                  5      r " S S\\S9r " S S\5      r " S S\5      rg)zBase transpiler passes.    )annotationsN)abstractmethod)CallableHashableIterable)	signature)QuantumCircuit)
DAGCircuit)GenericPassPassManagerIR)PropertySetRunStatePassManagerState   )TranspilerErrorc                  .    \ rS rSrSrS r\S 5       rSrg)MetaPass   zMetaclass for transpiler passes.

Enforces the creation of some fields in the pass while allowing passes to
override ``__init__``.
c                    [         R                  " U /UQ70 UD6n[        [        R	                  XU5      5      Ul        U$ N)type__call__hashr   _freeze_init_parameters_hash)clsargskwargspass_instances       V/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/basepasses.pyr   MetaPass.__call__0   s:    c;D;F;"8#C#CCv#VW    c                   [        5       n[        U R                  5      nUR                  " U/UQ70 UD6nSU R                  4/nUR
                  R                  5        Hf  u  pxX:X  a  M  [        U[        5      (       a  UR                  U[        U5      U45        M@  UR                  U[        U5      [        U5      45        Mh     [        U5      $ )Nzclass_.__name__)objectr   __init__bind__name__	argumentsitems
isinstancer   appendr   repr	frozenset)	class_r   r   
self_guardinit_signaturebound_signaturer(   namevalues	            r    r    MetaPass._freeze_init_parameters5   s    X
"6??3(--jJ4J6J'9:	*44::<KD"%**  $UU!;<  $UT%[!AB = ##r"    N)	r'   
__module____qualname____firstlineno____doc__r   staticmethodr   __static_attributes__r5   r"   r    r   r      s     $
 $ $r"   r   c                     ^  \ rS rSrSrU 4S jrS rS r\SS j5       r	\
S 5       r\
S 5       r S     SS	 jjrS
rU =r$ )BasePassE   z!Base class for transpiler passes.c                P   > [         TU ]  5         / U l        [        S 5      U l        g r   )superr%   	preservesr   r   )self	__class__s    r    r%   BasePass.__init__H   s     02$Z
r"   c                    U R                   $ r   )r   rB   s    r    __hash__BasePass.__hash__M   s    zzr"   c                0    [        U 5      [        U5      :H  $ r   )r   )rB   others     r    __eq__BasePass.__eq__P   s    
 DzT%[((r"   c                    [         e)zRun a pass on the DAGCircuit. This is implemented by the pass developer.

Args:
    dag: the dag on which the pass is run.

Raises:
    NotImplementedError: when this is left unimplemented for a pass.
)NotImplementedError)rB   dags     r    runBasePass.runW   s
     "!r"   c                "    [        U [        5      $ )zCheck if the pass is a transformation pass.

If the pass is a TransformationPass, that means that the pass can manipulate the DAG,
but cannot modify the property set (but it can be read).
)r*   TransformationPassrF   s    r    is_transformation_passBasePass.is_transformation_passc   s     $ 233r"   c                "    [        U [        5      $ )zCheck if the pass is an analysis pass.

If the pass is an AnalysisPass, that means that the pass can analyze the DAG and write
the results of that analysis in the property set. Modifications on the DAG are not allowed
by this kind of pass.
)r*   AnalysisPassrF   s    r    is_analysis_passBasePass.is_analysis_passl   s     $--r"   c                    SSK Jn  U" U /5      nUc  U R                  nUR                  XS9nUb9  X$R                  La+  UR	                  5         UR                  UR                  5        U$ )a  Runs the pass on circuit.

Args:
    circuit: The dag on which the pass is run.
    property_set: Input/output property set. An analysis pass might change the property set
        in-place.  If not given, the existing ``property_set`` attribute of the pass will
        be used (if set).

Returns:
    If on transformation pass, the resulting QuantumCircuit.
    If analysis pass, the input circuit.
r   )PassManager)property_set)qiskit.transpilerr[   r\   rP   clearupdate)rB   circuitr\   r[   pmouts         r    r   BasePass.__call__v   sj    " 	2$ 
 ,,LffWf8#OO(K  0
r"   )r   rA   )rO   r
   r   )r`   r	   r\   zPropertySet | dict | Nonereturnr	   )r'   r6   r7   r8   r9   r%   rG   rK   r   rP   propertyrT   rX   r   r;   __classcell__rC   s   @r    r=   r=   E   s|    + 
) 	" 	" 4 4 . . 37!! 0! 
	! !r"   r=   )	metaclassc                      \ rS rSrSrSrg)rW      z/An analysis pass: change property set, not DAG.r5   N)r'   r6   r7   r8   r9   r;   r5   r"   r    rW   rW      s    9r"   rW   c                  `   ^  \ rS rSrSr S       SU 4S jjjr      SU 4S jjrSrU =r$ )	rS      z4A transformation pass: change DAG, not property set.c                  > [         TU ]  UUUS9u  pBUR                  R                  [        R
                  :X  aC  [        U[        5      (       d.  [        SU R                  R                   S[        U5       35      eXB4$ )N)passmanager_irstatecallbackz?Transformation passes should return a transformed dag.The pass z is returning a )r@   executeworkflow_statusprevious_runr   SUCCESSr*   r
   r   rC   r'   r   )rB   rn   ro   rp   new_dagrC   s        r    rq   TransformationPass.execute   s     ) ) 
   --1A1AAgz22%  $ 7 788HgY 
 ~r"   c                   > [         TU ]  X5      nU[        R                  :X  a8  UR                  R
                  R                  [        U R                  5      5        U$ r   )	r@   update_statusr   rt   rr   completed_passesintersection_updatesetrA   )rB   ro   	run_staterC   s      r    rx    TransformationPass.update_status   sJ    
 %e7(((!!22FFs4>>GZ[r"   r5   r   )rn   r   ro   r   rp   r   rd   z&tuple[PassManagerIR, PassManagerState])ro   r   r|   r   rd   r   )	r'   r6   r7   r8   r9   rq   rx   r;   rf   rg   s   @r    rS   rS      sa    > "	%   	
 
0 *  
	 r"   rS   )r9   
__future__r   abcr   collections.abcr   r   r   inspectr   qiskit.circuitr	   qiskit.dagcircuitr
   qiskit.passmanager.base_tasksr   r   %qiskit.passmanager.compilation_statusr   r   r   
exceptionsr   ABCMetar   r=   rW   rS   r5   r"   r    <module>r      sh     " 
  8 8  ) ( D Y Y '%$s{{ %$PR{h Rj:8 :   r"   