§
    ¹³Ùg÷(  ã                  ó@  — d Z ddlmZ ddlZddl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  G d	„ d
¦  «        Zej         G d„ de¦  «        ¦   «         Zej         G d„ de¦  «        ¦   «         Zej         G d„ de¦  «        ¦   «         Z G d„ de¦  «        Zd„ ZdS )zAnnotated Operations.é    )ÚannotationsN)ÚUnionÚList)Ú	Operation)ÚParameterValueType)Ú_compute_control_matrixÚ_ctrl_state_to_int)ÚCircuitErrorc                  ó   — e Zd ZdZdS )ÚModifierz[The base class that all modifiers of :class:`~.AnnotatedOperation` should
    inherit from.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úX/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/annotated_operation.pyr   r      s   € € € € € ðð ð 	€Dr   r   c                  ó   — e Zd ZdZdS )ÚInverseModifierz;Inverse modifier: specifies that the operation is inverted.Nr   r   r   r   r   r   !   s   € € € € € àEÐEà€Dr   r   c                  ó:   — e Zd ZU dZdZded<   dZded<   d	d
d„ZdS )ÚControlModifierz}Control modifier: specifies that the operation is controlled by ``num_ctrl_qubits``
    and has control state ``ctrl_state``.r   ÚintÚnum_ctrl_qubitsNúUnion[int, str, None]Ú
ctrl_statec                ó>   — || _         t          ||¦  «        | _        d S )N)r   r	   r   )Úselfr   r   s      r   Ú__init__zControlModifier.__init__0   s   € Ø.ˆÔÝ,¨Z¸ÑIÔIˆŒˆˆr   )r   N)r   r   r   r   )r   r   r   r   r   Ú__annotations__r   r   r   r   r   r   r   (   sd   € € € € € € ð-ð -ð €OÐÐÐÑØ(,€JÐ,Ð,Ð,Ñ,ðJð Jð Jð Jð Jð Jð Jr   r   c                  ó   — e Zd ZU dZded<   dS )ÚPowerModifierzNPower modifier: specifies that the operation is raised to the power ``power``.ÚfloatÚpowerN)r   r   r   r   r    r   r   r   r"   r"   5   s   € € € € € € àXÐXà€L€L�L€L€Lr   r"   c                  óÚ   — e Zd ZdZd'd„Zed„ ¦   «         Zed„ ¦   «         Zed	„ ¦   «         Zd(d„Z	d)d„Z
d„ Z	 	 	 	 d*d+d„Zd,d-d„Zd.d/d„Zed0d!„¦   «         Zej        d1d#„¦   «         Zd2d&„ZdS )3ÚAnnotatedOperationzAnnotated operation.Úbase_opr   Ú	modifiersúUnion[Modifier, List[Modifier]]c                óT   — || _         	 t          |t          ¦  «        r|n|g| _        dS )a›  
        Create a new AnnotatedOperation.

        An "annotated operation" allows to add a list of modifiers to the
        "base" operation. For now, the only supported modifiers are of
        types :class:`~.InverseModifier`, :class:`~.ControlModifier` and
        :class:`~.PowerModifier`.

        An annotated operation can be viewed as an extension of
        :class:`~.ControlledGate` (which also allows adding control to the
        base operation). However, an important difference is that the
        circuit definition of an annotated operation is not constructed when
        the operation is declared, and instead happens during transpilation,
        specifically during the :class:`~.HighLevelSynthesis` transpiler pass.

        An annotated operation can be also viewed as a "higher-level"
        or "more abstract" object that can be added to a quantum circuit.
        This enables writing transpiler optimization passes that make use of
        this higher-level representation, for instance removing a gate
        that is immediately followed by its inverse.

        Args:
            base_op: base operation being modified
            modifiers: ordered list of modifiers. Supported modifiers include
                ``InverseModifier``, ``ControlModifier`` and ``PowerModifier``.

        Examples::

            op1 = AnnotatedOperation(SGate(), [InverseModifier(), ControlModifier(2)])

            op2_inner = AnnotatedGate(SGate(), InverseModifier())
            op2 = AnnotatedGate(op2_inner, ControlModifier(2))

        Both op1 and op2 are semantically equivalent to an ``SGate()`` which is first
        inverted and then controlled by 2 qubits.
        N)r'   Ú
isinstancer   r(   )r   r'   r(   s      r   r   zAnnotatedOperation.__init__?   s5   € ðJ ˆŒØ[Ý&0°½DÑ&AÔ&AÐR˜˜È	À{ˆŒð	8ð 	8r   c                ó   — dS )z,Unique string identifier for operation type.Ú	annotatedr   ©r   s    r   ÚnamezAnnotatedOperation.namej   s	   € ð ˆ{r   c                óv   — d}| j         D ]!}t          |t          ¦  «        r
||j        z  }Œ"|| j        j        z   S )zNumber of qubits.r   )r(   r+   r   r   r'   Ú
num_qubits)r   r   Úmodifiers      r   r1   zAnnotatedOperation.num_qubitso   sJ   € ð ˆØœð 	<ð 	<ˆHÝ˜(¥OÑ4Ô4ð <Ø 8Ô#;Ñ;�øà ¤Ô!8Ñ8Ð8r   c                ó   — | j         j        S )zNumber of classical bits.)r'   Ú
num_clbitsr.   s    r   r4   zAnnotatedOperation.num_clbitsy   s   € ð Œ|Ô&Ð&r   ÚreturnÚboolc                ól   — t          |t          ¦  «        o| j        |j        k    o| j        |j        k    S )z,Checks if two AnnotatedOperations are equal.)r+   r&   r(   r'   )r   Úothers     r   Ú__eq__zAnnotatedOperation.__eq__~   s9   € õ �uÕ0Ñ1Ô1ð .Ø” %¤/Ò1ð.à” ¤Ò-ð	
r   ú'AnnotatedOperation'c                ó€   — t          | j                             ¦   «         | j                             ¦   «         ¬¦  «        S )z3Return a copy of the :class:`~.AnnotatedOperation`.)r'   r(   )r&   r'   Úcopyr(   r.   s    r   r<   zAnnotatedOperation.copy†   s1   € å!¨$¬,×*;Ò*;Ñ*=Ô*=ÈÌ×I\ÒI\ÑI^ÔI^Ð_Ñ_Ô_Ð_r   c                óž  — ddl m}  || j        ¦  «        }| j        D ]®}t	          |t
          ¦  «        r|                     d¦  «        }Œ-t	          |t          ¦  «        r* |t          |j	        |j
        |j        ¦  «        ¦  «        }Œlt	          |t          ¦  «        r|                     |j        ¦  «        }Œœt          d|› d�¦  «        ‚|S )z@Return a matrix representation (allowing to construct Operator).r   )ÚOperatoréÿÿÿÿúUnknown modifier ú.)Úqiskit.quantum_info.operatorsr>   r'   r(   r+   r   r$   r   r   Údatar   r   r"   r
   )r   r>   Úoperatorr2   s       r   Ú	to_matrixzAnnotatedOperation.to_matrixŠ   sé   € à:Ð:Ð:Ð:Ð:Ð:à�8˜DœLÑ)Ô)ˆàœð 	Dð 	DˆHÝ˜(¥OÑ4Ô4ð DØ#Ÿ>š>¨"Ñ-Ô-��Ý˜H¥oÑ6Ô6ð 	DØ#˜8Ý+Ø œ xÔ'?ÀÔATñô ñô ��õ
 ˜H¥mÑ4Ô4ð DØ#Ÿ>š>¨(¬.Ñ9Ô9��å"Ð#B°xÐ#BÐ#BÐ#BÑCÔCÐCØˆr   é   NTr   r   Úlabelú
str | Noner   úint | str | Noner-   c                ó¦   — | j                              ¦   «         }|                     t          ||¬¦  «        ¦  «         t	          | j        |¦  «        S )ag  
        Return the controlled version of itself.

        Implemented as an annotated operation, see  :class:`.AnnotatedOperation`.

        Args:
            num_ctrl_qubits: number of controls to add to gate (default: ``1``)
            label: ignored (used for consistency with other control methods)
            ctrl_state: The control state in decimal or as a bitstring
                (e.g. ``'111'``). If ``None``, use ``2**num_ctrl_qubits-1``.
            annotated: ignored (used for consistency with other control methods)

        Returns:
            Controlled version of the given operation.
        )r   r   )r(   r<   Úappendr   r&   r'   )r   r   rG   r   r-   Úextended_modifierss         r   ÚcontrolzAnnotatedOperation.controlŸ   sU   € ð. "œ^×0Ò0Ñ2Ô2ÐØ×!Ò!Ý¨OÈ
ÐSÑSÔSñ	
ô 	
ð 	
õ " $¤,Ð0BÑCÔCÐCr   c                ó    — | j                              ¦   «         }|                     t          ¦   «         ¦  «         t	          | j        |¦  «        S )a0  
        Return the inverse version of itself.

        Implemented as an annotated operation, see  :class:`.AnnotatedOperation`.

        Args:
            annotated: ignored (used for consistency with other inverse methods)

        Returns:
            Inverse version of the given operation.
        )r(   r<   rK   r   r&   r'   )r   r-   rL   s      r   ÚinversezAnnotatedOperation.inverse¼   sE   € ð "œ^×0Ò0Ñ2Ô2ÐØ×!Ò!¥/Ñ"3Ô"3Ñ4Ô4Ð4Ý! $¤,Ð0BÑCÔCÐCr   FÚexponentr#   c                ó¢   — | j                              ¦   «         }|                     t          |¦  «        ¦  «         t	          | j        |¦  «        S )ao  
        Raise this gate to the power of ``exponent``.

        Implemented as an annotated operation, see  :class:`.AnnotatedOperation`.

        Args:
            exponent: the power to raise the gate to
            annotated: ignored (used for consistency with other power methods)

        Returns:
            An operation implementing ``gate^exponent``
        )r(   r<   rK   r"   r&   r'   )r   rP   r-   rL   s       r   r$   zAnnotatedOperation.powerÍ   sG   € ð "œ^×0Ò0Ñ2Ô2ÐØ×!Ò!¥-°Ñ"9Ô"9Ñ:Ô:Ð:Ý! $¤,Ð0BÑCÔCÐCr   úlist[ParameterValueType]c                ó.   — t          | j        dg ¦  «        S )z,The params of the underlying base operation.Úparams)Úgetattrr'   r.   s    r   rT   zAnnotatedOperation.paramsß   s   € õ �t”| X¨rÑ2Ô2Ð2r   Úvaluec                óx   — t          | j        d¦  «        r|| j        _        d S t          d| j        › d�¦  «        ‚)NrT   z6Cannot set attribute ``params`` on the base operation rA   )Úhasattrr'   rT   ÚAttributeError)r   rV   s     r   rT   zAnnotatedOperation.paramsä   sH   € å�4”< Ñ*Ô*ð 	Ø"'ˆDŒLÔÐÐå ØXÈÌÐXÐXÐXñô ð r   Ú	parameterr   c                ó�   — t          | j        d¦  «        r| j                             |¦  «        S t          d| j        › d�¦  «        ‚)z7Validate a parameter for the underlying base operation.Úvalidate_parameterz1Cannot validate parameters on the base operation rA   )rX   r'   r\   rY   )r   rZ   s     r   r\   z%AnnotatedOperation.validate_parameterí   sK   € å�4”<Ð!5Ñ6Ô6ð 	>Ø”<×2Ò2°9Ñ=Ô=Ð=åÐ`ÐQUÔQ]Ð`Ð`Ð`ÑaÔaÐar   )r'   r   r(   r)   )r5   r6   )r5   r:   )rF   NNT)
r   r   rG   rH   r   rI   r-   r6   r5   r&   )T)r-   r6   )F)rP   r#   r-   r6   )r5   rR   )rV   rR   )rZ   r   r5   r   )r   r   r   r   r   Úpropertyr/   r1   r4   r9   r<   rE   rM   rO   r$   rT   Úsetterr\   r   r   r   r&   r&   <   s  € € € € € ØÐð)8ð )8ð )8ð )8ðV ðð ñ „Xðð ð9ð 9ñ „Xð9ð ð'ð 'ñ „Xð'ð
ð 
ð 
ð 
ð`ð `ð `ð `ðð ð ð.  !Ø Ø'+ØðDð Dð Dð Dð Dð:Dð Dð Dð Dð Dð"Dð Dð Dð Dð Dð$ ð3ð 3ð 3ñ „Xð3ð „]ðð ð ñ „]ððbð bð bð bð bð br   r&   c                ó  — d}d}d}| D ]�}t          |t          ¦  «        r|dz  }Œt          |t          ¦  «        r||j        z  }||j        z  |j        z  }ŒOt          |t
          ¦  «        r||j        z  }Œot          d|› d�¦  «        ‚g }|dk     r&|                     t          ¦   «         ¦  «         |dz  }|dk    r"|                     t          |¦  «        ¦  «         |dk    r#|                     t          ||¦  «        ¦  «         |S )aÏ  
    Returns the canonical representative of the modifier list. This is possible
    since all the modifiers commute; also note that InverseModifier is a special
    case of PowerModifier. The current solution is to compute the total number
    of control qubits / control state and the total power. The InverseModifier
    will be present if total power is negative, whereas the power modifier will
    be present only with positive powers different from 1.
    rF   r   r?   r@   rA   )	r+   r   r   r   r   r"   r$   r
   rK   )r(   r$   r   r   r2   Úcanonical_modifierss         r   Ú_canonicalize_modifiersra   õ   s:  € ð €EØ€OØ€Jàð 	@ð 	@ˆÝ�h¥Ñ0Ô0ð 	@Ø�R‰KˆEˆEÝ˜¥/Ñ2Ô2ð 	@Ø˜xÔ7Ñ7ˆOØ$¨Ô(@Ñ@ÀHÔDWÑWˆJˆJÝ˜¥-Ñ0Ô0ð 	@Ø�X”^Ñ#ˆEˆEåÐ>°8Ð>Ð>Ð>Ñ?Ô?Ð?àÐØˆq‚y€yØ×"Ò"¥?Ñ#4Ô#4Ñ5Ô5Ð5Ø�‰ˆà�‚z€zØ×"Ò"¥=°Ñ#7Ô#7Ñ8Ô8Ð8Ø˜ÒÐØ×"Ò"¥?°?ÀJÑ#OÔ#OÑPÔPÐPàÐr   )r   Ú
__future__r   ÚdataclassesÚtypingr   r   Úqiskit.circuit.operationr   Ú"qiskit.circuit.parameterexpressionr   Úqiskit.circuit._utilsr   r	   Úqiskit.circuit.exceptionsr
   r   Ú	dataclassr   r   r"   r&   ra   r   r   r   ú<module>rj      sÃ  ðð Ð à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .Ø AÐ AÐ AÐ AÐ AÐ AØ MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ 2Ð 2Ð 2Ð 2Ð 2Ð 2ð	ð 	ð 	ð 	ð 	ñ 	ô 	ð 	ð Ôð	ð 	ð 	ð 	ð 	�hñ 	ô 	ñ Ôð	ð Ôð	Jð 	Jð 	Jð 	Jð 	J�hñ 	Jô 	Jñ Ôð	Jð Ôðð ð ð ð �Hñ ô ñ Ôððvbð vbð vbð vbð vb˜ñ vbô vbð vbðr"ð "ð "ð "ð "r   