"QAOA for MaxCut" Tutorial gives error

Hello,

I found the notebook tutorial_qaoa_maxcut.ipynb returns an error for the following block of code.

pauli_z = [[1, 0], [0, -1]]
pauli_z_2 = np.kron(pauli_z, pauli_z, requires_grad=False)


@qml.qnode(dev)
def circuit(gammas, betas, edge=None, n_layers=1):
    # apply Hadamards to get the n qubit |+> state
    for wire in range(n_wires):
        qml.Hadamard(wires=wire)
    # p instances of unitary operators
    for i in range(n_layers):
        U_C(gammas[i])
        U_B(betas[i])
    if edge is None:
        # measurement phase
        return qml.sample()
    # during the optimization phase we are evaluating a term
    # in the objective using expval
    return qml.expval(qml.Hermitian(pauli_z_2, wires=edge))

The error returned is:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-9b14f55d55c2> in <module>
      1 pauli_z = [[1, 0], [0, -1]]
----> 2 pauli_z_2 = np.kron(pauli_z, pauli_z, requires_grad=False)
      3 
      4 
      5 @qml.qnode(dev)

<__array_function__ internals> in kron(*args, **kwargs)

TypeError: _kron_dispatcher() got an unexpected keyword argument 'requires_grad'

Hi @dancbeaulieu, it’s good to see you in the forum!

Are you sure that you’re importing numpy from PennyLane? You can import it using:

from pennylane import numpy as np

You need to use this version of numpy in order to be able to add “requires_grad” as needed.

Please let me know if this solves your problem!

I was using normal numpy, not Pennylane numpy. This was the problem.

I’m glad this fixed it!