§
    ¹³Ùg(  ã                  ó‚   — d Z ddlmZ ddlmZmZ ddlZddlm	Z	 ddl
mZ ddlmZmZmZ dd	lmZ  G d
„ de¦  «        ZdS )úUnitary gate.é    )Úannotations)ÚIteratorÚIterableN)ÚParameterExpression)ÚCircuitErroré   )ÚAnnotatedOperationÚControlModifierÚPowerModifier)ÚInstructionc                  óº   ‡ — e Zd ZdZ	 	 	 d-d.ˆ fd„ZdZd/d„Zd0d1d„Zd2d„Zd2d„Z		 	 	 	 d3d4d „Z
ed5d#„¦   «         Zed6d&„¦   «         Zed7d(„¦   «         Zd8d+„Zd,„ Zˆ xZS )9ÚGater   NÚdtÚnameÚstrÚ
num_qubitsÚintÚparamsÚlistÚlabelú
str | NoneÚreturnÚNonec           	     óf   •— d| _         t          ¦   «                              ||d||||¬¦  «         dS )zóCreate a new gate.

        Args:
            name: The Qobj name of the gate.
            num_qubits: The number of qubits the gate acts on.
            params: A list of parameters.
            label: An optional label for the gate.
        Nr   )r   ÚdurationÚunit)Ú
definitionÚsuperÚ__init__)Úselfr   r   r   r   r   r   Ú	__class__s          €úI/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/gate.pyr    zGate.__init__   s:   ø€ ð" ˆŒÝ‰Œ×Ò˜˜z¨1¨f¸EÈHÐ[_ÐÑ`Ô`Ð`Ð`Ð`ó    é   ú
np.ndarrayc                ó–   — t          | d¦  «        r|                      t          ¬¦  «        S t          dt	          | ¦  «        › �¦  «        ‚)aB  Return a Numpy.array for the gate unitary matrix.

        Returns:
            np.ndarray: if the Gate subclass has a matrix definition.

        Raises:
            CircuitError: If a Gate subclass does not implement this method an
                exception will be raised when this base class method is called.
        Ú	__array__)Údtypezto_matrix not defined for this )Úhasattrr(   Úcomplexr   Útype)r!   s    r#   Ú	to_matrixzGate.to_matrix3   sG   € õ �4˜Ñ%Ô%ð 	1Ø—>’>­�>Ñ0Ô0Ð0ÝÐI½TÀ$¹Z¼ZÐIÐIÑJÔJÐJr$   FÚexponentÚfloatÚ	annotatedÚboolc                óÂ   — ddl m} ddlm} |s5 | || ¦  «                             |d¬¦  «        | j        › d|› �¬¦  «        S t          | t          |¦  «        ¦  «        S )a¸  Raise this gate to the power of ``exponent``.

        Implemented either as a unitary gate (ref. :class:`~.library.UnitaryGate`)
        or as an annotated operation (ref. :class:`.AnnotatedOperation`). In the case of several standard
        gates, such as :class:`.RXGate`, when the power of a gate can be expressed in terms of another
        standard gate that is returned directly.

        Args:
            exponent (float): the power to raise the gate to
            annotated (bool): indicates whether the power gate can be implemented
                as an annotated operation. In the case of several standard
                gates, such as :class:`.RXGate`, this argument is ignored when
                the power of a gate can be expressed in terms of another
                standard gate.

        Returns:
            An operation implementing ``gate^exponent``

        Raises:
            CircuitError: If gate is not unitary
        r   )ÚOperator)ÚUnitaryGateT)Úassume_unitaryú^)r   )Úqiskit.quantum_info.operatorsr3   Ú0qiskit.circuit.library.generalized_gates.unitaryr4   Úpowerr   r
   r   )r!   r.   r0   r3   r4   s        r#   r9   z
Gate.powerA   s•   € ð. 	;Ð:Ð:Ð:Ð:Ð:ØPÐPÐPÐPÐPÐPàð 	EØ�;Ø�˜‘”×$Ò$ X¸dÐ$ÑCÔCÈdÌiÐKdÐKdÐZbÐKdÐKdðñ ô ð õ & d­M¸(Ñ,CÔ,CÑDÔDÐDr$   ú'Gate'c                ó,   — |                       |¦  «        S ©N)r9   )r!   r.   s     r#   Ú__pow__zGate.__pow__b   s   € Ø�zŠz˜(Ñ#Ô#Ð#r$   c                óx   — t          | j        › d|› �| j        g ¬¦  «        }| j        |_        | j        |_        |S )NÚ*)r   r   r   )r   r   r   Úvalidate_parameterr   )r!   r.   Úgates      r#   Ú_return_repeatzGate._return_repeate   sB   € Ý˜DœIÐ2Ð2¨Ð2Ð2¸t¼ÐWYÐZÑZÔZˆØ"&Ô"9ˆÔØ”kˆŒØˆr$   r	   Únum_ctrl_qubitsÚ
ctrl_stateúint | str | Noneúbool | Nonec                ól   — |sddl m }  || |||¦  «        S t          | t          ||¬¦  «        ¦  «        S )a‰  Return the controlled version of itself.

        Implemented either as a controlled gate (ref. :class:`.ControlledGate`)
        or as an annotated operation (ref. :class:`.AnnotatedOperation`).

        Args:
            num_ctrl_qubits: number of controls to add to gate (default: ``1``)
            label: optional gate label. Ignored if implemented as an annotated
                operation.
            ctrl_state: the control state in decimal or as a bitstring
                (e.g. ``'111'``). If ``None``, use ``2**num_ctrl_qubits-1``.
            annotated: indicates whether the controlled gate is implemented
                as an annotated gate. If ``None``, this is set to ``False``
                if the controlled gate can directly be constructed, and otherwise
                set to ``True``. This allows defering the construction process in case the
                synthesis of the controlled gate requires more information (e.g.
                values of unbound parameters).

        Returns:
            Controlled version of the given operation.

        Raises:
            QiskitError: unrecognized mode or invalid ctrl_state
        r	   )Úadd_control)rC   rD   )rH   r
   r   )r!   rC   r   rD   r0   rH   s         r#   ÚcontrolzGate.controlk   s[   € ð> ð 		à0Ð0Ð0Ð0Ð0Ð0à�;˜t _°e¸ZÑHÔHÐHõ &Ø•o°oÐR\Ð]Ñ]Ô]ñô ð r$   ÚqargúIterator[tuple[list, list]]c              #  ó"   K  — | D ]	}|gg fV — Œ
dS )zXExpands a single argument.

        For example: [q[0], q[1]] -> [q[0]], [q[1]]
        N© )rJ   Úarg0s     r#   Ú_broadcast_single_argumentzGate._broadcast_single_argument•   s6   è è € ð ð 	ð 	ˆDØ�&˜"�*ÐÐÐÐð	ð 	r$   Úqarg0Úqarg1c              #  óP  K  — t          | ¦  «        t          |¦  «        k    r t          | |¦  «        D ]\  }}||gg fV — Œd S t          | ¦  «        dk    r|D ]}| d         |gg fV — Œd S t          |¦  «        dk    r| D ]}||d         gg fV — Œd S t          d| › d|› �¦  «        ‚)Nr	   r   z4Not sure how to combine these two-qubit arguments:
 z
 )ÚlenÚzipr   )rP   rQ   rN   Úarg1s       r#   Ú_broadcast_2_argumentszGate._broadcast_2_arguments    s  è è € åˆu‰:Œ:�˜U™œÒ#Ð#õ " %¨Ñ/Ô/ð 'ð '‘
��dØ˜T�l BÐ&Ð&Ð&Ð&Ð&ð'ð 'å�‰ZŒZ˜1Š_ˆ_ð ð +ð +�Ø˜Q”x Ð&¨Ð*Ð*Ð*Ð*Ð*ð+ð +å�‰ZŒZ˜1Š_ˆ_ð ð +ð +�Ø˜U 1œXÐ&¨Ð*Ð*Ð*Ð*Ð*ð+ð +õ ØYÈÐYÐYÐRWÐYÐYñô ð r$   Úqargsc              #  ó¦   ‡ K  — t          ˆ fd„‰ D ¦   «         ¦  «        r!t          ‰ Ž D ]}t          |¦  «        g fV — Œd S t          d‰ › d�¦  «        ‚)Nc              3  ód   •K  — | ]*}t          |¦  «        t          ‰d          ¦  «        k    V — Œ+dS )r   N)rS   )Ú.0rJ   rW   s     €r#   ú	<genexpr>z1Gate._broadcast_3_or_more_args.<locals>.<genexpr>¸   s8   øè è € Ð<Ð<¨d�s�4‰yŒy�C  a¤™MœMÒ)Ð<Ð<Ð<Ð<Ð<Ð<r$   z0Not sure how to combine these qubit arguments:
 ú
)ÚallrT   r   r   )rW   Úargs   ` r#   Ú_broadcast_3_or_more_argszGate._broadcast_3_or_more_args¶   s€   øè è € åÐ<Ð<Ð<Ð<°eÐ<Ñ<Ô<Ñ<Ô<ð 	^Ý˜E�{ð $ð $�Ý˜3‘i”i �mÐ#Ð#Ð#Ð#ð$ð $õ Ð\ÐSXÐ\Ð\Ð\Ñ]Ô]Ð]r$   ÚcargsúIterable[tuple[list, list]]c           	     óš  — t          |¦  «        | j        k    s|r8t          dt          |¦  «        › dt          |¦  «        › d| j        › d�¦  «        ‚t          d„ |D ¦   «         ¦  «        rt          d¦  «        ‚t          |¦  «        dk    rg g fgS t          |¦  «        dk    r t                               |d         ¦  «        S t          |¦  «        d	k    r't                               |d         |d         ¦  «        S t          |¦  «        d
k    rt                               |¦  «        S t          dt          |¦  «        › d�¦  «        ‚)a½  Validation and handling of the arguments and its relationship.

        For example, ``cx([q[0],q[1]], q[2])`` means ``cx(q[0], q[2]); cx(q[1], q[2])``. This
        method yields the arguments in the right grouping. In the given example::

            in: [[q[0],q[1]], q[2]],[]
            outs: [q[0], q[2]], []
                  [q[1], q[2]], []

        The general broadcasting rules are:

            * If len(qargs) == 1::

                [q[0], q[1]] -> [q[0]],[q[1]]

            * If len(qargs) == 2::

                [[q[0], q[1]], [r[0], r[1]]] -> [q[0], r[0]], [q[1], r[1]]
                [[q[0]], [r[0], r[1]]]       -> [q[0], r[0]], [q[0], r[1]]
                [[q[0], q[1]], [r[0]]]       -> [q[0], r[0]], [q[1], r[0]]

            * If len(qargs) >= 3::

                [q[0], q[1]], [r[0], r[1]],  ...] -> [q[0], r[0], ...], [q[1], r[1], ...]

        Args:
            qargs: List of quantum bit arguments.
            cargs: List of classical bit arguments.

        Returns:
            A tuple with single arguments.

        Raises:
            CircuitError: If the input is not valid. For example, the number of
                arguments does not match the gate expectation.
        zThe amount of qubit(z)/clbit(z1) arguments does not match the gate expectation (z).c              3  ó   K  — | ]}| V — Œd S r<   rM   )rZ   rJ   s     r#   r[   z+Gate.broadcast_arguments.<locals>.<genexpr>é   s$   è è € Ð*Ð*˜D�4ˆxÐ*Ð*Ð*Ð*Ð*Ð*r$   z&One or more of the arguments are emptyr   r	   é   é   zThis gate cannot handle z
 arguments)rS   r   r   Úanyr   rO   rV   r_   )r!   rW   r`   s      r#   Úbroadcast_argumentszGate.broadcast_arguments¾   s^  € õJ ˆu‰:Œ:˜œÒ(Ð(¨EÐ(ÝðH¥s¨5¡z¤zð Hð H½3¸u¹:¼:ð Hð HØ48´OðHð Hð Hñô ð õ
 Ð*Ð* EÐ*Ñ*Ô*Ñ*Ô*ð 	IÝÐGÑHÔHÐHåˆu‰:Œ:˜Š?ˆ?à�R�ðð õ ˆu‰:Œ:˜Š?ˆ?Ý×2Ò2°5¸´8Ñ<Ô<Ð<Ý�‰ZŒZ˜1Š_ˆ_Ý×.Ò.¨u°Q¬x¸¸q¼ÑBÔBÐBÝ�‰ZŒZ˜1Š_ˆ_Ý×1Ò1°%Ñ8Ô8Ð8åÐP½#¸e¹*¼*ÐPÐPÐPÑQÔQÐQr$   c                ó¾  — t          |t          ¦  «        rIt          |j        ¦  «        dk    r|S |                     ¦   «         sd| j        › �}t          |¦  «        ‚|S t          |t          t          f¦  «        r|S t          |t          j
        t          j        f¦  «        r|                     ¦   «         S t          dt          |¦  «        › d| j        › d�¦  «        ‚)z<Gate parameters should be int, float, or ParameterExpressionr   z.Bound parameter expression is complex in gate zInvalid param type z
 for gate ú.)Ú
isinstancer   rS   Ú
parametersÚis_realr   r   r   r/   ÚnpÚintegerÚfloatingÚitemr,   )r!   Ú	parameterÚmsgs      r#   r@   zGate.validate_parameterù   sÝ   € å�iÕ!4Ñ5Ô5ð 	Ý�9Ô'Ñ(Ô(¨1Ò,Ð,Ø Ð Ø×$Ò$Ñ&Ô&ð (ØRÀtÄyÐRÐR�Ý" 3Ñ'Ô'Ð'ØÐÝ�i¥#¥u Ñ.Ô.ð 	^ØÐÝ˜	¥B¤Jµ´Ð#<Ñ=Ô=ð 	^Ø—>’>Ñ#Ô#Ð#åÐ\µT¸)±_´_Ð\Ð\ÐPTÔPYÐ\Ð\Ð\Ñ]Ô]Ð]r$   )NNr   )
r   r   r   r   r   r   r   r   r   r   )r   r&   )F)r.   r/   r0   r1   )r.   r/   r   r:   )r	   NNN)rC   r   r   r   rD   rE   r0   rF   )rJ   r   r   rK   )rP   r   rQ   r   r   rK   )rW   r   r   rK   )rW   r   r`   r   r   ra   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r    Ú__array_priority__r-   r9   r=   rB   rI   ÚstaticmethodrO   rV   r_   rg   r@   Ú__classcell__)r"   s   @r#   r   r      s|  ø€ € € € € ØÐð !ØØðað að að að að að að* ÐðKð Kð Kð KðEð Eð Eð Eð EðB$ð $ð $ð $ðð ð ð ð  !Ø Ø'+Ø!%ð(ð (ð (ð (ð (ðT ðð ð ñ „\ðð ðð ð ñ „\ðð* ð^ð ^ð ^ñ „\ð^ð9Rð 9Rð 9Rð 9Rðv^ð ^ð ^ð ^ð ^ð ^ð ^r$   r   )rv   Ú
__future__r   Útypingr   r   Únumpyrm   Ú"qiskit.circuit.parameterexpressionr   Úqiskit.circuit.exceptionsr   Úannotated_operationr
   r   r   Úinstructionr   r   rM   r$   r#   ú<module>r�      sß   ðð Ð à "Ð "Ð "Ð "Ð "Ð "Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð à BÐ BÐ BÐ BÐ BÐ BØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SÐ SØ $Ð $Ð $Ð $Ð $Ð $ðn^ð n^ð n^ð n^ð n^ˆ;ñ n^ô n^ð n^ð n^ð n^r$   