§
    º³Ùgä	  ã                   ór   — d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
 dee
ge
f         ded	efd
„Zd„ ZdS )z<Internal utilities for working with control-flow operations.é    N)ÚCallable)ÚControlFlowOp)Úcircuit_to_dagÚdag_to_circuit)Ú
DAGCircuitÚdag_mappingÚopÚreturnc                 óP   ‡ — |                      ˆ fd„|j        D ¦   «         ¦  «        S )záUse 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`.c           	      ó^   •— g | ])}t           ‰t          |¦  «        ¦  «        d ¬¦  «        ‘Œ*S )F)Úcopy_operations)r   r   )Ú.0Úblockr   s     €úa/granary/edev/quantum/lib/python3.11/site-packages/qiskit/transpiler/passes/utils/control_flow.pyú
<listcomp>zmap_blocks.<locals>.<listcomp>   sH   ø€ ð 	
ð 	
ð 	
àõ ˜;˜;¥~°eÑ'<Ô'<Ñ=Ô=ÈuÐUÑUÔUð	
ð 	
ð 	
ó    )Úreplace_blocksÚblocks)r   r	   s   ` r   Ú
map_blocksr      sE   ø€ ð ×Òð	
ð 	
ð 	
ð 	
àœð	
ñ 	
ô 	
ñô ð r   c                 óJ   ‡ ‡— t          j        ‰ ¦  «        ˆ ˆfd„¦   «         Š‰S )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                 ó¶   •‡ — ˆˆ fd„}|                      ¦   «         }|�0|D ]-}|                     |t          ||j        ¦  «        d¬¦  «         Œ. ‰‰ |¦  «        S )Nc                 ó   •—  ‰‰| ¦  «        S )N© )ÚdagÚoutÚselfs    €€r   Úbound_wrapped_methodz:trivial_recurse.<locals>.out.<locals>.bound_wrapped_method6   s   ø€ Ø�3�t˜S‘>”>Ð!r   F)Úpropagate_condition)Úcontrol_flow_op_nodesÚsubstitute_noder   r	   )r   r   r   Úcontrol_flow_nodesÚnodeÚmethodr   s   `    €€r   r   ztrivial_recurse.<locals>.out4   s–   øø€ ð	"ð 	"ð 	"ð 	"ð 	"ð 	"ð !×6Ò6Ñ8Ô8ÐØÐ)Ø*ð ð �Ø×#Ò#Ø�*Ð%9¸4¼7ÑCÔCÐY^ð $ñ ô ð ð ð ˆv�d˜CÑ Ô Ð 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,      s·   ðð CÐ Bà Ð Ð Ð Ø Ð Ð Ð Ð Ð à (Ð (Ð (Ð (Ð (Ð (Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ø (Ð (Ð (Ð (Ð (Ð (ð	˜H j \°:Ð%=Ô>ð 	ÀMð 	ÐVcð 	ð 	ð 	ð 	ðð ð ð ð r   