'function' object has no attribute 'PauliZ

Hie l am pretty new to pennylane and trying to implement some tutorials. I was trying the variational quantum circuit.

import pennylane as qml
from pennylane import numpy as np

dev = qml.device(‘default.qubit’, wires=1)

@qml.qnode(dev)
def circuit(params):
qml.RY(params[0], wires=0)
return qml.expval.PauliZ(0)

print(‘The expectation value {}’.format(circuit([0])))
print(‘The expectation value {}’.format(circuit([np.pi/3])))
print(‘The expectation value {}’.format(circuit([np.pi])))

I am getting this area:

AttributeError: ‘function’ object has no attribute ‘PauliZ’

I am not sure why this error is generated or the cause, can you please help. l was running it on colab.

Hi @munya,
In PennyLane, you have to specify the type of measurement to make (expectation value, variance, or sample) using the observable (in this case, PauliZ) as the argument.

Try replacing your return statement with return qml.expval(qml.PauliZ(0))

It worked like magic thank you, this was more like my baby steps in pennylane can you please refer me to some literature or useful tutorials if there are any?

Glad to hear you got it working.
All our tutorials, demos, and resources are located at pennylane.ai/qml