§
    ¹³Ùg  ã                  óR  — d Z ddlmZ ddlmZmZ ddlmZmZ ddl	Z	ddl
mZmZmZ ddlmZ ddlmZmZ dd	lmZ d
 ed¦  «        z   e	j        d
d
gd
dgge	j        ¬¦  «        z  Z ee¦  «         G d„ de¦  «        ¦   «         Z eed
¬¦  «         G d„ de¦  «        ¦   «         ZdS )zHadamard gate.é    )Úannotations)ÚsqrtÚpi)ÚOptionalÚUnionN)ÚSingletonGateÚSingletonControlledGateÚstdlib_singleton_key)ÚQuantumRegister)Úwith_gate_arrayÚwith_controlled_gate_array)ÚStandardGateé   é   éÿÿÿÿ)Údtypec                  ó|   ‡ — e Zd ZdZej        Zddddœdˆ fd„Z e¦   «         Z	d„ Z
	 	 	 	 ddˆ fd„Zddd„Zd„ Zˆ xZS )ÚHGateu—  Single-qubit Hadamard gate.

    This gate is a \pi rotation about the X+Z axis, and has the effect of
    changing computation basis from :math:`|0\rangle,|1\rangle` to
    :math:`|+\rangle,|-\rangle` and vice-versa.

    Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
    with the :meth:`~qiskit.circuit.QuantumCircuit.h` method.

    **Circuit symbol:**

    .. code-block:: text

             â”Œâ”€â”€â”€â”�
        q_0: â”¤ H â”œ
             â””â”€â”€â”€â”˜

    **Matrix Representation:**

    .. math::

        H = \frac{1}{\sqrt{2}}
            \begin{pmatrix}
                1 & 1 \\
                1 & -1
            \end{pmatrix}
    NÚdt)ÚdurationÚunitÚlabelúOptional[str]c               óV   •— t          ¦   «                              ddg |||¬¦  «         dS )zCreate new H gate.Úhr   )r   r   r   N)ÚsuperÚ__init__)Úselfr   r   r   Ú	__class__s       €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/standard_gates/h.pyr   zHGate.__init__<   s.   ø€ å‰Œ×Ò˜˜a ¨5¸8È$ÐÑOÔOÐOÐOÐOó    c                óè   — ddl m} ddlm} t	          dd¦  «        } ||| j        ¬¦  «        } |dt          ¦  «        |d         gg fg}|D ]\  }}}|                     |||¦  «         Œ|| _        dS )z*
        gate h a { u2(0,pi) a; }
        r   ©ÚQuantumCircuitr   )ÚU2GateÚq©ÚnameN)	Úqiskit.circuit.quantumcircuitr$   Úu2r%   r   r(   r   Ú_appendÚ
definition)	r   r$   r%   r&   ÚqcÚrulesÚinstrÚqargsÚcargss	            r    Ú_definezHGate._defineB   s§   € ð
 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐå˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆØ�&˜�B‘-”- ! A¤$ ¨Ð,Ð-ˆØ#(ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr!   r   Únum_ctrl_qubitsÚintú
str | NoneÚ
ctrl_stateúint | str | NoneÚ	annotatedúbool | Nonec                ó’   •— |s|dk    rt          ||| j        ¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }|S )ac  Return a (multi-)controlled-H gate.

        One control qubit returns a CH gate.

        Args:
            num_ctrl_qubits: number of control qubits.
            label: An optional label for the gate [Default: ``None``]
            ctrl_state: control state expressed as integer,
                string (e.g.``'110'``), or ``None``. If ``None``, use all 1s.
            annotated: indicates whether the controlled gate should be implemented
                as an annotated gate. If ``None``, this is handled as ``False``.

        Returns:
            ControlledGate: controlled version of this gate.
        r   )r   r6   Ú_base_label)r3   r   r6   r8   )ÚCHGater   r   Úcontrol)r   r3   r   r6   r8   Úgater   s         €r    r=   zHGate.controlR   s^   ø€ ð, ð 	˜_°Ò1Ð1Ý °*È$Ì*ÐUÑUÔUˆDˆDå‘7”7—?’?Ø /ØØ%Ø#ð	 #ñ ô ˆDð ˆr!   FÚboolc                ó   — t          ¦   «         S )aª  Return inverted H gate (itself).

        Args:
            annotated: when set to ``True``, this is typically used to return an
                :class:`.AnnotatedOperation` with an inverse modifier set instead of a concrete
                :class:`.Gate`. However, for this class this argument is ignored as this gate
                is self-inverse.

        Returns:
            HGate: inverse gate (self-inverse).
        )r   ©r   r8   s     r    ÚinversezHGate.inverses   s   € õ ‰wŒwˆr!   c                ó,   — t          |t          ¦  «        S ©N)Ú
isinstancer   ©r   Úothers     r    Ú__eq__zHGate.__eq__�   s   € Ý˜%¥Ñ'Ô'Ð'r!   rD   )r   r   )r   NNN)r3   r4   r   r5   r6   r7   r8   r9   ©F©r8   r?   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú_standard_gater   r
   Ú_singleton_lookup_keyr2   r=   rB   rH   Ú__classcell__©r   s   @r    r   r      sç   ø€ € € € € ðð ð8 "Ô'€NðPÀÈ4ð Pð Pð Pð Pð Pð Pð Pð Pð 1Ð0Ñ2Ô2Ððð ð ð$  !Ø Ø'+Ø!%ðð ð ð ð ð ð ðBð ð ð ð ð(ð (ð (ð (ð (ð (ð (r!   r   ©r3   c                  óp   ‡ — e Zd ZdZej        Z	 	 dddddœdˆ fd	„Z ed
¬¦  «        Z	d„ Z
ddd„Zd„ Zˆ xZS )r<   u²  Controlled-Hadamard gate.

    Applies a Hadamard on the target qubit if the control is
    in the :math:`|1\rangle` state.

    Can be applied to a :class:`~qiskit.circuit.QuantumCircuit`
    with the :meth:`~qiskit.circuit.QuantumCircuit.ch` method.

    **Circuit symbol:**

    .. code-block:: text

        q_0: â”€â”€â– â”€â”€
             â”Œâ”€â”´â”€â”�
        q_1: â”¤ H â”œ
             â””â”€â”€â”€â”˜

    **Matrix Representation:**

    .. math::

        CH\ q_0, q_1 =
            I \otimes |0\rangle\langle 0| + H \otimes |1\rangle\langle 1| =
            \begin{pmatrix}
                1 & 0 & 0 & 0 \\
                0 & \frac{1}{\sqrt{2}} & 0 & \frac{1}{\sqrt{2}} \\
                0 & 0 & 1 & 0 \\
                0 & \frac{1}{\sqrt{2}} & 0 & -\frac{1}{\sqrt{2}}
            \end{pmatrix}

    .. note::

        In Qiskit's convention, higher qubit indices are more significant
        (little endian convention). In many textbooks, controlled gates are
        presented with the assumption of more significant qubits as control,
        which in our case would be q_1. Thus a textbook matrix for this
        gate will be:

        .. code-block:: text

                 â”Œâ”€â”€â”€â”�
            q_0: â”¤ H â”œ
                 â””â”€â”¬â”€â”˜
            q_1: â”€â”€â– â”€â”€

        .. math::

            CH\ q_1, q_0 =
                |0\rangle\langle 0| \otimes I + |1\rangle\langle 1| \otimes H =
                \begin{pmatrix}
                    1 & 0 & 0 & 0 \\
                    0 & 1 & 0 & 0 \\
                    0 & 0 & \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\
                    0 & 0 & \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}}
                \end{pmatrix}
    Nr   )r   r   r;   r   r   r6   úOptional[Union[int, str]]c               óz   •— t          ¦   «                              ddg d||t          |¬¦  «        |||¬¦
  «
         dS )zCreate new CH gate.Úchr   r   )r   )r3   r   r6   Ú	base_gater   r   r;   N)r   r   r   )r   r   r6   r   r   r;   r   s         €r    r   zCHGate.__init__Â   sY   ø€ õ 	‰Œ×ÒØØØØØØ!Ý +Ð.Ñ.Ô.ØØØ#ð 	ñ 	
ô 	
ð 	
ð 	
ð 	
r!   r   rS   c           	     óü  — ddl m} ddlm} ddlm}m} ddlm}m	} t          dd¦  «        } ||| j        ¬	¦  «        } |¦   «         |d         gg ft          ¦   «         |d         gg f |¦   «         |d         gg f |¦   «         |d         |d         gg f |¦   «         |d         gg ft          ¦   «         |d         gg f |¦   «         |d         gg fg}	|	D ]\  }
}}|                     |
||¦  «         Œ|| _        d
S )z¨
        gate ch a,b {
            s b;
            h b;
            t b;
            cx a, b;
            tdg b;
            h b;
            sdg b;
        }
        r   r#   r   )ÚCXGate)ÚTGateÚTdgGate)ÚSGateÚSdgGater   r&   r'   N)r)   r$   ÚxrZ   Útr[   r\   Úsr]   r^   r   r(   r   r+   r,   )r   r$   rZ   r[   r\   r]   r^   r&   r-   r.   r/   r0   r1   s                r    r2   zCHGate._defineÛ   s]  € ð 	AÐ@Ð@Ð@Ð@Ð@ØÐÐÐÐÐØ%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ø%Ð%Ð%Ð%Ð%Ð%Ð%Ð%å˜A˜sÑ#Ô#ˆØˆ^˜A D¤IÐ.Ñ.Ô.ˆàˆU‰WŒW�q˜”t�f˜bÐ!Ý‰WŒW�q˜”t�f˜bÐ!ØˆU‰WŒW�q˜”t�f˜bÐ!ØˆV‰XŒX˜˜!œ˜a œd�| RÐ(ØˆW‰YŒY˜˜1œ˜ Ð#Ý‰WŒW�q˜”t�f˜bÐ!ØˆW‰YŒY˜˜1œ˜ Ð#ð
ˆð $)ð 	,ð 	,ÑˆE�5˜%Ø�JŠJ�u˜e UÑ+Ô+Ð+Ð+àˆŒˆˆr!   Fr8   r?   c                ó,   — t          | j        ¬¦  «        S )z!Return inverted CH gate (itself).)r6   )r<   r6   rA   s     r    rB   zCHGate.inverseý   s   € å ¤Ð1Ñ1Ô1Ð1r!   c                óL   — t          |t          ¦  «        o| j        |j        k    S rD   )rE   r<   r6   rF   s     r    rH   zCHGate.__eq__  s!   € Ý˜%¥Ñ(Ô(ÐP¨T¬_ÀÔ@PÒ-PÐPr!   )NN)r   r   r6   rU   rI   rJ   )rK   rL   rM   rN   r   r<   rO   r   r
   rP   r2   rB   rH   rQ   rR   s   @r    r<   r<   …   sÉ   ø€ € € € € ð7ð 7ðr "Ô(€Nð  $Ø04ð
ð
 ØØð
ð 
ð 
ð 
ð 
ð 
ð 
ð 
ð. 1Ð0ÀÐCÑCÔCÐð ð  ð  ðD2ð 2ð 2ð 2ð 2ðQð Qð Qð Qð Qð Qð Qr!   r<   )rN   Ú
__future__r   Úmathr   r   Útypingr   r   ÚnumpyÚqiskit.circuit.singletonr   r	   r
   Úqiskit.circuit.quantumregisterr   Úqiskit.circuit._utilsr   r   Úqiskit._accelerate.circuitr   ÚarrayÚ
complex128Ú_H_ARRAYr   r<   © r!   r    ú<module>rp      s™  ðð Ð à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ð Ð Ð Ð Ø "Ð "Ð "Ð "Ð "Ð "Ð "Ð "Ø €€€Ø aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aÐ aØ :Ð :Ð :Ð :Ð :Ð :Ø MÐ MÐ MÐ MÐ MÐ MÐ MÐ MØ 3Ð 3Ð 3Ð 3Ð 3Ð 3àˆtˆt�A‰wŒw‰;˜˜œ q¨! f¨q°"¨gÐ%6¸eÔ>NÐOÑOÔOÑO€ð €�ÑÔðe(ð e(ð e(ð e(ð e(ˆMñ e(ô e(ñ Ôðe(ðP Ð˜H°aÐ8Ñ8Ô8ð|Qð |Qð |Qð |Qð |QÐ$ñ |Qô |Qñ 9Ô8ð|Qð |Qð |Qr!   