
    z	i0                     `    S r SSKJrJrJrJr  SSKJr  SSKJ	r	  SSK
Jr   " S S\5      rS rg	)
z"UnrollForLoops transpilation pass     )	ForLoopOpContinueLoopOpBreakLoopOpIfElseOp)TransformationPass)control_flow)circuit_to_dagc                   T   ^  \ rS rSrSrSU 4S jjr\R                  S 5       rSr	U =r
$ )UnrollForLoops   zF``UnrollForLoops`` transpilation pass unrolls for-loops when possible.c                 .   > [         TU ]  5         Xl        g)a  Things like ``for x in {0, 3, 4} {rx(x) qr[1];}`` will turn into
``rx(0) qr[1]; rx(3) qr[1]; rx(4) qr[1];``.

.. note::
    The ``UnrollForLoops`` unrolls only one level of block depth. No inner loop will
    be considered by ``max_target_depth``.

Args:
    max_target_depth (int): Optional. Checks if the unrolled block is over a particular
        subcircuit depth. To disable the check, use ``-1`` (Default).
N)super__init__max_target_depth)selfr   	__class__s     h/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/transpiler/passes/utils/unroll_forloops.pyr   UnrollForLoops.__init__   s     	 0    c                    UR                  [        5       H  nUR                  R                  u  p4nSU R                  s=:  a   [        U5      UR                  5       -  :  a  O  OMR  [        U5      (       a  Md  [        U5      R                  5       nU H7  nU(       a  UR                  XG05      OUnUR                  [        U5      SS9  M9     UR                  X&5        M     U$ )zRun the UnrollForLoops pass on ``dag``.

Args:
    dag (DAGCircuit): the directed acyclic graph to run on.

Returns:
    DAGCircuit: Transformed DAG.
r   T)inplace)op_nodesr   opparamsr   lendepth _body_contains_continue_or_breakr	   copy_empty_likeassign_parameterscomposesubstitute_node_with_dag)	r   dag
forloop_opindexset
loop_parambodyunrolled_dagindex_value
bound_bodys	            r   runUnrollForLoops.run'   s     ,,y1J+5==+?+?(X4 4((G3x=4::<+GG 055)$/??AL'ISD**J+DEY]  $$^J%?$N	  (
 ((B# 2& 
r   )r   ))__name__
__module____qualname____firstlineno____doc__r   r   trivial_recurser*   __static_attributes____classcell__)r   s   @r   r   r      s%    P1 !! "r   r   c                     U R                    Hi  nUR                  n[        U[        [        45      (       a    g[        U[
        5      (       d  MC  UR                   H  n[        U5      (       d  M      g   Mk     g)z[Checks if a circuit contains ``continue``s or ``break``s. Conditional bodies are inspected.TF)data	operation
isinstancer   r   r   r   r   )circuitinstr7   blocks       r   r   r   G   s^    NN	i.+!>??i**"))3E:: *  r   N)r1   qiskit.circuitr   r   r   r   qiskit.transpiler.basepassesr   qiskit.transpiler.passes.utilsr   qiskit.convertersr	   r   r    r   r   <module>rA      s,    * K K ; 7 ,/' /d
r   