§
    ¹³Ùgý"  ã                  óT   — d Z ddlmZ ddlZddlZddlZddlmZ  G d„ d¦  «        Z	dS )z!
Base register reference object.
é    )ÚannotationsN)ÚCircuitErrorc                  ó¸   — e Zd ZdZg d¢Z ej        ¦   «         ZdZdZ	ddd	„Z
d
„ Zed„ ¦   «         Zed„ ¦   «         Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚRegisterzÍImplement a generic register.

    .. note::
        This class should not be instantiated directly. This is just a superclass
        for :class:`~.ClassicalRegister` and :class:`~.QuantumRegister`.

    )Ú_nameÚ_sizeÚ_bitsÚ_bit_indicesÚ_hashÚ_reprÚregNÚsizeú
int | NoneÚnameú
str | Nonec                óŠ  ‡ — ||fdk    s|�|�t          d|› d|› d�¦  «        ‚|�t          |¦  «        }	 |t          |¦  «        k    }n# t          t          f$ r d}Y nw xY w|s(t          dt          |¦  «        j        › d|› d	�¦  «        ‚t          |¦  «        }|d
k     r(t          dt          |¦  «        j        › d|› d	�¦  «        ‚|€‰ j        › t          ‰ j	        ¦  «        › �}n3	 t          |¦  «        }n"# t          $ r}t          d¦  «        |‚d}~ww xY w|‰ _        |‰ _        t          t          ‰ ¦  «        ‰ j        ‰ j        f¦  «        ‰ _        ‰ j        j        › d‰ j        › d‰ j        › d�‰ _        |��‰ j        t          t+          |¦  «        ¦  «        k    rt          d|› �¦  «        ‚t-          ˆ fd„|D ¦   «         ¦  «        rt          d|› �¦  «        ‚t/          |¦  «        ‰ _        d„ t3          ‰ j        ¦  «        D ¦   «         ‰ _        dS ˆ fd„t7          |¦  «        D ¦   «         ‰ _        d‰ _        dS )aû  Create a new generic register.

        Either the ``size`` or the ``bits`` argument must be provided. If
        ``size`` is not None, the register will be pre-populated with bits of the
        correct type.

        Args:
            size (int): Optional. The number of bits to include in the register.
            name (str): Optional. The name of the register. If not provided, a
               unique name will be auto-generated from the register type.
            bits (list[Bit]): Optional. A list of Bit() instances to be used to
               populate the register.

        Raises:
            CircuitError: if both the ``size`` and ``bits`` arguments are
                provided, or if neither are.
            CircuitError: if ``size`` is not valid.
            CircuitError: if ``name`` is not a valid name according to the
                OpenQASM spec.
            CircuitError: if ``bits`` contained duplicated bits.
            CircuitError: if ``bits`` contained bits of an incorrect type.
        )NNNzIExactly one of the size or bits arguments can be provided. Provided size=z bits=ú.Fz#Register size must be an integer. (z 'z' was provided)r   z$Register size must be non-negative (zRThe circuit name should be castable to a string (or None for autogenerate a name).ú(z, 'z')z+Register bits must not be duplicated. bits=c              3  óD   •K  — | ]}t          |‰j        ¦  «         V — Œd S ©N)Ú
isinstanceÚbit_type)Ú.0ÚbitÚselfs     €úM/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/register.pyú	<genexpr>z$Register.__init__.<locals>.<genexpr>u   s2   øè è € ÐFÐF¸#•z # t¤}Ñ5Ô5Ð5ÐFÐFÐFÐFÐFÐFó    z4Provided bits did not all match register type. bits=c                ó   — i | ]\  }}||“Œ	S © r    ©r   Úidxr   s      r   ú
<dictcomp>z%Register.__init__.<locals>.<dictcomp>x   ó   € Ð PÐ PÐ P©h¨c°3  cÐ PÐ PÐ Pr   c                ó<   •— g | ]}‰                      ‰|¦  «        ‘ŒS r    )r   ©r   r"   r   s     €r   ú
<listcomp>z%Register.__init__.<locals>.<listcomp>z   s'   ø€ ÐJÐJÐJ°s˜$Ÿ-š-¨¨cÑ2Ô2ÐJÐJÐJr   )r   ÚlenÚintÚ
ValueErrorÚ	TypeErrorÚtypeÚ__name__ÚprefixÚnextÚinstances_counterÚstrÚ	Exceptionr   r   Úhashr   Ú	__class__Ú__qualname__r   r   r   ÚsetÚanyÚlistr	   Ú	enumerater
   Úrange)r   r   r   ÚbitsÚ
valid_sizeÚexs   `     r   Ú__init__zRegister.__init__-   sÎ  ø€ ð0 �$ˆ<˜<Ò'Ð'¨DÐ,<ÀÐAQÝð?Ø+/ð?ð ?Ø7;ð?ð ?ð ?ñô ð ð ÐÝ�t‘9”9ˆDð	Ø¥ T¡¤Ò*ˆJˆJøÝ�IÐ&ð 	ð 	ð 	ØˆJˆJˆJð	øøøð ð 	ÝØbµd¸4±j´jÔ6IÐbÐbÈTÐbÐbÐbñô ð õ �4‰yŒyˆà�!Š8ˆ8ÝØcµt¸D±z´zÔ7JÐcÐcÈdÐcÐcÐcñô ð ð
 ˆ<Ø”kÐA¥4¨Ô(>Ñ#?Ô#?ÐAÐAˆDˆDðÝ˜4‘y”y��øÝð ð ð Ý"ð9ñô ð ðøøøøðøøøð ˆŒ
ØˆŒ
å�4 ™:œ: t¤z°4´:Ð>Ñ?Ô?ˆŒ
ØœÔ3ÐQÐQ°d´iÐQÐQÀDÄIÐQÐQÐQˆŒ
ØÐàŒz�S¥ T¡¤™^œ^Ò+Ð+Ý"Ð#WÐQUÐ#WÐ#WÑXÔXÐXåÐFÐFÐFÐFÀÐFÑFÔFÑFÔFð bÝ"Ð#`ÐZ^Ð#`Ð#`ÑaÔaÐaÝ˜d™œˆDŒJØ PÐ P½)ÀDÄJÑ:OÔ:OÐ PÑ PÔ PˆDÔÐÐàJÐJÐJÐJ½eÀD¹k¼kÐJÑJÔJˆDŒJð !%ˆDÔÐÐs)   ¶A
 Á
A ÁA Ã+C; Ã;
DÄDÄDc                óÆ   — | j                              dd¦  «        d         t                               dd¦  «        d         k    rt          j        dt
          d¬¦  «         | S )Nr   é   r   zNsubclassing 'Register' is not supported, and may not be possible in Qiskit 2.0)ÚcategoryÚ
stacklevel)Ú
__module__Úsplitr-   ÚwarningsÚwarnÚDeprecationWarning)Úclss    r   Ú__init_subclass__zRegister.__init_subclass__‚   sb   € ð Œ>×Ò  QÑ'Ô'¨Ô*­h¯nªn¸SÀ!Ñ.DÔ.DÀQÔ.GÒGÐGÝŒMØ`Ý+Øðñ ô ð ð
 ˆ
r   c                ó   — | j         S )zGet the register name.)r   ©r   s    r   r   zRegister.name�   ó   € ð ŒzÐr   c                ó   — | j         S )zGet the register size.©r   rK   s    r   r   zRegister.size’   rL   r   c                ó   — | j         S )z5Return the official string representing the register.)r   rK   s    r   Ú__repr__zRegister.__repr__—   ó
   € àŒzÐr   c                ó   — | j         S )zReturn register size.rN   rK   s    r   Ú__len__zRegister.__len__›   rQ   r   c                ó~  ‡ — t          |t          t          j        t          t
          f¦  «        st          d¦  «        ‚t          |t          ¦  «        r‰ j        |         S t          |t
          ¦  «        r=t          |¦  «        t          ‰ ¦  «        k     rˆ fd„|D ¦   «         S t          d¦  «        ‚‰ j        |         S )aÓ  
        Arg:
            bit_type (Qubit or Clbit): a constructor type return element/s.
            key (int or slice or list): index of the bit to be retrieved.

        Returns:
            Qubit or Clbit or list(Qubit) or list(Clbit): a Qubit or Clbit instance if
            key is int. If key is a slice, returns a list of these instances.

        Raises:
            CircuitError: if the `key` is not an integer or not in the range `(0, self.size)`.
        z-expected integer or slice index into registerc                ó*   •— g | ]}‰j         |         ‘ŒS r    )r	   r&   s     €r   r'   z(Register.__getitem__.<locals>.<listcomp>²   s   ø€ Ð7Ð7Ð7¨C˜œ
 3œÐ7Ð7Ð7r   zregister index out of range)
r   r)   ÚnpÚintegerÚslicer8   r   r	   Úmaxr(   )r   Úkeys   ` r   Ú__getitem__zRegister.__getitem__Ÿ   s®   ø€ õ ˜#¥¥R¤Zµ½Ð=Ñ>Ô>ð 	PÝÐNÑOÔOÐOÝ�c�5Ñ!Ô!ð 	#Ø”:˜c”?Ð"Ý˜�TÑ"Ô"ð 	#Ý�3‰xŒx�#˜d™)œ)Ò#Ð#Ø7Ð7Ð7Ð7°3Ð7Ñ7Ô7Ð7å"Ð#@ÑAÔAÐAà”:˜c”?Ð"r   c              #  óV   K  — t          | j        ¦  «        D ]}| j        |         V — Œd S r   )r:   r   r	   )r   r"   s     r   Ú__iter__zRegister.__iter__¸   s>   è è € Ý˜œÑ$Ô$ð 	"ð 	"ˆCØ”*˜S”/Ð!Ð!Ð!Ð!ð	"ð 	"r   c                óh   — | j         €#d„ t          | j        ¦  «        D ¦   «         | _         || j         v S )Nc                ó   — i | ]\  }}||“Œ	S r    r    r!   s      r   r#   z)Register.__contains__.<locals>.<dictcomp>¾   r$   r   )r
   r9   r	   )r   r   s     r   Ú__contains__zRegister.__contains__¼   s9   € ØÔÐ$Ø PÐ P½)ÀDÄJÑ:OÔ:OÐ PÑ PÔ PˆDÔà�dÔ'Ð'Ð'r   c                óÄ   — | j         €#d„ t          | j        ¦  «        D ¦   «         | _         	 | j         |         S # t          $ r}t	          d|› d| › d�¦  «        |‚d}~ww xY w)z8Find the index of the provided bit within this register.Nc                ó   — i | ]\  }}||“Œ	S r    r    r!   s      r   r#   z"Register.index.<locals>.<dictcomp>Å   r$   r   zBit z not found in Register r   )r
   r9   r	   ÚKeyErrorr*   )r   r   Úerrs      r   ÚindexzRegister.indexÂ   s†   € àÔÐ$Ø PÐ P½)ÀDÄJÑ:OÔ:OÐ PÑ PÔ PˆDÔð	RØÔ$ SÔ)Ð)øÝð 	Rð 	Rð 	RÝÐG CÐGÐGÀÐGÐGÐGÑHÔHÈcÐQøøøøð	Røøøs   ¬9 ¹
AÁAÁAc                óÄ   — | |u rdS d}t          | ¦  «        t          |¦  «        u r9| j        |j        k    r)t          d„ t          | |¦  «        D ¦   «         ¦  «        rd}|S )aó  Two Registers are the same if they are of the same type
        (i.e. quantum/classical), and have the same name and size. Additionally,
        if either Register contains new-style bits, the bits in both registers
        will be checked for pairwise equality. If two registers are equal,
        they will have behave identically when specified as circuit args.

        Args:
            other (Register): other Register

        Returns:
            bool: `self` and `other` are equal.
        TFc              3  ó`   K  — | ])\  }}d |j         |j        |j         |j        fv ¯!||k    V — Œ*d S r   )Ú	_registerÚ_index)r   ÚsbitÚobits      r   r   z"Register.__eq__.<locals>.<genexpr>à   sT   è è € ð ð ñ �D˜$Ø˜DœN¨D¬K¸¼ÈÌÐUÐUÐUð ˜’àUÐUÐUÐUð	ð r   )r,   r   ÚallÚzip)r   ÚotherÚress      r   Ú__eq__zRegister.__eq__Ì   sƒ   € ð �5ˆ=ˆ=Ø�4àˆå�‰JŒJ�$˜u™+œ+Ð%Ð%Ø”
˜eœkÒ)Ð)Ýð ð õ #& d¨EÑ"2Ô"2ðñ ô ñ ô ð *ð ˆCØˆ
r   c                ó   — | j         S )z9Make object hashable, based on the name and size to hash.)r   rK   s    r   Ú__hash__zRegister.__hash__ê   rQ   r   c                óB   — | j         | j        | j        | j        | j        fS r   )r   r   r   r   r	   rK   s    r   Ú__getstate__zRegister.__getstate__î   s   € ð Œz˜4œ: t¤z°4´:¸t¼zÐIÐIr   c                óV   — |\  | _         | _        | _        | _        | _        d | _        d S r   )r   r   r   r   r	   r
   )r   Ústates     r   Ú__setstate__zRegister.__setstate__ô   s*   € ØEJÑBˆŒ
�D”J ¤
¨D¬J¸¼
Ø ˆÔÐÐr   )NNN)r   r   r   r   )r-   rC   r5   Ú__doc__Ú	__slots__Ú	itertoolsÚcountr0   r.   r   r>   rI   Úpropertyr   r   rP   rS   r[   r]   r`   re   rp   rr   rt   rw   r    r   r   r   r      sH  € € € € € ðð ð NÐMÐM€Ið (˜	œÑ)Ô)Ðà€FØ€HðS%ð S%ð S%ð S%ð S%ðj	ð 	ð 	ð ðð ñ „Xðð ðð ñ „Xððð ð ðð ð ð#ð #ð #ð2"ð "ð "ð(ð (ð (ðRð Rð Rðð ð ð<ð ð ðJð Jð Jð!ð !ð !ð !ð !r   r   )
rx   Ú
__future__r   rz   rE   ÚnumpyrV   Úqiskit.circuit.exceptionsr   r   r    r   r   ú<module>r€      s’   ððð ð #Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø €€€Ø Ð Ð Ð à 2Ð 2Ð 2Ð 2Ð 2Ð 2ðZ!ð Z!ð Z!ð Z!ð Z!ñ Z!ô Z!ð Z!ð Z!ð Z!r   