§
    ¹³Ùgò  ã                   óš   — d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	 ddl
mZmZ  G d	„ d
e¦  «        Zdee         dee         defd„ZdS )zFourier checking circuit.é    )ÚSequenceN)ÚQuantumCircuit)ÚCircuitError)Údeprecate_funcé   )ÚDiagonalÚDiagonalGatec                   óp   ‡ — e Zd ZdZ eddd¬¦  «        dee         dee         dd	fˆ fd
„¦   «         Zˆ xZS )ÚFourierCheckinga>  Fourier checking circuit.

    The circuit for the Fourier checking algorithm, introduced in [1],
    involves a layer of Hadamards, the function :math:`f`, another layer of
    Hadamards, the function :math:`g`, followed by a final layer of Hadamards.
    The functions :math:`f` and :math:`g` are classical functions realized
    as phase oracles (diagonal operators with {-1, 1} on the diagonal).

    The probability of observing the all-zeros string is :math:`p(f,g)`.
    The algorithm solves the promise Fourier checking problem,
    which decides if f is correlated with the Fourier transform
    of g, by testing if :math:`p(f,g) <= 0.01` or :math:`p(f,g) >= 0.05`,
    promised that one or the other of these is true.

    The functions :math:`f` and :math:`g` are currently implemented
    from their truth tables but could be represented concisely and
    implemented efficiently for special classes of functions.

    Fourier checking is a special case of :math:`k`-fold forrelation [2].

    **Reference:**

    [1] S. Aaronson, BQP and the Polynomial Hierarchy, 2009 (Section 3.2).
    `arXiv:0910.4698 <https://arxiv.org/abs/0910.4698>`_

    [2] S. Aaronson, A. Ambainis, Forrelation: a problem that
    optimally separates quantum from classical computing, 2014.
    `arXiv:1411.5729 <https://arxiv.org/abs/1411.5729>`_
    z1.3z4Use qiskit.circuit.library.fourier_checking instead.T)ÚsinceÚadditional_msgÚpendingÚfÚgÚreturnNc                 óô  •— t          j        t          |¦  «        ¦  «        }t          |¦  «        t          |¦  «        k    s|dk    s|                     ¦   «         st	          d¦  «        ‚t          t          |¦  «        d|› d|› �¬¦  «        }|                     |j        ¦  «         | 	                    t          |¦  «        d¬¦  «         |                     |j        ¦  «         | 	                    t          |¦  «        d¬¦  «         |                     |j        ¦  «          t          ¦   «         j        |j        d|j        iŽ |  	                    |                     ¦   «         | j        d¬	¦  «         d
S )aÙ  Create Fourier checking circuit.

        Args:
            f: truth table for f, length 2**n list of {1,-1}.
            g: truth table for g, length 2**n list of {1,-1}.

        Raises:
            CircuitError: if the inputs f and g are not valid.

        Reference Circuit:
            .. plot::
               :alt: Diagram illustrating the previously described circuit.

               from qiskit.circuit.library import FourierChecking
               from qiskit.visualization.library import _generate_circuit_library_visualization
               f = [1, -1, -1, -1]
               g = [1, 1, -1, -1]
               circuit = FourierChecking(f, g)
               _generate_circuit_library_visualization(circuit)
        r   ú_The functions f and g must be given as truth tables, each as a list of 2**n entries of {1, -1}.úfc: ú, ©ÚnameT)Úinplacer   )Úqubitsr   N)ÚmathÚlog2ÚlenÚ
is_integerr   r   ÚintÚhr   Úcomposer   ÚsuperÚ__init__Úqregsr   Úto_gate)Úselfr   r   Ú
num_qubitsÚcircuitÚ	__class__s        €ú]/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/fourier_checking.pyr"   zFourierChecking.__init__8   sD  ø€ õ4 ”Y�s 1™vœvÑ&Ô&ˆ
åˆq‰6Œ6•S˜‘V”VÒÐ˜z¨Qš˜°j×6KÒ6KÑ6MÔ6M˜Ýðñô ð õ !¥ Z¡¤°¸a°°À1°°ÐGÑGÔGˆØ�	Š	�'”.Ñ!Ô!Ð!Ø�Š� ™œ¨TˆÑ2Ô2Ð2Ø�	Š	�'”.Ñ!Ô!Ð!Ø�Š� ™œ¨TˆÑ2Ô2Ð2Ø�	Š	�'”.Ñ!Ô!Ð!Ø�‰ŒÔ˜'œ-Ð;¨g¬lÐ;Ð;Ð;Ø�Š�W—_’_Ñ&Ô&¨t¬{ÀDˆÑIÔIÐIÐIÐIó    )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   Ú__classcell__)r(   s   @r)   r   r      sš   ø€ € € € € ðð ð< €^ØØMØðñ ô ð
(J˜( 3œ-ð (J¨H°S¬Mð (J¸dð (Jð (Jð (Jð (Jð (Jñô ð
(Jð (Jð (Jð (Jð (Jr*   r   r   r   r   c                 ó‚  — t          j        t          | ¦  «        ¦  «        }t          | ¦  «        t          |¦  «        k    s|dk    s|                     ¦   «         st	          d¦  «        ‚t          |¦  «        }t          |d| › d|› �¬¦  «        }|                     |j        ¦  «         | 	                    t          | ¦  «        t          |¦  «        ¦  «         |                     |j        ¦  «         | 	                    t          |¦  «        t          |¦  «        ¦  «         |                     |j        ¦  «         |S )aU  Fourier checking circuit.

    The circuit for the Fourier checking algorithm, introduced in [1],
    involves a layer of Hadamards, the function :math:`f`, another layer of
    Hadamards, the function :math:`g`, followed by a final layer of Hadamards.
    The functions :math:`f` and :math:`g` are classical functions realized
    as phase oracles (diagonal operators with {-1, 1} on the diagonal).

    The probability of observing the all-zeros string is :math:`p(f,g)`.
    The algorithm solves the promise Fourier checking problem,
    which decides if f is correlated with the Fourier transform
    of g, by testing if :math:`p(f,g) <= 0.01` or :math:`p(f,g) >= 0.05`,
    promised that one or the other of these is true.

    The functions :math:`f` and :math:`g` are currently implemented
    from their truth tables but could be represented concisely and
    implemented efficiently for special classes of functions.

    Fourier checking is a special case of :math:`k`-fold forrelation [2].

    **Reference Circuit:**

    .. plot::
       :alt: Circuit diagram output by the previous code.
       :include-source:

       from qiskit.circuit.library import fourier_checking
       circuit = fourier_checking([1, -1, -1, -1], [1, 1, -1, -1])
       circuit.draw('mpl')

    **Reference:**

    [1] S. Aaronson, BQP and the Polynomial Hierarchy, 2009 (Section 3.2).
    `arXiv:0910.4698 <https://arxiv.org/abs/0910.4698>`_

    [2] S. Aaronson, A. Ambainis, Forrelation: a problem that
    optimally separates quantum from classical computing, 2014.
    `arXiv:1411.5729 <https://arxiv.org/abs/1411.5729>`_
    r   r   r   r   r   )r   r   r   r   r   r   r   r   r   Úappendr	   Úrange)r   r   r&   r'   s       r)   Úfourier_checkingr3   h   s  € õP ”�3˜q™6œ6Ñ"Ô"€Jå
ˆ1�v„v•�Q‘”ÒÐ˜:¨š?˜?°*×2GÒ2GÑ2IÔ2I˜?Ýðñ
ô 
ð 	
õ
 �Z‘”€Jå˜Z¨o°Q¨o¨o¸!¨o¨oÐ>Ñ>Ô>€GØ‡I‚IˆgŒnÑÔÐØ‡N‚N•< ‘?”?¥E¨*Ñ$5Ô$5Ñ6Ô6Ð6Ø‡I‚IˆgŒnÑÔÐØ‡N‚N•< ‘?”?¥E¨*Ñ$5Ô$5Ñ6Ô6Ð6Ø‡I‚IˆgŒnÑÔÐØ€Nr*   )r.   Úcollections.abcr   r   Úqiskit.circuitr   Úqiskit.circuit.exceptionsr   Úqiskit.utils.deprecationr   Úgeneralized_gates.diagonalr   r	   r   r   r3   © r*   r)   ú<module>r:      sì   ðð  Ð à $Ð $Ð $Ð $Ð $Ð $Ø €€€à )Ð )Ð )Ð )Ð )Ð )Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3à >Ð >Ð >Ð >Ð >Ð >Ð >Ð >ðLJð LJð LJð LJð LJ�nñ LJô LJð LJð^8˜ œð 8¨(°3¬-ð 8¸Nð 8ð 8ð 8ð 8ð 8ð 8r*   