
    z	i                         S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
Jr  SSKJrJr  SS	KJr  \(       a  SS
KJr   " S S\5      r " S S5      rg)z0Circuit operation representing a ``while`` loop.    )annotations)TYPE_CHECKING)ClassicalRegisterClbit)expr)CircuitError   )validate_conditioncondition_resources)ControlFlowOpQuantumCircuitc                     ^  \ rS rSrSr S     SU 4S jjjr\S 5       r\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r
S	 rS
rU =r$ )WhileLoopOp   zA circuit operation which repeatedly executes a subcircuit (``body``) until
a condition (``condition``) evaluates as False.

The classical bits used in ``condition`` must be a subset of those attached
to ``body``.
c                x   > UR                   nUR                  n[        TU ]  SXEU/US9  [	        U5      U l        g)a  
Args:
    condition: A condition to be checked prior to executing ``body``. Can be
        specified as either a tuple of a ``ClassicalRegister`` to be tested
        for equality with a given ``int``, or as a tuple of a ``Clbit`` to
        be compared to either a ``bool`` or an ``int``.
    body: The loop body to be repeatedly executed.
    label: An optional label for identifying the instruction.

while_looplabelN)
num_qubits
num_clbitssuper__init__r
   
_condition)self	conditionbodyr   r   r   	__class__s         _/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/controlflow/while_loop.pyr   WhileLoopOp.__init__%   s;     __
__
zvUS,Y7    c                    U R                   $ N_paramsr   s    r   paramsWhileLoopOp.params:   s    ||r!   c                    U R                   $ )z!The condition for the while loop.r   r&   s    r   r   WhileLoopOp.condition>   s     r!   c                    Xl         g r#   r*   )r   values     r   r   r+   C   s    r!   c                `   SSK Jn  Uu  n[        X25      (       d  [        S[	        U5       S35      eUR
                  U R
                  :w  d  UR                  U R                  :w  a@  [        SU R
                   SU R                   SUR
                   SUR                   S3	5      eU/U l        g )Nr   r   zJWhileLoopOp expects a body parameter of type QuantumCircuit, but received .zAttempted to assign a body parameter with a num_qubits or num_clbits different than that of the WhileLoopOp. WhileLoopOp num_qubits/clbits: /z" Supplied body num_qubits/clbits: )qiskit.circuitr   
isinstancer   typer   r   r%   )r   
parametersr   r   s       r   r'   r(   G   s     	2$//004T
|1> 
 ??doo-DOO1S226//1B!DOOCT U448OO3DAdooEVVWY  vr!   c                "    U R                   S   4$ )Nr   r$   r&   s    r   blocksWhileLoopOp.blocks^   s    Q!!r!   c                F    Uu  n[        U R                  X R                  S9$ )Nr   )r   r   r   )r   r6   r   s      r   replace_blocksWhileLoopOp.replace_blocksb   s    4??D

CCr!   )r   r%   r#   )r   =tuple[ClassicalRegister, int] | tuple[Clbit, int] | expr.Exprr   r   r   
str | None)__name__
__module____qualname____firstlineno____doc__r   propertyr'   r   setterr6   r9   __static_attributes____classcell__)r   s   @r   r   r      s     !	8P8 8 	8 8*         ]] , " "D Dr!   r   c                  D    \ rS rSrSrSrSS.     S	S jjrS rS rSr	g)
WhileLoopContextg   a  A context manager for building up while loops onto circuits in a natural order, without
having to construct the loop body first.

Within the block, a lot of the bookkeeping is done for you; you do not need to keep track of
which qubits and clbits you are using, for example.  All normal methods of accessing the qubits
on the underlying :obj:`~QuantumCircuit` will work correctly, and resolve into correct accesses
within the interior block.

You generally should never need to instantiate this object directly.  Instead, use
:obj:`.QuantumCircuit.while_loop` in its context-manager form, i.e. by not supplying a ``body``
or sets of qubits and clbits.

Example usage::

    from qiskit.circuit import QuantumCircuit, Clbit, Qubit
    bits = [Qubit(), Qubit(), Clbit()]
    qc = QuantumCircuit(bits)

    with qc.while_loop((bits[2], 0)):
        qc.h(0)
        qc.cx(0, 1)
        qc.measure(0, 0)

.. warning::

    This is an internal interface and no part of it should be relied upon outside of Qiskit
    Terra.
)_circuitr   _labelNr   c               <    Xl         [        U5      U l        X0l        g r#   )rI   r
   r   rJ   )r   circuitr   r   s       r   r   WhileLoopContext.__init__   s      ,Y7r!   c                    [        U R                  5      nU R                  R                  UR                  UR
                  S9  g )N)clbits	registers)r   r   rI   _push_scoperO   cregs)r   	resourcess     r   	__enter__WhileLoopContext.__enter__   s1    '8	!!)9)9Y__!Ur!   c                j   Ub  U R                   R                  5         gU R                   R                  5       nUR                  UR                  5       UR	                  5       5      nU R                   R                  [        U R                  XPR                  S9UR                  UR                  5        g)NFr   )	rI   
_pop_scopebuildqubitsrO   appendr   r   rJ   )r   exc_typeexc_valexc_tbscoper   s         r   __exit__WhileLoopContext.__exit__   s     MM$$&((* {{5<<>5<<>:[[AKKKK	

 r!   )rL   r   r   r;   r   r<   )
r=   r>   r?   r@   rA   	__slots__r   rT   r_   rD    r!   r   rG   rG   g   s@    : 5I !

 Q

 
Vr!   rG   N)rA   
__future__r   typingr   r1   r   r   qiskit.circuit.classicalr   qiskit.circuit.exceptionsr   _builder_utilsr
   r   control_flowr   r   r   rG   rb   r!   r   <module>ri      s@    7 "   3 ) 2 C '-GD- GDT? ?r!   