§
    ¹³Ùg&  ã                  óf   — 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
  G d„ de¦  «        Zdd„ZdS )zHidden Linear Function circuit.é    )ÚannotationsN)ÚQuantumCircuit)ÚCircuitError)Údeprecate_funcc                  óL   ‡ — e Zd ZdZ eddd¬¦  «        dˆ fd
„¦   «         Zˆ xZS )ÚHiddenLinearFunctiona¿  Circuit to solve the hidden linear function problem.

    The 2D Hidden Linear Function problem is determined by a 2D adjacency
    matrix A, where only elements that are nearest-neighbor on a grid have
    non-zero entries. Each row/column corresponds to one binary variable
    :math:`x_i`.

    The hidden linear function problem is as follows:

    Consider the quadratic form

    .. math::

        q(x) = \sum_{i,j=1}^{n}{x_i x_j} ~(\mathrm{mod}~ 4)

    and restrict :math:`q(x)` onto the nullspace of A. This results in a linear
    function.

    .. math::

        2 \sum_{i=1}^{n}{z_i x_i} ~(\mathrm{mod}~ 4)  \forall  x \in \mathrm{Ker}(A)

    and the goal is to recover this linear function (equivalently a vector
    :math:`[z_0, ..., z_{n-1}]`). There can be multiple solutions.

    In [1] it is shown that the present circuit solves this problem
    on a quantum computer in constant depth, whereas any corresponding
    solution on a classical computer would require circuits that grow
    logarithmically with :math:`n`. Thus this circuit is an example
    of quantum advantage with shallow circuits.

    **Reference Circuit:**

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

           from qiskit.circuit.library import HiddenLinearFunction
           from qiskit.visualization.library import _generate_circuit_library_visualization
           A = [[1, 1, 0], [1, 0, 1], [0, 1, 1]]
           circuit = HiddenLinearFunction(A)
           _generate_circuit_library_visualization(circuit)

    **Reference:**

    [1] S. Bravyi, D. Gosset, R. Koenig, Quantum Advantage with Shallow Circuits, 2017.
    `arXiv:1704.00690 <https://arxiv.org/abs/1704.00690>`_
    z1.3z:Use qiskit.circuit.library.hidden_linear_function instead.T)ÚsinceÚadditional_msgÚpendingÚadjacency_matrixúlist | np.ndarrayÚreturnÚNonec                óÆ   •— t          |¦  «        } t          ¦   «         j        |j        d|j        iŽ |                      |                     ¦   «         | j        ¦  «         dS )zåCreate new HLF circuit.

        Args:
            adjacency_matrix: a symmetric n-by-n list of 0-1 lists.
                n will be the number of qubits.

        Raises:
            CircuitError: If A is not symmetric.
        ÚnameN)Úhidden_linear_functionÚsuperÚ__init__Úqregsr   ÚappendÚto_gateÚqubits)Úselfr   ÚcircuitÚ	__class__s      €úc/granary/edev/quantum/lib/python3.11/site-packages/qiskit/circuit/library/hidden_linear_function.pyr   zHiddenLinearFunction.__init__H   sY   ø€ õ )Ð)9Ñ:Ô:ˆØ�‰ŒÔ˜'œ-Ð;¨g¬lÐ;Ð;Ð;Ø�Š�G—O’OÑ%Ô% t¤{Ñ3Ô3Ð3Ð3Ð3ó    )r   r   r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ú__classcell__)r   s   @r   r   r      sq   ø€ € € € € ð.ð .ð` €^ØØSØðñ ô ð
4ð 4ð 4ð 4ð 4ñô ð
4ð 4ð 4ð 4ð 4r   r   r   r   r   r   c                ój  — t          j        | ¦  «        } t          j        | |                      ¦   «         ¦  «        st	          d¦  «        ‚t          | ¦  «        }t          |d| › �¬¦  «        }|                     t          |¦  «        ¦  «         t          |¦  «        D ]<}t          |dz   |¦  «        D ]&}| |         |         r| 	                    ||¦  «         Œ'Œ=t          |¦  «        D ]%}| |         |         r| 
                    |¦  «         Œ&|                     t          |¦  «        ¦  «         |S )añ  Circuit to solve the hidden linear function problem.

    The 2D Hidden Linear Function problem is determined by a 2D adjacency
    matrix A, where only elements that are nearest-neighbor on a grid have
    non-zero entries. Each row/column corresponds to one binary variable
    :math:`x_i`.

    The hidden linear function problem is as follows:

    Consider the quadratic form

    .. math::

        q(x) = \sum_{i,j=1}^{n}{x_i x_j} ~(\mathrm{mod}~ 4)

    and restrict :math:`q(x)` onto the nullspace of A. This results in a linear
    function.

    .. math::

        2 \sum_{i=1}^{n}{z_i x_i} ~(\mathrm{mod}~ 4)  \forall  x \in \mathrm{Ker}(A)

    and the goal is to recover this linear function (equivalently a vector
    :math:`[z_0, ..., z_{n-1}]`). There can be multiple solutions.

    In [1] it is shown that the present circuit solves this problem
    on a quantum computer in constant depth, whereas any corresponding
    solution on a classical computer would require circuits that grow
    logarithmically with :math:`n`. Thus this circuit is an example
    of quantum advantage with shallow circuits.

    **Reference Circuit:**

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

       from qiskit.circuit.library import hidden_linear_function
       A = [[1, 1, 0], [1, 0, 1], [0, 1, 1]]
       circuit = hidden_linear_function(A)
       circuit.draw('mpl')

    Args:
        adjacency_matrix: a symmetric n-by-n list of 0-1 lists.
            n will be the number of qubits.

    Raises:
        CircuitError: If A is not symmetric.

    **Reference:**

    [1] S. Bravyi, D. Gosset, R. Koenig, Quantum Advantage with Shallow Circuits, 2017.
    `arXiv:1704.00690 <https://arxiv.org/abs/1704.00690>`_
    z'The adjacency matrix must be symmetric.zhlf: )r   é   )ÚnpÚasarrayÚallcloseÚ	transposer   Úlenr   ÚhÚrangeÚczÚs)r   Ú
num_qubitsr   ÚiÚjs        r   r   r   \   sF  € õn ”zÐ"2Ñ3Ô3ÐÝŒ;Ð'Ð)9×)CÒ)CÑ)EÔ)EÑFÔFð FÝÐDÑEÔEÐEåÐ%Ñ&Ô&€JÝ˜ZÐ.HÐ6FÐ.HÐ.HÐIÑIÔI€Gà‡I‚I�e�JÑÔÑ Ô Ð Ý�:ÑÔð !ð !ˆÝ�q˜1‘u˜jÑ)Ô)ð 	!ð 	!ˆAØ Ô" 1Ô%ð !Ø—
’
˜1˜aÑ Ô Ð øð	!õ �:ÑÔð ð ˆØ˜AÔ˜qÔ!ð 	Ø�IŠI�a‰LŒLˆLøØ‡I‚I�e�JÑÔÑ Ô Ð Ø€Nr   )r   r   r   r   )r!   Ú
__future__r   Únumpyr%   Úqiskit.circuit.quantumcircuitr   Úqiskit.circuit.exceptionsr   Úqiskit.utils.deprecationr   r   r   © r   r   ú<module>r7      s¸   ðð &Ð %à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø 8Ð 8Ð 8Ð 8Ð 8Ð 8Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3ðB4ð B4ð B4ð B4ð B4˜>ñ B4ô B4ð B4ðJGð Gð Gð Gð Gð Gr   