thanks @christina for your answer.
I think I have identified a strange behaviour.
I have the following function that allows me to return the expectation value for a list of commuting observables :
def mesure_obs(q_fun,nqbits,obs):
dev = qml.device("lightning.qubit", wires=range(nqbits))
@qml.qnode(dev)
def circuit_(*args):
q_fun(*args)
return [qml.expval(o) for o in obs]
return circuit_
Now I am seemingly contructing the same list of observables in two ways, first with the contruction we discussed previously :
obs = [qml.PauliZ(0),qml.PauliZ(1),qml.PauliZ(0)@qml.PauliZ(1)]
P = qml.PauliZ(2)
obs_cond = obs.copy() + [qml.prod(o , P) for o in obs] + [P]
obs_cond
>>>[PauliZ(wires=[0]),
>>>PauliZ(wires=[1]),
>>>PauliZ(wires=[0]) @ PauliZ(wires=[1]),
>>>PauliZ(wires=[0]) @ PauliZ(wires=[2]),
>>>PauliZ(wires=[1]) @ PauliZ(wires=[2]),
>>>(PauliZ(wires=[0]) @ PauliZ(wires=[1])) @ PauliZ(wires=[2]),
>>>PauliZ(wires=[2])]
and second by simply writing the result down directly, which results exaclty in the same thing when printing them :
obs_cond_bis = [qml.PauliZ(wires=[0]),
qml.PauliZ(wires=[1]),
qml.PauliZ(wires=[0]) @ qml.PauliZ(wires=[1]),
qml.PauliZ(wires=[0]) @ qml.PauliZ(wires=[2]),
qml.PauliZ(wires=[1]) @ qml.PauliZ(wires=[2]),
(qml.PauliZ(wires=[0]) @ qml.PauliZ(wires=[1])) @ qml.PauliZ(wires=[2]),
qml.PauliZ(wires=[2])]
Now trying to apply that a quantum function c (I dont think whats inside matter I have tried several and the result was the same everytime)
def c():
qml.Hadamard(wires=0)
qml.CNOT(wires=[0,1])
And the two seemingly identical lists behave differently, one returns the correct result while the other returns an error.
mesure_obs(c,3, obs_cond_bis)()
>>>tensor([0., 0., 1., 0., 0., 1., 1.], requires_grad=True)
mesure_obs(c,3, obs_cond)()
>>>TypeError: Expected a Pauli word Observable instance, instead got expval(PauliZ(wires=[0])) @ expval(PauliZ(wires=[2])).
But on the other hand doing the following works :
for o in obs_cond:
print(mesure_obs(c,3, [o])())
>>>[0.]
>>>[0.]
>>>[1.]
>>>[0.]
>>>[0.]
>>>[1.]
>>>[1.]
Am I misusing a functionality of pennylane ?