
    z	i                        S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  \R                  (       a  SSKJrJr   " S	 S
\	5      r " S S5      rg)zSimple box basic block.    )annotationsN)Delay)CircuitError   )ControlFlowOp)QuantumCircuit
Annotationc                     ^  \ rS rSrSr    S         SU 4S jjjr\S 5       r\R                  S 5       r\S 5       r	\S 5       r
S rU 4S	 jrS
rU =r$ )BoxOp   aX  A scoped "box" of operations on a circuit that are treated atomically in the greater context.

A "box" is a control-flow construct that is entered unconditionally.  The contents of the box
behave somewhat as if the start and end of the box were barriers, except it is permissible to
commute operations "all the way" through the box.  The box is also an explicit scope for the
purposes of variables, stretches and compiler passes.

A box may be "annotated" with arbitrary user-defined custom :class:`.Annotation` objects.  In
cases where order is important, these should be interpreted by applying the first annotation in
the list first, then the second, and so on.  It is generally recommended that annotations should
not be order-dependent, wherever possible.

Typically you create this by using the builder-interface form of :meth:`.QuantumCircuit.box`.
c                   > [         TU ]  SUR                  UR                  U/US9  [	        U5      U l        [        R                  " X#5      u  U l        U l	        g)a  
Default constructor of :class:`BoxOp`.

Args:
    body: the circuit to use as the body of the box.  This should explicitly close over any
        :class:`.expr.Var` variables that must be incident from the outer circuit.  The
        required number of qubit and clbits for the resulting instruction are inferred from
        the number in the circuit, even if they are idle.
    duration: an optional duration for the box as a whole.
    unit: the unit of the ``duration``.
    label: an optional string label for the instruction.
    annotations: any :class:`.Annotation`\ s to apply to the box.  In cases where order
        is important, annotations are to be interpreted in the same order they appear in
        the iterable.
box)labelN)
super__init__
num_qubits
num_clbitslistr   r   _validate_argumentsdurationunit)selfbodyr   r   r   r   	__class__s         X/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/controlflow/box.pyr   BoxOp.__init__+   sN    . 	4&PUV,#(#<#<X#L ty    c                    U R                   $ N_paramsr   s    r   paramsBoxOp.paramsF   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   zDBoxOp 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 BoxOp. BoxOp num_qubits/clbits: /z" Supplied body num_qubits/clbits: )qiskit.circuitr   
isinstancer   typer   r   r!   )r   
parametersr   r   s       r   r#   r$   J   s     	2$//004T
|1> 
 ??doo-DOO1S,,0OO+<Adoo=N O448OO3DAdooEVVWY  vr   c                     U R                   S   $ )zThe ``body`` :class:`.QuantumCircuit` of the operation.

This is the same object returned as the sole entry in :meth:`params` and :meth:`blocks`.
r   )r#   r"   s    r   r   
BoxOp.bodya   s     {{1~r   c                "    U R                   S   4$ )Nr   r    r"   s    r   blocksBoxOp.blocksk   s    Q!!r   c                t    Uu  n[        UU R                  U R                  U R                  U R                  S9$ )Nr   r   r   r   )r   r   r   r   r   )r   r/   r   s      r   replace_blocksBoxOp.replace_blockso   s7    ]]**((
 	
r   c                  > [        U[        5      =(       ao    U R                  UR                  :H  =(       aO    U R                  UR                  :H  =(       a/    U R                  UR                  :H  =(       a    [
        TU ]  U5      $ r   )r)   r   r   r   r   r   __eq__)r   otherr   s     r   r6   BoxOp.__eq__y   sj    ue$ &/&		UZZ'&   E$5$55& u%	
r   )r!   r   r   r   )NNN )
r   r   r   Noner   z@typing.Literal['dt', 's', 'ms', 'us', 'ns', 'ps', 'expr'] | Noner   
str | Noner   typing.Iterable[Annotation])__name__
__module____qualname____firstlineno____doc__r   propertyr#   setterr   r/   r3   r6   __static_attributes____classcell__)r   s   @r   r   r      s    $ QU 35MM M O	M
 M 1M M6   ]] ,   " "

 
r   r   c                  R    \ rS rSrSrSrSSSSS.         SS jjrS	 rS
 rSr	g)
BoxContext   zContext-manager that powers :meth:`.QuantumCircuit.box`.

This is not part of the public interface, and should not be instantiated by users.
_circuit	_duration_unit_label_annotationsNdtr9   r2   c               @    Xl         X l        X0l        X@l        XPl        g)z
Args:
    circuit: the outermost scope of the circuit under construction.
    duration: the final duration of the box.
    unit: the unit of ``duration``.
    label: an optional label for the box.
NrI   )r   circuitr   r   r   r   s         r   r   BoxContext.__init__   s       !
'r   c                6    U R                   R                  SS9  g )NF)allow_jumps)rJ   _push_scoper"   s    r   	__enter__BoxContext.__enter__   s     	!!e!4r   c           
        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U R                  U R                  U R                  U R                  S9UR                  UR                  5        g)NFr2   )rJ   
_pop_scopebuildqubitsclbitsappendr   rK   rL   rM   rN   )r   exc_typeexc_valexc_tbscoper   s         r   __exit__BoxContext.__exit__   s     MM$$&((* {{5<<>5<<>:ZZkk -- KKKK
	
 r   )rN   rJ   rK   rM   rL   )
rQ   r   r   r:   r   z1typing.Literal['dt', 's', 'ms', 'us', 'ns', 'ps']r   r;   r   r<   )
r=   r>   r?   r@   rA   	__slots__r   rV   rb   rD   r9   r   r   rG   rG      s]    
 MI BF 35(( 	(
 @( ( 1(,5r   rG   )rA   
__future__r   typingqiskit.circuit.delayr   qiskit.circuit.exceptionsr   control_flowr   TYPE_CHECKINGr(   r   r	   r   rG   r9   r   r   <module>rk      s>     "  & 2 '	9e
M e
P9 9r   