
    z	i                         S r SSKJr  SSKrSSKJr  SSKJr  SSKJ	r	  SSK
JrJr   " S	 S
\5      rS\\   S\\   S\4S jrg)zFourier checking circuit.    )SequenceN)QuantumCircuit)CircuitError)deprecate_func   )DiagonalDiagonalGatec                   ^   ^  \ rS rSrSr\" SSSS9S\\   S\\   S	S
4U 4S jj5       rSr	U =r
$ )FourierChecking   a  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].

References:

[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2.1z4Use qiskit.circuit.library.fourier_checking instead.zin Qiskit 3.0)sinceadditional_msgremoval_timelinefgreturnNc                   > [         R                  " [        U5      5      n[        U5      [        U5      :w  d  US:X  d  UR                  5       (       d  [	        S5      e[        [        U5      SU SU 3S9nUR                  UR                  5        UR                  [        U5      SS9  UR                  UR                  5        UR                  [        U5      SS9  UR                  UR                  5        [        TU ]0  " UR                  SUR                  06  U R                  UR                  5       U R                  SS	9  g
)aa  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        a/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/circuit/library/fourier_checking.pyr#   FourierChecking.__init__8   s    4 YYs1v&
q6SVzQj6K6K6M6M  !ZaS1#G		'..!T2		'..!T2		'..!'--;gll;W__&t{{DI     )__name__
__module____qualname____firstlineno____doc__r   r   r   r#   __static_attributes____classcell__)r)   s   @r*   r   r      sL    < M(
(J(3- (JHSM (Jd (J
(Jr,   r   r   r   r   c                 (   [         R                  " [        U 5      5      n[        U 5      [        U5      :w  d  US:X  d  UR                  5       (       d  [	        S5      e[        U5      n[        USU  SU 3S9nUR                  UR                  5        UR                  [        U 5      [        U5      5        UR                  UR                  5        UR                  [        U5      [        U5      5        UR                  UR                  5        U$ )a  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')

References:

[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_checkingr8   h   s    P 3q6"J
1vQ:?*2G2G2I2I
 	

 ZJZQCr!o>GIIgnnNN<?E*$56IIgnnNN<?E*$56IIgnnNr,   )r2   collections.abcr   r   qiskit.circuitr   qiskit.circuit.exceptionsr   qiskit.utils.deprecationr   generalized_gates.diagonalr   r	   r   r   r8   r-   r,   r*   <module>r>      sO      $  ) 2 3 >LJn LJ^8 8(3- 8N 8r,   