Problem with printing the result with the parameter naming: 'Variable' object is not subscriptable

I have encountered a problem in naming a parameter while printing the result as fellow, please help.

I have a tutorial quantum natural gradient that provide an example to name parameter like params[0], params[1]

qml.RZ(params[0], wires = 0)
qml.RZ(params[1], wires = 1)

I want to make use of the above naming pattern to measure a tensor-product observable

@qml.qnode(dev, interface=‘autograd’)

def circuit(params):
qml.RX(params[0],wires = 0)
qml.RY(params[1],wires = 0)
qml.CNOT(wires = [0, 1])
#my_circuit(wires = (1,0))
return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliZ(1))

But when I type the following code

print(circuit(np.pi / 2))

it generate an error:

‘Variable’ object is not subscriptable

I know the technique by following this tutorial

Could anyone please give me some hint how to correct it?

Hi @alanspace! The reason you are getting this error is that the QNode input parameters, np.pi/2, is a scalar. However, inside the QNode, you have params[0] and params[1], which indicates that the parameters should be a list or an array of size at least 2.

The following should work:

>>> params = [np.pi/2, 0.543]
>>> print(circuit(params))