
    z	i                        S 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\	5      rSS jrg)9Expand a gate in a circuit using its decomposition rules.    )annotations)Sequence)Type)fnmatch)TransformationPass)control_flow)	DAGOpNode)
DAGCircuit)circuit_to_dag)Instruction   )HighLevelSynthesisc                  V   ^  \ rS rSrSr  S     SU 4S jjjrS	S jrS
S jrSrU =r	$ )	Decompose   r   c                :   > [         TU ]  5         Xl        X l        g)a  
Args:
    gates_to_decompose: optional subset of gates to be decomposed,
        identified by gate label, name or type. Defaults to all gates.
    apply_synthesis: If ``True``, run :class:`.HighLevelSynthesis` to synthesize operations
        that do not have a definition attached.
N)super__init__gates_to_decomposeapply_synthesis)selfr   r   	__class__s      b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/basis/decompose.pyr   Decompose.__init__"   s     	"4.    c                   U R                   (       a	  [        SS9OSnUR                  5        GH  nU R                  U5      (       d  M  UR	                  5       (       a=  [
        R                  " U R                  UR                  5      nUR                  X4SS9  Mn  [        UR                  SS5      cB  U R                   (       a/  [        U5      nUR                  U5      nUR                  X65        M  M  UR                  R                  R                  n[        U5      S:X  a  [        UR                   5      [        US   R"                  5      s=:X  a  S:X  a  O  O[        UR$                  5      [        US   R&                  5      s=:X  a  S:X  a{  O  OxUR                  R                  R(                  (       a3  U=R(                  UR                  R                  R(                  -  sl        UR                  X7S   R*                  SS9  GM  [-        UR                  R                  5      nUR                  X45        GM     U$ )	zrRun the Decompose pass on `dag`.

Args:
    dag: input dag.

Returns:
    output dag where ``gate`` was expanded.
F)qubits_initially_zeroNT)inplace
definition   r   )r   r   op_nodes_should_decomposeis_control_flowr	   
map_blocksrunopsubstitute_nodegetattr_node_to_dagsubstitute_node_with_dagr    datalenqargsqubitscargsclbitsglobal_phase	operationr   )r   daghlsnodedecompositionnode_as_dagsynthesizedrules           r   r&   Decompose.run4   s    BFAUAU u=[_ LLND))$//##%% , 7 7$'' J##D#F,5=''".t"4K"%''+"6K00C ( ww)).. INDJJ3tAw~~+>C!CDJJ3tAw~~+>C!Cww))66((DGG,>,>,K,KK(''1g.?.?'N$24773E3E$FM00E= #@ 
r   c                  ^ U R                   c  g[        U R                   [        5      (       d  U R                   /nOU R                   nU Vs/ s H  n[        U[        5      (       d  M  UPM     nnU Vs/ s H  n[        U[        5      (       d  M  UPM     nn[        TR                  SS5      bO  TR                  R                  S:w  a5  TR                  R                  U;   d  [        U4S jU 5       5      (       a  gTR                  U;   d  [        U4S jU 5       5      (       a  g[        U4S jU 5       5      (       a  ggs  snf s  snf )	zUCall a decomposition pass on this circuit to decompose one level (shallow decompose).NTlabel c              3  d   >#    U  H%  n[        TR                  R                  U5      v   M'     g 7fN)r   r'   r=   .0pr6   s     r   	<genexpr>.Decompose._should_decompose.<locals>.<genexpr>t   s%     -^Q]AgdggmmQ.G.GQ]s   -0c              3  P   >#    U  H  n[        TR                  U5      v   M     g 7fr@   )r   namerA   s     r   rD   rE   x   s"      '
+7aGDIIq!!<   #&c              3  P   >#    U  H  n[        TR                  U5      v   M     g 7fr@   )
isinstancer'   )rB   r'   r6   s     r   rD   rE   |   s     B>RDGGR((>rH   F)
r   rJ   liststrtyper)   r'   r=   anyrG   )r   r6   gatessstrings_listggate_type_lists    `     r   r#   Decompose._should_decomposec   s   ""*$11488,,-E++E#(?5aJq#,>5?%*BUjD.A!UB DGGWd+7#&#-^Q]-^*^*^ YY%3 '
+7'
 $
 $
 B>BBB% @Bs   E	*E	6EE)r   r   )NF)r   zBstr | Type[Instruction] | Sequence[str | Type[Instruction]] | Noner   boolreturnNone)r4   r   rV   r   )r6   r
   rV   rU   )
__name__
__module____qualname____firstlineno____doc__r   r&   r#   __static_attributes____classcell__)r   s   @r   r   r      sG    C  %/ O/
 / 
/ /$-^ r   r   c                    [        5       nUR                  U R                  5        UR                  U R                  5        UR                  U R                  U R                  U R                  5        U$ r@   )r   
add_qubitsr.   
add_clbitsr0   apply_operation_backr'   )r6   r4   s     r   r*   r*      sL    
,CNN4::NN4::TWWdjj$**=Jr   N)r6   r
   rV   r   )r\   
__future__r   collections.abcr   typingr   r   qiskit.transpiler.basepassesr   qiskit.transpiler.passes.utilsr	   qiskit.dagcircuit.dagnoder
   qiskit.dagcircuit.dagcircuitr    qiskit.converters.circuit_to_dagr   qiskit.circuit.instructionr   	synthesisr   r   r*    r   r   <module>rn      sA    @ " $   ; 7 / 3 ; 2 *`" `Fr   