§
    ¹³Ùg!  ã                  óˆ   — d Z ddlmZ ddl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  G d„ d¦  «        ZdS )z
Instruction collection.
é    )Úannotations)ÚMutableSequence)ÚCallable)ÚCircuitError)Údeprecate_funcé   )ÚClbitÚClassicalRegister)Ú	Operation)ÚCircuitInstructionc                  óÀ   — e Zd ZdZdZddœd!d„Zd„ Zd	„ Zd"d
„Zd#d„Z	d$d%d„Z
 edd¬¦  «        d&d„¦   «         Zd„ Zed„ ¦   «         Zed„ ¦   «         Zed „ ¦   «         ZdS )'ÚInstructionSetz+Instruction collection, and their contexts.©Ú_instructionsÚ
_requesterN)Úresource_requesterr   ú/Callable[..., ClassicalRegister | Clbit] | Nonec               ó"   — g | _         || _        dS )aÛ  New collection of instructions.

        The context (``qargs`` and ``cargs`` that each instruction is attached to) is also stored
        separately for each instruction.

        Args:
            resource_requester: A callable that takes in the classical resource used in the
                condition, verifies that it is present in the attached circuit, resolves any indices
                into concrete :obj:`.Clbit` instances, and returns the concrete resource.  If this
                is not given, specifying a condition with an index is forbidden, and all concrete
                :obj:`.Clbit` and :obj:`.ClassicalRegister` resources will be assumed to be valid.

                .. note::

                    The callback ``resource_requester`` is called once for each call to
                    :meth:`.c_if`, and assumes that a call implies that the resource will now be
                    used.  It may throw an error if the resource is not valid for usage.

        Nr   )Úselfr   s     úS/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/instructionset.pyÚ__init__zInstructionSet.__init__"   s   € ð4 ð 	Ôð -ˆŒˆˆó    c                ó*   — t          | j        ¦  «        S )z$Return number of instructions in set)Úlenr   ©r   s    r   Ú__len__zInstructionSet.__len__?   s   € å�4Ô%Ñ&Ô&Ð&r   c                ód   — | j         |         }t          |t          ¦  «        r|S |\  }}||         S )zReturn instruction at index)r   Ú
isinstancer   )r   ÚiÚinstÚdataÚidxs        r   Ú__getitem__zInstructionSet.__getitem__C   s:   € àÔ! !Ô$ˆÝ�dÕ.Ñ/Ô/ð 	ØˆKØ‰	ˆˆcØ�CŒyÐr   c                ó(  — t          |t          ¦  «        sbt          |t          ¦  «        st          d¦  «        ‚|�|€t          d¦  «        ‚t          |t	          |¦  «        t	          |¦  «        ¦  «        }| j                             |¦  «         dS )z:Add an instruction and its context (where it is attached).z.attempt to add non-Operation to InstructionSetNz6missing qargs or cargs in old-style InstructionSet.add)r   r   r   r   Útupler   Úappend)r   ÚinstructionÚqargsÚcargss       r   ÚaddzInstructionSet.addK   sŠ   € å˜+Õ'9Ñ:Ô:ð 	VÝ˜k­9Ñ5Ô5ð UÝ"Ð#SÑTÔTÐTØˆ}  Ý"Ð#[Ñ\Ô\Ð\Ý,¨[½%À¹,¼,ÍÈeÉÌÑUÔUˆKØÔ×!Ò! +Ñ.Ô.Ð.Ð.Ð.r   r!   ú#MutableSequence[CircuitInstruction]ÚposÚintc                ó>   — | j                              ||f¦  «         dS )z Add a reference to an instruction and its context within a mutable sequence.
        Updates to the instruction set will modify the specified sequence in place.N)r   r&   )r   r!   r,   s      r   Ú_add_refzInstructionSet._add_refU   s%   € ð 	Ô×!Ò! 4¨ +Ñ.Ô.Ð.Ð.Ð.r   FÚ	annotatedÚboolc                óR  — t          | j        ¦  «        D ]‘\  }}t          |t          ¦  «        r8|                     |j                             |¬¦  «        ¬¦  «        | j        |<   ŒR|\  }}||         }|                     |j                             |¬¦  «        ¬¦  «        ||<   Œ’| S )z”Invert all instructions.

        .. note::
            It is preferable to take the inverse *before* appending the gate(s) to the circuit.
        )r0   ©Ú	operation)Ú	enumerater   r   r   Úreplacer4   Úinverse)r   r0   r   r'   r!   r"   s         r   r7   zInstructionSet.inverseZ   sÃ   € õ (¨Ô(:Ñ;Ô;ð 
	ð 
	‰NˆAˆ{Ý˜+Õ'9Ñ:Ô:ð 	Ø(3×(;Ò(;Ø)Ô3×;Ò;ÀiÐ;ÑPÔPð )<ñ )ô )�Ô" 1Ñ%Ð%ð (‘	��cØ" 3œi�Ø'×/Ò/Ø)Ô3×;Ò;ÀiÐ;ÑPÔPð 0ñ ô ��S‘	�	ð ˆr   z1.3.0zin 2.0.0)ÚsinceÚremoval_timelineÚ	classicalúClbit | ClassicalRegister | intÚvalÚreturnú'InstructionSet'c                óò  — | j         €+t          |t          t          f¦  «        st	          d¦  «        ‚| j         �|                       |¦  «        }t          | j        ¦  «        D ]“\  }}t          |t          ¦  «        r:|j         	                    ||¦  «        }| 
                    |¬¦  «        | j        |<   ŒT|\  }}||         }| 
                    |j         	                    ||¦  «        ¬¦  «        ||<   Œ”| S )aó  Set a classical equality condition on all the instructions in this set between the
        :obj:`.ClassicalRegister` or :obj:`.Clbit` ``classical`` and value ``val``.

        .. note::
            You should prefer to use the :meth:`.QuantumCircuit.if_test` builder interface, rather
            than using this method.

        .. note::

            This is a setter method, not an additive one.  Calling this multiple times will silently
            override any previously set condition on any of the contained instructions; it does not
            stack.

        Args:
            classical: the classical resource the equality condition should be on.  If this is given
                as an integer, it will be resolved into a :obj:`.Clbit` using the same conventions
                as the circuit these instructions are attached to.
            val: the value the classical resource should be equal to.

        Returns:
            This same instance of :obj:`.InstructionSet`, but now mutated to have the given equality
            condition.

        Raises:
            CircuitError: if the passed classical resource is invalid, or otherwise not resolvable
                to a concrete resource that these instructions are permitted to access.
        NznCannot pass an index as a condition variable without specifying a requester when creating this InstructionSet.r3   )r   r   r	   r
   r   r5   r   r   r4   Úc_ifr6   )r   r:   r<   r"   r'   Úupdatedr!   s          r   r@   zInstructionSet.c_ifm   s  € ð: Œ?Ð"­:°iÅ%ÕIZÐA[Ñ+\Ô+\Ð"Ýð6ñô ð ð Œ?Ð&ØŸš¨	Ñ2Ô2ˆIÝ )¨$Ô*<Ñ =Ô =ð 		ð 		ÑˆC�Ý˜+Õ'9Ñ:Ô:ð Ø%Ô/×4Ò4°YÀÑDÔD�Ø*5×*=Ò*=ÈÐ*=Ñ*PÔ*P�Ô" 3Ñ'Ð'à'‘	��cØ" 3œi�Ø'×/Ò/Ø)Ô3×8Ò8¸ÀCÑHÔHð 0ñ ô ��S‘	�	ð ˆr   c                ó$   — d„ | j         D ¦   «         S )Nc              3  ól   K  — | ]/}t          |t          ¦  «        r|n|d          |d                  V — Œ0dS )r   r   N)r   r   )Ú.0r   s     r   ú	<genexpr>z4InstructionSet._instructions_iter.<locals>.<genexpr>¡   sB   è è € ÐcÐcÈ1•Z Õ#5Ñ6Ô6ÐF��¸A¸a¼DÀÀ1Ä¼JÐcÐcÐcÐcÐcÐcr   )r   r   s    r   Ú_instructions_iterz!InstructionSet._instructions_iter    s   € ØcÐcÐPTÔPbÐcÑcÔcÐcr   c                ó>   — d„ |                       ¦   «         D ¦   «         S )zlLegacy getter for the instruction components of an instruction set.  This does not
        support mutation.c                ó   — g | ]	}|j         ‘Œ
S © r3   ©rD   r'   s     r   ú
<listcomp>z/InstructionSet.instructions.<locals>.<listcomp>§   s   € ÐSÐSÐS¨+�Ô%ÐSÐSÐSr   ©rF   r   s    r   ÚinstructionszInstructionSet.instructions£   s%   € ð TÐS¸×9PÒ9PÑ9RÔ9RÐSÑSÔSÐSr   c                ó>   — d„ |                       ¦   «         D ¦   «         S )zfLegacy getter for the qargs components of an instruction set.  This does not support
        mutation.c                ó6   — g | ]}t          |j        ¦  «        ‘ŒS rI   )ÚlistÚqubitsrJ   s     r   rK   z(InstructionSet.qargs.<locals>.<listcomp>­   ó#   € ÐVÐVÐV¨[•�[Ô'Ñ(Ô(ÐVÐVÐVr   rL   r   s    r   r(   zInstructionSet.qargs©   ó%   € ð WÐV¸D×<SÒ<SÑ<UÔ<UÐVÑVÔVÐVr   c                ó>   — d„ |                       ¦   «         D ¦   «         S )zfLegacy getter for the cargs components of an instruction set.  This does not support
        mutation.c                ó6   — g | ]}t          |j        ¦  «        ‘ŒS rI   )rP   ÚclbitsrJ   s     r   rK   z(InstructionSet.cargs.<locals>.<listcomp>³   rR   r   rL   r   s    r   r)   zInstructionSet.cargs¯   rS   r   )r   r   )NN)r!   r+   r,   r-   )F)r0   r1   )r:   r;   r<   r-   r=   r>   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r#   r*   r/   r7   r   r@   rF   ÚpropertyrM   r(   r)   rI   r   r   r   r      sC  € € € € € Ø5Ð5à/€Ið
 OSð-ð -ð -ð -ð -ð -ð:'ð 'ð 'ðð ð ð/ð /ð /ð /ð/ð /ð /ð /ð
ð ð ð ð ð& €^˜'°JÐ?Ñ?Ô?ð-ð -ð -ñ @Ô?ð-ðddð dð dð ðTð Tñ „XðTð
 ðWð Wñ „XðWð
 ðWð Wñ „XðWð Wð Wr   r   N)rZ   Ú
__future__r   Úcollections.abcr   Útypingr   Úqiskit.circuit.exceptionsr   Úqiskit.utilsr   Úclassicalregisterr	   r
   r4   r   Úquantumcircuitdatar   r   rI   r   r   ú<module>rd      sí   ððð ð #Ð "Ð "Ð "Ð "Ð "à +Ð +Ð +Ð +Ð +Ð +Ø Ð Ð Ð Ð Ð à 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø  Ð  Ð  Ð  Ð  Ð  Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2ðVWð VWð VWð VWð VWñ VWô VWð VWð VWð VWr   