
    z	i@	                     l    S r SSKrSSKJr  SSKJr  SSKJrJr  SSK	J
r
  S\\
/\
4   S\S	\4S
 jrS rg)z<Internal utilities for working with control-flow operations.    N)Callable)ControlFlowOp)circuit_to_dagdag_to_circuit)
DAGCircuitdag_mappingopreturnc                     UR                  UR                   Vs/ s H  n[        U " [        U5      5      SS9PM     sn5      $ s  snf )zUse the ``dag_mapping`` function to replace the blocks of a :class:`.ControlFlowOp` with new
ones.  Each block will be automatically converted to a :class:`.DAGCircuit` and then returned
to a :class:`.QuantumCircuit`.F)copy_operations)replace_blocksblocksr   r   )r   r	   blocks      e/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/utils/control_flow.py
map_blocksr      sN      	
" ;~e'<=uU"	
 	
s   #Ac                 J   ^ ^ [         R                  " T 5      U U4S j5       mT$ )a  Decorator that causes :class:`.BasePass.run` to iterate over all control-flow nodes,
replacing their operations with a new :class:`.ControlFlowOp` whose blocks have all had
:class`.BasePass.run` called on them.

This is only suitable for simple run calls that store no state between calls, do not need
circuit-specific information feeding into them (such as via a :class:`.PropertySet`), and will
safely do nothing to control-flow operations that are in the DAG.

If slightly finer control is needed on when the control-flow operations are modified, one can
use :func:`map_blocks` as::

    if isinstance(node.op, ControlFlowOp):
        dag.substitute_node(node, map_blocks(self.run, node.op))

from with :meth:`.BasePass.run`.c                    >^  UU 4S jnUR                  5        H(  nUR                  U[        X#R                  5      5        M*     T" T U5      $ )Nc                    > T" TU 5      $ )N )dagoutselfs    r   bound_wrapped_method:trivial_recurse.<locals>.out.<locals>.bound_wrapped_method6   s    tS>!    )control_flow_op_nodessubstitute_noder   r	   )r   r   r   nodemethodr   s   `   r   r   trivial_recurse.<locals>.out4   sD    	" --/Dj1Eww&OP 0dC  r   )	functoolswraps)r   r   s   `@r   trivial_recurser#   #   s'    " __V! ! Jr   )__doc__r!   typingr   qiskit.circuitr   qiskit.convertersr   r   qiskit.dagcircuitr   r   r#   r   r   r   <module>r)      sF    C   ( < (	Hj\:%=> 	M 	Vc 	r   