
    z	i                       S r SSKJr  SSKJr  SSKJrJr  SSKrSSK	J
r
JrJr  SSKJrJr  SSKJr  S	\" S
5      -  \R$                  " S	S	/S	S//\R&                  S9-  r\" \5       " S S\
5      5       r\" \S	S9 " S S\5      5       rg)zHadamard gate.    )annotations)sqrt)OptionalUnionN)SingletonGateSingletonControlledGatestdlib_singleton_key)with_gate_arraywith_controlled_gate_array)StandardGate      )dtypec                     ^  \ rS rSrSr\R                  rS	S
U 4S jjjr\	" 5       r
S r    S       SU 4S jjjrSSS jjrS rSrU =r$ )HGate   uG  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}
c                &   > [         TU ]  SS/ US9  g)z2
Args:
    label: An optional label for the gate.
hr   labelN)super__init__)selfr   	__class__s     a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/standard_gates/h.pyr   HGate.__init__;   s    
 	a51    c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gzDefault definitionr   )QuantumCircuitT)legacy_qubitsnameN)	qiskit.circuitr!   _from_circuit_datar   H_get_definitionparamsr#   
definitionr   r!   s     r   _defineHGate._defineD   sA     	2 );;NN**4;;7tRVR[R[ < 
r   c                n   > U(       d  US:X  a  [        X#U R                  S9nU$ [        TU ]  UUUUS9nU$ )a  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   
ctrl_state_base_label)num_ctrl_qubitsr   r.   	annotated)CHGater   r   control)r   r0   r   r.   r1   gater   s         r   r3   HGate.controlQ   sN    , _1$**UD  7? /%#	 # D r   c                    [        5       $ )aj  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   r1   s     r   inverseHGate.inverser   s     wr   c                "    [        U[        5      $ N)
isinstancer   r   others     r   __eq__HGate.__eq__   s    %''r   r)   r;   )r   Optional[str])r   NNN)r0   intr   z
str | Noner.   zint | str | Noner1   zbool | NoneFr1   bool)__name__
__module____qualname____firstlineno____doc__r   r&   _standard_gater   r	   _singleton_lookup_keyr+   r3   r8   r?   __static_attributes____classcell__r   s   @r   r   r      s{    8 "^^N2 2 12
  ! '+!%  %	
  B( (r   r   r0   c                     ^  \ rS rSrSr\R                  r  SSS.   SU 4S jjjjr\	" SS9r
S rSSS	 jjrS
 rSrU =r$ )r2      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}
N)r/   c               <   > [         TU ]  SS/ SUU[        US9US9  g)zCreate new CH gate.chr   r   r   )r0   r   r.   	base_gater/   N)r   r   r   )r   r   r.   r/   r   s       r   r   CHGate.__init__   s4     	!+.# 	 		
r   r   rQ   c                    SSK Jn  UR                  [        R                  R                  U R                  5      SU R                  S9U l        gr    )	r$   r!   r%   r   CHr'   r(   r#   r)   r*   s     r   r+   CHGate._define   sA     	2 );;OO++DKK8SWS\S\ < 
r   c                (    [        U R                  S9$ )z!Return inverted CH gate (itself).)r.   )r2   r.   r7   s     r   r8   CHGate.inverse   s    11r   c                b    [        U[        5      =(       a    U R                  UR                  :H  $ r;   )r<   r2   r.   r=   s     r   r?   CHGate.__eq__   s#    %(PT__@P@P-PPr   rA   )NN)r   rB   r.   zOptional[Union[int, str]]rD   rE   )rG   rH   rI   rJ   rK   r   rY   rL   r   r	   rM   r+   r8   r?   rN   rO   rP   s   @r   r2   r2      se    7r "__N  $04

 

 .
 
& 1C
2Q Qr   r2   )rK   
__future__r   mathr   typingr   r   numpyqiskit.circuit.singletonr   r   r	   qiskit.circuit._utilsr
   r   qiskit._accelerate.circuitr   array
complex128_H_ARRAYr   r2    r   r   <module>rj      s     "  "  a a M 3tAw;q!fq"g%6e>N>NOO e(M e( e(P Ha8dQ$ dQ 9dQr   