Pennylane Function Exp

I have the following code block:
import pennylane as qml
def ansatz(params):
“”"VQC ansatz using single-qubits unitaries and entangling gates

    params : shape (`depth` + 1, `n_wires`, 3) tensor containing trainable parameters
j = np.random.randint(3)
k = np.random.randint(n_wires)

for i in range(n_wires):
    #qml.Rot(params[0, k, 0], params[0, k, 1], params[0, k, 2], wires=i)
    qml.exp(qml.PauliY(i), 0.5j*params[0, i, 1])
    qml.exp(qml.PauliZ(i), 0.5j*params[0, i, 2])

for s in pset:

Later I got
TypeError: must be real number, not ArrayBox

Does anyone notice any problem with calling
qml.exp(qml.PauliY(i), 0.5j*params[0, i, 1])


Hi @David_Liu, welcome to the Forum!

I’m currently unable to reproduce your error. I’m also puzzled about your code. Maybe this community demo on VQC can help you.

Some additional suggestions:

  • It’s important not to define ‘j’ as a number because ‘j’ is used as the imaginary unit in Python.
  • You haven’t defined pset anywhere so this raises an error
  • Make sure you are using the latest version of PennyLane (v0.26). You can check this by using qml.about()
  • If you want this to be a qnode (which I think you do) then remember that you will need a device and you will need to decorate your circuit with @qml.qnode(dev). I encourage you to watch this tutorial video to learn how to create your first quantum circuit.

Please feel free to clarify your question or let me know if this helps! :slightly_smiling_face:

Thank you much. Thank you much. (at least 20 characters)

No problem David! I’m glad you’re learning how to use PennyLane :smiley: