§
    ¹³ÙgÎw  ã                  óp  — d Z ddlmZ ddlZddlZddlZddlmZmZmZm	Z	m
Z
mZmZ ddlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZ ddlmZ ddlm Z m!Z! ej"        rddl#Z# G d„ dej$        ¦  «        Z% G d„ dej&        ¦  «        Z' G d„ deej$        ¦  «        Z( G d„ de%¦  «        Z)dS )z4Builder types for the basic control-flow constructs.é    )ÚannotationsN)Ú
CollectionÚIterableÚ	FrozenSetÚTupleÚUnionÚOptionalÚSequence)ÚCircuitData)Úexpr)ÚClbitÚClassicalRegister©ÚCircuitError)ÚInstruction)ÚCircuitInstruction)ÚQubitÚQuantumRegister)ÚRegisteré   )Úcondition_resourcesÚnode_resourcesc                  ó<  — e Zd ZdZdZeej        dd„¦   «         ¦   «         Zej        ddœdd
„¦   «         Z	ej        dd„¦   «         Z
ej        dd„¦   «         Zej        d d„¦   «         Zej        d d„¦   «         Zej        d d„¦   «         Zej        d!d„¦   «         ZdS )"ÚCircuitScopeInterfaceaã  An interface that circuits and builder blocks explicitly fulfill, which contains the primitive
    methods of circuit construction and object validation.

    This allows core circuit methods to be applied to the currently open builder scope, and allows
    the builders to hook into all places where circuit resources might be used.  This allows the
    builders to track the resources being used, without getting in the way of
    :class:`.QuantumCircuit` doing its own thing.
    © ÚreturnúSequence[CircuitInstruction]c                ó   — dS )zIIndexable view onto the :class:`.CircuitInstruction`s backing this scope.Nr   ©Úselfs    úX/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/controlflow/builder.pyÚinstructionsz"CircuitScopeInterface.instructions6   ó   € € € ó    F©Ú_standard_gateÚinstructionr   c               ó   — dS )aí  Low-level 'append' primitive; this may assume that the qubits, clbits and operation are
        all valid for the circuit.

        Abstraction of :meth:`.QuantumCircuit._append` (the low-level one, not the high-level).

        Args:
            instruction: the resource-validated instruction context object.

        Returns:
            the instruction context object actually appended.  This is not required to be the same
            as the object given (but typically will be).
        Nr   )r    r'   r&   s      r!   ÚappendzCircuitScopeInterface.append;   r#   r$   Údatar   c                ó   — dS )zwAppends all instructions from ``data`` to the scope.

        Args:
            data: The instruction listing.
        Nr   )r    r*   s     r!   ÚextendzCircuitScopeInterface.extendL   r#   r$   Ú	specifierúClbit | ClassicalRegister | intúClbit | ClassicalRegisterc                ó   — dS )aC  Resolve a single bit-like classical-resource specifier.

        A resource refers to either a classical bit or a register, where integers index into the
        classical bits of the greater circuit.

        This is called whenever a classical bit or register is being used outside the standard
        :class:`.Clbit` usage of instructions in :meth:`append`, such as in a legacy two-tuple
        condition.

        Args:
            specifier: the classical resource specifier.

        Returns:
            the resolved resource.  This cannot be an integer any more; an integer input is resolved
            into a classical bit.

        Raises:
            CircuitError: if the resource cannot be used by the scope, such as an out-of-range index
                or a :class:`.Clbit` that isn't actually in the circuit.
        Nr   )r    r-   s     r!   Úresolve_classical_resourcez0CircuitScopeInterface.resolve_classical_resourceT   r#   r$   Úvarúexpr.Varc                ó   — dS )aÁ  Add an uninitialized variable to the circuit scope.

        The general circuit context is responsible for ensuring the variable is initialized.  These
        uninitialized variables are guaranteed to be standalone.

        Args:
            var: the variable to add, if valid.

        Raises:
            CircuitError: if the variable cannot be added, such as because it invalidly shadows or
                redefines an existing name.
        Nr   ©r    r2   s     r!   Úadd_uninitialized_varz+CircuitScopeInterface.add_uninitialized_varm   r#   r$   c                ó   — dS )aj  Remove a variable from the locals of this scope.

        This is only called in the case that an exception occurred while initializing the variable,
        and is not exposed to users.

        Args:
            var: the variable to remove.  It can be assumed that this was already the subject of an
                :meth:`add_uninitialized_var` call.
        Nr   r5   s     r!   Ú
remove_varz CircuitScopeInterface.remove_var|   r#   r$   c                ó   — dS )a  Called for every standalone classical real-time variable being used by some circuit
        instruction.

        The given variable is guaranteed to be a stand-alone variable; bit-like resource-wrapping
        variables will have been filtered out and their resources given to
        :meth:`resolve_classical_resource`.

        Args:
            var: the variable to validate.

        Returns:
            the same variable.

        Raises:
            CircuitError: if the variable is not valid for this scope.
        Nr   r5   s     r!   Úuse_varzCircuitScopeInterface.use_varˆ   r#   r$   ÚnameÚstrúOptional[expr.Var]c                ó   — dS )a^  Get the variable (if any) in scope with the given name.

        This should call up to the parent scope if in a control-flow builder scope, in case the
        variable exists in an outer scope.

        Args:
            name: the name of the symbol to lookup.

        Returns:
            the variable if it is found, otherwise ``None``.
        Nr   )r    r;   s     r!   Úget_varzCircuitScopeInterface.get_var›   r#   r$   N)r   r   )r'   r   r   r   ©r*   r   )r-   r.   r   r/   ©r2   r3   )r;   r<   r   r=   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚpropertyÚabcÚabstractmethodr"   r)   r,   r1   r6   r8   r:   r?   r   r$   r!   r   r   *   s^  € € € € € ðð ð €IàØÔðXð Xð Xñ Ôñ „XðXð 	ÔàAFðð ð ð ð ñ Ôðð  	Ôðð ð ñ Ôðð 	Ôðð ð ñ Ôðð0 	Ôðð ð ñ Ôðð 	Ôð	ð 	ð 	ñ Ôð	ð 	Ôðð ð ñ Ôðð$ 	Ôðð ð ñ Ôðð ð r$   r   c                  óL   — e Zd ZU dZdZded<   dZded<   dZded<   dZd	ed
<   dS )ÚInstructionResourcesa#  The quantum and classical resources used within a particular instruction.

    .. warning::

        This is an internal interface and no part of it should be relied upon outside of Qiskit
        Terra.

    Attributes:
        qubits: A collection of qubits that will be used by the instruction.
        clbits: A collection of clbits that will be used by the instruction.
        qregs: A collection of quantum registers that are used by the instruction.
        cregs: A collection of classical registers that are used by the instruction.
    r   zCollection[Qubit]ÚqubitszCollection[Clbit]ÚclbitszCollection[QuantumRegister]ÚqregszCollection[ClassicalRegister]ÚcregsN)	rB   rC   rD   rE   rL   Ú__annotations__rM   rN   rO   r   r$   r!   rK   rK   ª   sb   € € € € € € ðð ð !#€FÐ"Ð"Ð"Ñ"Ø "€FÐ"Ð"Ð"Ñ"Ø)+€EÐ+Ð+Ð+Ñ+Ø+-€EÐ-Ð-Ð-Ñ-Ð-Ð-r$   rK   c                  ón   — e Zd ZdZdZej        dd	„¦   «         Zej        dd„¦   «         Zdd„Z	d„ Z
d„ ZdS )ÚInstructionPlaceholdera©  A fake instruction that lies about its number of qubits and clbits.

    These instances are used to temporarily represent control-flow instructions during the builder
    process, when their lengths cannot be known until the end of the block.  This is necessary to
    allow constructs like::

        with qc.for_loop(range(5)):
            qc.h(0)
            qc.measure(0, 0)
            qc.break_loop().c_if(0, 0)

    since ``qc.break_loop()`` needs to return a (mostly) functional
    :obj:`~qiskit.circuit.Instruction` in order for :meth:`.InstructionSet.c_if` to work correctly.

    When appending a placeholder instruction into a circuit scope, you should create the
    placeholder, and then ask it what resources it should be considered as using from the start by
    calling :meth:`.InstructionPlaceholder.placeholder_instructions`.  This set will be a subset of
    the final resources it asks for, but it is used for initializing resources that *must* be
    supplied, such as the bits used in the conditions of placeholder ``if`` statements.

    .. warning::

        This is an internal interface and no part of it should be relied upon outside of Qiskit
        Terra.
    TrL   úFrozenSet[Qubit]rM   úFrozenSet[Clbit]r   ú(Tuple[Instruction, InstructionResources]c                ó   — t           ‚)a˜  Get a concrete, complete instruction that is valid to act over all the given resources.

        The returned resources may not be the full width of the given resources, but will certainly
        be a subset of them; this can occur if (for example) a placeholder ``if`` statement is
        present, but does not itself contain any placeholder instructions.  For resource efficiency,
        the returned :class:`.ControlFlowOp` will not unnecessarily span all resources, but only the
        ones that it needs.

        .. note::

            The caller of this function is responsible for ensuring that the inputs to this function
            are non-strict supersets of the bits returned by :meth:`placeholder_resources`.

        Any condition added in by a call to :obj:`.Instruction.c_if` will be propagated through, but
        set properties like ``duration`` will not; it doesn't make sense for control-flow operations
        to have pulse scheduling on them.

        Args:
            qubits: The qubits the created instruction should be defined across.
            clbits: The clbits the created instruction should be defined across.

        Returns:
            A full version of the relevant control-flow instruction, and the resources that it uses.
            This is a "proper" instruction instance, as if it had been defined with the correct
            number of qubits and clbits from the beginning.
        ©ÚNotImplementedError)r    rL   rM   s      r!   Úconcrete_instructionz+InstructionPlaceholder.concrete_instructionÜ   s
   € õ< "Ð!r$   rK   c                ó   — t           ‚)aZ  Get the qubit and clbit resources that this placeholder instruction should be considered
        as using before construction.

        This will likely not include *all* resources after the block has been built, but using the
        output of this method ensures that all resources will pass through a
        :meth:`.QuantumCircuit.append` call, even if they come from a placeholder, and consequently
        will be tracked by the scope managers.

        Returns:
            A collection of the quantum and classical resources this placeholder instruction will
            certainly use.
        rW   r   s    r!   Úplaceholder_resourcesz,InstructionPlaceholder.placeholder_resourcesü   s
   € õ "Ð!r$   r'   r   c                ó   — | j         |_         |S )aé  Copy mutable properties from ourselves onto a non-placeholder instruction.

        The mutable properties are expected to be things like ``condition``, added onto a
        placeholder by the :meth:`c_if` method.  This mutates ``instruction``, and returns the same
        instance that was passed.  This is mostly intended to make writing concrete versions of
        :meth:`.concrete_instruction` easy.

        The complete list of mutations is:

        * ``condition``, added by :meth:`c_if`.

        Args:
            instruction: the concrete instruction instance to be mutated.

        Returns:
            The same instruction instance that was passed, but mutated to propagate the tracked
            changes to this class.
        )Ú
_condition)r    r'   s     r!   Ú_copy_mutable_propertiesz/InstructionPlaceholder._copy_mutable_properties  s   € ð& "&¤ˆÔØÐr$   c                ó    — t          d¦  «        ‚)Nz*Cannot assemble a placeholder instruction.r   r   s    r!   ÚassemblezInstructionPlaceholder.assemble%  s   € ÝÐGÑHÔHÐHr$   c                ó    — t          d¦  «        ‚)Nz(Cannot repeat a placeholder instruction.r   )r    Úns     r!   ÚrepeatzInstructionPlaceholder.repeat(  s   € ÝÐEÑFÔFÐFr$   N)rL   rS   rM   rT   r   rU   )r   rK   )r'   r   r   r   )rB   rC   rD   rE   Ú
_directiverH   rI   rY   r[   r^   r`   rc   r   r$   r!   rR   rR   ¿   s¥   € € € € € ðð ð4 €JàÔð"ð "ð "ñ Ôð"ð> 	Ôð"ð "ð "ñ Ôð"ðð ð ð ð2Ið Ið IðGð Gð Gð Gð Gr$   rR   c                  óî   — e Zd ZdZdZddddœd>d„Zd„ Zd„ Zed„ ¦   «         Z	ed„ ¦   «         Z
ed„ ¦   «         Zddœd?d„Zd@d"„Zd#„ ZdAd&„ZdAd'„ZdBd*„ZdAd+„Zd,„ Zd-„ ZdCd.„ZdCd/„ZdDd2„ZdEd5„ZdFd;„ZdGd=„ZdS )HÚControlFlowBuilderBlocka…  A lightweight scoped block for holding instructions within a control-flow builder context.

    This class is designed only to be used by :obj:`.QuantumCircuit` as an internal context for
    control-flow builder instructions, and in general should never be instantiated by any code other
    than that.

    Note that the instructions that are added to this scope may not be valid yet, so this elides
    some of the type-checking of :obj:`.QuantumCircuit` until those things are known.

    The general principle of the resource tracking through these builder blocks is that every
    necessary resource should pass through an :meth:`.append` call, so that at the point that
    :meth:`.build` is called, the scope knows all the concrete resources that it requires.  However,
    the scope can also contain "placeholder" instructions, which may need extra resources filling in
    from outer scopes (such as a ``break`` needing to know the width of its containing ``for``
    loop).  This means that :meth:`.build` takes all the *containing* scope's resources as well.
    This does not break the "all resources pass through an append" rule, because the containing
    scope will only begin to build its instructions once it has received them all.

    In short, :meth:`.append` adds resources, and :meth:`.build` may use only a subset of the extra
    ones passed.  This ensures that all instructions know about all the resources they need, even in
    the case of ``break``, but do not block any resources that they do *not* need.

    .. warning::

        This is an internal interface and no part of it should be relied upon outside of Qiskit
        Terra.
    )	Ú_instructionsÚ	registersÚglobal_phaseÚ_allow_jumpsÚ_parentÚ_builtÚ_forbidden_messageÚ_vars_localÚ_vars_capturer   TN)rh   Úallow_jumpsÚforbidden_messagerL   úIterable[Qubit]rM   úIterable[Clbit]Úparentr   rh   úIterable[Register]rp   Úboolrq   úOptional[str]c               óº   — t          ||¦  «        | _        t          |¦  «        | _        d| _        i | _        i | _        || _        || _        d| _	        || _
        dS )a»  
        Args:
            qubits: Any qubits this scope should consider itself as using from the beginning.
            clbits: Any clbits this scope should consider itself as using from the beginning.  Along
                with ``qubits``, this is useful for things such as ``if`` and ``while`` loop
                builders, where the classical condition has associated resources, and is known when
                this scope is created.
            registers: Any registers this scope should consider itself as using from the
                beginning.  This is useful for :obj:`.IfElseOp` and :obj:`.WhileLoopOp` instances
                which use a classical register as their condition.
            allow_jumps: Whether this builder scope should allow ``break`` and ``continue``
                statements within it.  This is intended to help give sensible error messages when
                dangerous behavior is encountered, such as using ``break`` inside an ``if`` context
                manager that is not within a ``for`` manager.  This can only be safe if the user is
                going to place the resulting :obj:`.QuantumCircuit` inside a :obj:`.ForLoopOp` that
                uses *exactly* the same set of resources.  We cannot verify this from within the
                builder interface (and it is too expensive to do when the ``for`` op is made), so we
                fail safe, and require the user to use the more verbose, internal form.
            parent: The scope interface of the containing scope.
            forbidden_message: If a string is given here, a :exc:`.CircuitError` will be raised on
                any attempts to append instructions to the scope with this message.  This is used by
                pseudo scopes where the state machine of the builder scopes has changed into a
                position where no instructions should be accepted, such as when inside a ``switch``
                but outside any cases.
        g        FN)r   rg   Úsetrh   ri   rn   ro   rj   rk   rl   rm   )r    rL   rM   rt   rh   rp   rq   s          r!   Ú__init__z ControlFlowBuilderBlock.__init__U  s`   € õF )¨°Ñ8Ô8ˆÔÝ˜Y™œˆŒØˆÔØˆÔØˆÔØ'ˆÔØˆŒØˆŒØ"3ˆÔÐÐr$   c                ó4   — t          | j        j        ¦  «        S )z-The set of qubits associated with this scope.)ry   r"   rL   r   s    r!   rL   zControlFlowBuilderBlock.qubits‚  ó   € å�4Ô$Ô+Ñ,Ô,Ð,r$   c                ó4   — t          | j        j        ¦  «        S )z-The set of clbits associated with this scope.)ry   r"   rM   r   s    r!   rM   zControlFlowBuilderBlock.clbits†  r|   r$   c                ó   — | j         S )a¿  Whether this builder scope should allow ``break`` and ``continue`` statements within it.

        This is intended to help give sensible error messages when dangerous behavior is
        encountered, such as using ``break`` inside an ``if`` context manager that is not within a
        ``for`` manager.  This can only be safe if the user is going to place the resulting
        :obj:`.QuantumCircuit` inside a :obj:`.ForLoopOp` that uses *exactly* the same set of
        resources.  We cannot verify this from within the builder interface (and it is too expensive
        to do when the ``for`` op is made), so we fail safe, and require the user to use the more
        verbose, internal form.
        )rj   r   s    r!   rp   z#ControlFlowBuilderBlock.allow_jumpsŠ  s   € ð Ô Ð r$   c                ó   — | j         S ©N)rg   r   s    r!   r"   z$ControlFlowBuilderBlock.instructions˜  s   € àÔ!Ð!r$   c                ó‚   — ddl m}m} ddlm}m} ||||f}t          | |¦  «        rt          d| j        › d�¦  «        ‚d S )Nr   )ÚBreakLoopOpÚBreakLoopPlaceholder)ÚContinueLoopOpÚContinueLoopPlaceholderz)The current builder scope cannot take a 'z' because it is not in a loop.)	Ú
break_loopr‚   rƒ   Úcontinue_loopr„   r…   Ú
isinstancer   r;   )Ú	operationr‚   rƒ   r„   r…   Ú	forbiddens         r!   Ú_raise_on_jumpz&ControlFlowBuilderBlock._raise_on_jumpœ  s‹   € ð 	BÐAÐAÐAÐAÐAÐAÐAØJÐJÐJÐJÐJÐJÐJÐJà Ð"6¸ÐH_Ð`ˆ	Ý�i Ñ+Ô+ð 	Ýð0¸I¼Nð 0ð 0ð 0ñô ð ð	ð 	r$   Fr%   r'   r   r&   r   c               óJ  — | j         �t          | j         ¦  «        ‚| j        s|                      |j        ¦  «         |j        D ]}| j                             |d¬¦  «         Œ|j        D ]}| j         	                    |d¬¦  «         Œ| j
                             |¦  «         |S ©NF©Ústrict)rm   r   rj   r‹   r‰   rL   r"   Ú	add_qubitrM   Ú	add_clbitrg   r)   )r    r'   r&   Úbs       r!   r)   zControlFlowBuilderBlock.append©  s¿   € ð Ô"Ð.Ý˜tÔ6Ñ7Ô7Ð7ØÔ ð 	7Ø×Ò Ô 5Ñ6Ô6Ð6ØÔ#ð 	9ð 	9ˆAØÔ×'Ò'¨°%Ð'Ñ8Ô8Ð8Ð8ØÔ#ð 	9ð 	9ˆAØÔ×'Ò'¨°%Ð'Ñ8Ô8Ð8Ð8ØÔ×!Ò! +Ñ.Ô.Ð.ØÐr$   r*   r   c                óˆ  — | j         �t          | j         ¦  «        ‚| j        s|                     | j        ¦  «         |                     ¦   «         \  }}|j        D ]"}||v r| j                             |d¬¦  «         Œ#|j	        D ]"}||v r| j         
                    |d¬¦  «         Œ#| j                             |¦  «         d S r�   )rm   r   rj   Ú
foreach_opr‹   Úactive_bitsrL   r"   r�   rM   r‘   r,   )r    r*   Úactive_qubitsÚactive_clbitsr’   s        r!   r,   zControlFlowBuilderBlock.extend·  sá   € ØÔ"Ð.Ý˜tÔ6Ñ7Ô7Ð7ØÔ ð 	1Ø�OŠO˜DÔ/Ñ0Ô0Ð0Ø'+×'7Ò'7Ñ'9Ô'9Ñ$ˆ�}à”ð 	=ð 	=ˆAØ�MÐ!Ð!ØÔ!×+Ò+¨A°eÐ+Ñ<Ô<Ð<øØ”ð 	=ð 	=ˆAØ�MÐ!Ð!ØÔ!×+Ò+¨A°eÐ+Ñ<Ô<Ð<øØÔ× Ò  Ñ&Ô&Ð&Ð&Ð&r$   c                óè   — | j         rt          d¦  «        ‚| j                             |¦  «        }t	          |t
          ¦  «        r|                      |f¦  «         n|                      |¦  «         |S )Nú4Cannot add resources after the scope has been built.)rl   r   rk   r1   rˆ   r   Úadd_bitsÚadd_register)r    r-   Úresources      r!   r1   z2ControlFlowBuilderBlock.resolve_classical_resourceÆ  ss   € ØŒ;ð 	WÝÐUÑVÔVÐVà”<×:Ò:¸9ÑEÔEˆÝ�h¥Ñ&Ô&ð 	(Ø�MŠM˜8˜+Ñ&Ô&Ð&Ð&à×Ò˜hÑ'Ô'Ð'Øˆr$   r2   r3   c                ó8  — | j         rt          d¦  «        ‚| j                             |j        ¦  «        x}�/||k    rt          d|› d�¦  «        ‚t          d|› d|› d�¦  «        ‚|j        | j        v rt          d|› d|› d�¦  «        ‚|| j        |j        <   d S )Nr™   ú'z!' is already present in the scopezcannot add 'z$' as its name shadows the existing ')rl   r   rn   Úgetr;   ro   )r    r2   Úpreviouss      r!   r6   z-ControlFlowBuilderBlock.add_uninitialized_varÑ  sÊ   € ØŒ;ð 	WÝÐUÑVÔVÐVð Ô(×,Ò,¨S¬XÑ6Ô6Ð6ˆHÐCØ˜3ŠˆÝ"Ð#M sÐ#MÐ#MÐ#MÑNÔNÐNÝÐb¨cÐbÐbÐW_ÐbÐbÐbÑcÔcÐcØŒ8�tÔ)Ð)Ð)ÝÐb¨cÐbÐbÐW_ÐbÐbÐbÑcÔcÐcØ%(ˆÔ˜œÑ"Ð"Ð"r$   c                óp   — | j         rt          d¦  «        ‚| j                             |j        ¦  «         d S )Nz7exception handler 'remove_var' called after scope built)rl   ÚRuntimeErrorrn   Úpopr;   r5   s     r!   r8   z"ControlFlowBuilderBlock.remove_varÞ  s;   € ØŒ;ð 	ZÝÐXÑYÔYÐYØÔ×Ò˜SœXÑ&Ô&Ð&Ð&Ð&r$   r;   r<   c                ór   — | j                              |¦  «        x}�|S | j                             |¦  «        S r€   )rn   rŸ   rk   r?   )r    r;   Úouts      r!   r?   zControlFlowBuilderBlock.get_varã  s9   € ØÔ#×'Ò'¨Ñ-Ô-Ð-ˆCÐ:ØˆJØŒ|×#Ò# DÑ)Ô)Ð)r$   c                óŒ  — | j                              |j        ¦  «        x}�||k    rd S t          d|› d|› d�¦  «        ‚| j                             |j        ¦  «        |k    rd S | j                             |j        ¦  «        |k    rt          d|› d�¦  «        ‚| j                             |¦  «         || j        |j        <   d S )Nzcannot use 'z"' which is shadowed by the local 'rž   zcannot close over 'z', which is not in scope)rn   rŸ   r;   r   ro   rk   r?   r:   )r    r2   Úlocals      r!   r:   zControlFlowBuilderBlock.use_varè  sÖ   € ØÔ%×)Ò)¨#¬(Ñ3Ô3Ð3ˆEÐ@Ø˜Š|ˆ|Ø�ÝÐ]¨cÐ]Ð]ÐUZÐ]Ð]Ð]Ñ^Ô^Ð^ØÔ×!Ò! #¤(Ñ+Ô+¨sÒ2Ð2ØˆFØŒ<×Ò ¤Ñ)Ô)¨SÒ0Ð0ÝÐR°SÐRÐRÐRÑSÔSÐSØŒ×Ò˜SÑ!Ô!Ð!Ø'*ˆÔ˜3œ8Ñ$Ð$Ð$r$   c                ó4   — | j                              ¦   «         S )z=Iterator over the variables currently declared in this scope.)rn   Úvaluesr   s    r!   Úiter_local_varsz'ControlFlowBuilderBlock.iter_local_varsô  s   € àÔ×&Ò&Ñ(Ô(Ð(r$   c                ó4   — | j                              ¦   «         S )z=Iterator over the variables currently captured in this scope.)ro   r©   r   s    r!   Úiter_captured_varsz*ControlFlowBuilderBlock.iter_captured_varsø  s   € àÔ!×(Ò(Ñ*Ô*Ð*r$   c                óH   — | j         st          d¦  «        ‚| j         d         S )zAGet the value of the most recent instruction tuple in this scope.ú$This scope contains no instructions.éÿÿÿÿ)rg   r   r   s    r!   ÚpeekzControlFlowBuilderBlock.peekü  s+   € àÔ!ð 	GÝÐEÑFÔFÐFØÔ! "Ô%Ð%r$   c                ó`   — | j         st          d¦  «        ‚| j                              ¦   «         S )zcGet the value of the most recent instruction in this scope, and remove it from this
        object.r®   )rg   r   r£   r   s    r!   r£   zControlFlowBuilderBlock.pop  s4   € ð Ô!ð 	GÝÐEÑFÔFÐFØÔ!×%Ò%Ñ'Ô'Ð'r$   ÚbitsúIterable[Union[Qubit, Clbit]]c                óü   — |D ]x}t          |t          ¦  «        r| j                             |d¬¦  «         Œ4t          |t          ¦  «        r| j                             |d¬¦  «         Œft          d|› d�¦  «        ‚dS )a�  Add extra bits to this scope that are not associated with any concrete instruction yet.

        This is useful for expanding a scope's resource width when it may contain ``break`` or
        ``continue`` statements, or when its width needs to be expanded to match another scope's
        width (as in the case of :obj:`.IfElseOp`).

        Args:
            bits: The qubits and clbits that should be added to a scope.  It is not an error if
                there are duplicates, either within the iterable or with the bits currently in
                scope.

        Raises:
            TypeError: if the provided bit is of an incorrect type.
        FrŽ   z5Can only add qubits or classical bits, but received 'z'.N)rˆ   r   r"   r�   r   r‘   Ú	TypeError)r    r²   Úbits      r!   rš   z ControlFlowBuilderBlock.add_bits	  s    € ð ð 	að 	aˆCÝ˜#�uÑ%Ô%ð aØÔ!×+Ò+¨C¸Ð+Ñ>Ô>Ð>Ð>Ý˜C¥Ñ'Ô'ð aØÔ!×+Ò+¨C¸Ð+Ñ>Ô>Ð>Ð>åÐ _ÐX[Ð _Ð _Ð _Ñ`Ô`Ð`ð	að 	ar$   Úregisterr   c                óz   — || j         v rdS | j                              |¦  «         |                      |¦  «         dS )zÚAdd a :obj:`.Register` to the set of resources used by this block, ensuring that
        all bits contained within are also accounted for.

        Args:
            register: the register to add to the block.
        N)rh   Úaddrš   )r    r·   s     r!   r›   z$ControlFlowBuilderBlock.add_register   sD   € ð �t”~Ð%Ð%àˆFØŒ×Ò˜8Ñ$Ô$Ð$Ø�Š�hÑÔÐÐÐr$   Ú
all_qubitsrS   Ú
all_clbitsrT   ú'qiskit.circuit.QuantumCircuit'c                ó&  ‡ ‡‡‡	‡
‡‡‡— ddl m}mŠ	 d‰ _        ‰ j        �t          d¦  «        ‚t          ‰¦  «        ‰                      ¦   «         z
  Št          ‰¦  «        ‰                      ¦   «         z
  Š |‰ j	        j        ‰ j	        j        g‰ j
        ¢R ‰ j        ‰ j                             ¦   «         dœŽŠ
‰ j                             ¦   «         D ]}‰
                     |¦  «         Œi Šˆ	ˆˆˆ
ˆˆˆˆ fd„}‰ j	                             |¦  «         ‰ j	                             ¦   «         }|                     ‰
j        ‰
j        ¦  «         ‰                     ¦   «         D ]
\  }}|||<   Œ‰
                     ¦   «                              |¦  «         ‰
S )a
  Build this scoped block into a complete :obj:`.QuantumCircuit` instance.

        This will build a circuit which contains all of the necessary qubits and clbits and no
        others.

        The ``qubits`` and ``clbits`` arguments should be sets that contains all the resources in
        the outer scope; these will be passed down to inner placeholder instructions, so they can
        apply themselves across the whole scope should they need to.  The resulting
        :obj:`.QuantumCircuit` will be defined over a (nonstrict) subset of these resources.  This
        is used to let ``break`` and ``continue`` span all resources, even if they are nested within
        several :obj:`.IfElsePlaceholder` objects, without requiring :obj:`.IfElsePlaceholder`
        objects *without* any ``break`` or ``continue`` statements to be full-width.

        Args:
            all_qubits: all the qubits in the containing scope of this block.  The block may expand
                to use some or all of these qubits, but will never gain qubits that are not in this
                set.
            all_clbits: all the clbits in the containing scope of this block.  The block may expand
                to use some or all of these clbits, but will never gain clbits that are not in this
                set.

        Returns:
            A circuit containing concrete versions of all the instructions that were in the scope,
            and using the minimal set of resources necessary to support them, within the enclosing
            scope.
        r   )ÚQuantumCircuitÚSwitchCaseOpTNz<Cannot build a forbidden scope. Please report this as a bug.)ri   Úcapturesc                óŒ  •— t          |t          ¦  «        �r4|                     ‰‰¦  «        \  }}t          |j        ¦  «        }t          |j        ¦  «        }t          |||¦  «        ‰| <   ‰rC|rA‰                     |¦  «        }|r*‰                     |¦  «         ‰ 	                    |¦  «         ‰rC|rA‰                     |¦  «        }|r*‰                     |¦  «         ‰ 	                    |¦  «         t          j        |j        |j        ¦  «        D ]5}|‰j        vr*‰                     |¦  «         ‰                     |¦  «         Œ6t!          |dd ¦  «        �Qt#          |j        ¦  «        j        D ]5}|‰j        vr*‰                     |¦  «         ‰                     |¦  «         Œ6d S t          |‰
¦  «        r„|j        }t          |t(          ¦  «        rd}	n-t          |t*          ¦  «        r|f}	nt-          |¦  «        j        }	|	D ]7}|‰j        vr*‰                     |¦  «         ‰                     |¦  «         Œ6d S d S )Nr]   r   )rˆ   rR   rY   ÚtuplerL   rM   r   ÚintersectionÚdifference_updaterš   Ú	itertoolsÚchainrN   rO   rh   r›   Úgetattrr   r]   Útargetr   r   r   )ÚindexÚopÚ	resourcesrL   rM   Ú
add_qubitsÚ
add_clbitsr·   rÈ   Útarget_registersr¿   r»   rº   r¥   Úplaceholder_to_concreteÚpotential_clbitsÚpotential_qubitsr    s             €€€€€€€€r!   Úupdate_registersz7ControlFlowBuilderBlock.build.<locals>.update_registersj  sŽ  ø€ Ý˜"Õ4Ñ5Ô5ñ 3Ø "× 7Ò 7¸
ÀJÑ OÔ O‘��IÝ˜yÔ/Ñ0Ô0�Ý˜yÔ/Ñ0Ô0�Ý1CÀBÈÐPVÑ1WÔ1WÐ'¨Ñ.ð $ð 1¨ð 1Ø!1×!>Ò!>¸vÑ!FÔ!F�JØ!ð 1Ø(×:Ò:¸:ÑFÔFÐFØŸš ZÑ0Ô0Ð0Ø#ð 1¨ð 1Ø!1×!>Ò!>¸vÑ!FÔ!F�JØ!ð 1Ø(×:Ò:¸:ÑFÔFÐFØŸš ZÑ0Ô0Ð0Ý )¤°	´ÀÄÑ QÔ Qð 3ð 3�HØ t¤~Ð5Ð5ð ×)Ò)¨(Ñ3Ô3Ð3Ø×(Ò(¨Ñ2Ô2Ð2øÝ�r˜<¨Ñ.Ô.Ð:Ý 3°B´MÑ BÔ BÔ Hð 3ð 3�HØ t¤~Ð5Ð5Ø×)Ò)¨(Ñ3Ô3Ð3Ø×(Ò(¨Ñ2Ô2Ð2øð3ð 3õ ˜B Ñ-Ô-ð 3Øœ�Ý˜f¥eÑ,Ô,ð DØ')Ð$Ð$Ý Õ(9Ñ:Ô:ð DØ(. yÐ$Ð$å'5°fÑ'=Ô'=Ô'CÐ$Ø 0ð 3ð 3�HØ t¤~Ð5Ð5Ø×)Ò)¨(Ñ3Ô3Ð3Ø×(Ò(¨Ñ2Ô2Ð2øð3ð 3ð3ð 3r$   )Úqiskit.circuitr¾   r¿   rl   rm   r¢   ry   rL   rM   rg   rh   ri   ro   r©   rn   r6   Úforeach_op_indexedÚcopyÚreplace_bitsÚitemsÚ_current_scoper,   )r    rº   r»   r¾   r2   rÒ   Úout_dataÚir'   r¿   r¥   rÏ   rÐ   rÑ   s   ```      @@@@@r!   ÚbuildzControlFlowBuilderBlock.build-  së  øøøøøøøø€ ð< 	@Ð?Ð?Ð?Ð?Ð?Ð?Ð?ð
 ˆŒàÔ"Ð.åÐ]Ñ^Ô^Ð^å˜z™?œ?¨T¯[ª[©]¬]Ñ:ÐÝ˜z™?œ?¨T¯[ª[©]¬]Ñ:Ðð ˆnØÔÔ%ØÔÔ%ð
ð Œ^ð
ð 
ð Ô*ØÔ'×.Ò.Ñ0Ô0ð
ð 
ð 
ˆð Ô#×*Ò*Ñ,Ô,ð 	+ð 	+ˆCð ×%Ò% cÑ*Ô*Ð*Ð*ð #%Ðð(	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ð (	3ðV 	Ô×-Ò-Ð.>Ñ?Ô?Ð?ð Ô%×*Ò*Ñ,Ô,ˆØ×Ò˜cœj¨#¬*Ñ5Ô5Ð5Ø5×;Ò;Ñ=Ô=ð 	&ð 	&‰NˆAˆ{Ø%ˆH�Q‰KˆKð 	×ÒÑÔ×#Ò# HÑ-Ô-Ð-Øˆ
r$   ú'ControlFlowBuilderBlock'c                ó´  — t          | ¦  «                             t          | ¦  «        ¦  «        }| j                             ¦   «         |_        | j                             ¦   «         |_        | j        |_        | j                             ¦   «         |_        | j                             ¦   «         |_        | j        |_        | j	        |_	        | j
        |_
        |S )a@  Return a semi-shallow copy of this builder block.

        The instruction lists and sets of qubits and clbits will be new instances (so mutations will
        not propagate), but any :obj:`.Instruction` instances within them will not be copied.

        Returns:
            a semi-shallow copy of this object.
        )ÚtypeÚ__new__rg   rÕ   rh   ri   rn   ro   rk   rj   rm   )r    r¥   s     r!   rÕ   zControlFlowBuilderBlock.copy¡  s«   € õ �4‰jŒj× Ò ¥ d¡¤Ñ,Ô,ˆØ Ô.×3Ò3Ñ5Ô5ˆÔØœ×+Ò+Ñ-Ô-ˆŒØÔ,ˆÔØÔ*×/Ò/Ñ1Ô1ˆŒØ Ô.×3Ò3Ñ5Ô5ˆÔØ”lˆŒØÔ,ˆÔØ!%Ô!8ˆÔØˆ
r$   )rL   rr   rM   rs   rt   r   rh   ru   rp   rv   rq   rw   )r'   r   r&   rv   r   r   r@   rA   )r;   r<   )r   r   )r²   r³   )r·   r   )rº   rS   r»   rT   r   r¼   )r   rÜ   )rB   rC   rD   rE   rF   rz   rL   rM   rG   rp   r"   Ústaticmethodr‹   r)   r,   r1   r6   r8   r?   r:   rª   r¬   r°   r£   rš   r›   rÛ   rÕ   r   r$   r!   rf   rf   ,  sõ  € € € € € ðð ð8
€Ið$ )+Ø Ø+/ð+4ð +4ð +4ð +4ð +4ð +4ðZ-ð -ð -ð-ð -ð -ð ð!ð !ñ „Xð!ð ð"ð "ñ „Xð"ð ð
ð 
ñ „\ð
ð JOðð ð ð ð ð ð'ð 'ð 'ð 'ð	ð 	ð 	ð)ð )ð )ð )ð'ð 'ð 'ð 'ð
*ð *ð *ð *ð

+ð 
+ð 
+ð 
+ð)ð )ð )ð+ð +ð +ð&ð &ð &ð &ð(ð (ð (ð (ðað að að að. ð  ð  ð  ðrð rð rð rðhð ð ð ð ð r$   rf   )*rE   Ú
__future__r   rH   rÅ   Útypingr   r   r   r   r   r	   r
   Úqiskit._accelerate.circuitr   Úqiskit.circuit.classicalr   Ú qiskit.circuit.classicalregisterr   r   Úqiskit.circuit.exceptionsr   Úqiskit.circuit.instructionr   Ú!qiskit.circuit.quantumcircuitdatar   Úqiskit.circuit.quantumregisterr   r   Úqiskit.circuit.registerr   Ú_builder_utilsr   r   ÚTYPE_CHECKINGÚqiskitÚABCr   Ú
NamedTuplerK   rR   rf   r   r$   r!   ú<module>rð      s  ðð ;Ð :ð #Ð "Ð "Ð "Ð "Ð "à 
€
€
€
Ø Ð Ð Ð Ø €€€Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tà 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø )Ð )Ð )Ð )Ð )Ð )Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø @Ð @Ð @Ð @Ð @Ð @Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ ,Ð ,Ð ,Ð ,Ð ,Ð ,à ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?à	Ôð Ø€M€M€Mð}ð }ð }ð }ð }˜CœGñ }ô }ð }ð@.ð .ð .ð .ð .˜6Ô,ñ .ô .ð .ð*jGð jGð jGð jGð jG˜[¨#¬'ñ jGô jGð jGðZGð Gð Gð Gð GÐ3ñ Gô Gð Gð Gð Gr$   