
    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  \(       a  SS	KJrJr   " S
 S5      rg)z
Instruction collection.
    )annotations)MutableSequence)CallableTYPE_CHECKING)CircuitError   )	Operation)CircuitInstruction)ClbitClassicalRegisterc                      \ rS rSrSrSrSS. SS jjrS rS rSS	 jr	SS
 jr
SSS jjrS r\S 5       r\S 5       r\S 5       rSrg)InstructionSet   z+Instruction collection, and their contexts._instructions
_requesterN)resource_requesterc                   / U l         Xl        g)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`` 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     W/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/instructionset.py__init__InstructionSet.__init__#   s    4  	 -    c                ,    [        U R                  5      $ )z$Return number of instructions in set)lenr   r   s    r   __len__InstructionSet.__len__@   s    4%%&&r   c                ^    U R                   U   n[        U[        5      (       a  U$ Uu  p4X4   $ )zReturn instruction at index)r   
isinstancer
   )r   iinstdataidxs        r   __getitem__InstructionSet.__getitem__D   s4    !!!$d.//K	yr   c                   [        U[        5      (       dP  [        U[        5      (       d  [        S5      eUb  Uc  [        S5      e[        U[	        U5      [	        U5      5      nU R
                  R                  U5        g)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   addInstructionSet.addL   sh    +'9::k955"#STT}"#[\\,[%,eUK!!+.r   c                <    U R                   R                  X45        g)zAdd 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#   poss      r   _add_refInstructionSet._add_refV   s     	!!4+.r   c                6   [        U R                  5       H  u  p#[        U[        5      (       a5  UR	                  UR
                  R                  US9S9U R                  U'   MO  Uu  pEXE   nUR	                  UR
                  R                  US9S9XE'   M     U $ )z|Invert all instructions.

.. note::
    It is preferable to take the inverse *before* appending the gate(s) to the circuit.
)	annotated)	operation)	enumerater   r    r
   replacer5   inverse)r   r4   r!   r*   r#   r$   s         r   r8   InstructionSet.inverse[   s     ((:(:;NA+'9::(3(;(;)33;;i;P )< )""1% (	"i'//)33;;i;P 0 	 < r   c                (    S U R                    5       $ )Nc              3  f   #    U  H'  n[        U[        5      (       a  UO
US    US      v   M)     g7f)r   r   N)r    r
   ).0r!   s     r   	<genexpr>4InstructionSet._instructions_iter.<locals>.<genexpr>r   s0     cPb1Z#566AaD1JFPbs   /1)r   r   s    r   _instructions_iter!InstructionSet._instructions_iterq   s    cPTPbPbccr   c                `    U R                  5        Vs/ s H  oR                  PM     sn$ s  snf )zdLegacy getter for the instruction components of an instruction set.  This does not
support mutation.)r?   r5   r   r*   s     r   instructionsInstructionSet.instructionst   s+     :>9P9P9RS9R+%%9RSSSs   +c                t    U R                  5        Vs/ s H  n[        UR                  5      PM     sn$ s  snf )z^Legacy getter for the qargs components of an instruction set.  This does not support
mutation.)r?   listqubitsrB   s     r   r+   InstructionSet.qargsz   3     =A<S<S<UV<U[[''(<UVVV   5c                t    U R                  5        Vs/ s H  n[        UR                  5      PM     sn$ s  snf )z^Legacy getter for the cargs components of an instruction set.  This does not support
mutation.)r?   rF   clbitsrB   s     r   r,   InstructionSet.cargs   rI   rJ   )r   z/Callable[..., ClassicalRegister | Clbit] | None)NN)r#   z#MutableSequence[CircuitInstruction]r0   int)F)r4   bool)__name__
__module____qualname____firstlineno____doc__	__slots__r   r   r%   r-   r1   r8   r?   propertyrC   r+   r,   __static_attributes__ r   r   r   r      s    5/I
 OS- L-:'//
,d T T
 W W
 W Wr   r   N)rT   
__future__r   collections.abcr   typingr   r   qiskit.circuit.exceptionsr   r5   r	   quantumcircuitdatar
   qiskit.circuitr   r   r   rX   r   r   <module>r_      s2    # + * 2   27fW fWr   