Closed meenu-kri closed 2 years ago
Hi @meenu-kri, thanks for reporting this. If you used qml.PauliZ(0) in the circuit, as a gate, surely applying it twice would give the identity. However here we're doing a measurement and you shouldn't be able to make multiple measurements on the same wire. In any case this is something that we should look into. Thank you for reporting it!
This is another manifestation of the assumption that the tensor class does not represent / support representing matrix composition. The explicit source of this can be found in operations.py
, in the eigvals
method of the Tensor
class. Notice that the method doesn't perform any product calculation of the eigvals, it simply concatenates the eigvals of the pauli observables which act on different wires. For this reason the eigvals remain [1, -1].
We are currently working on a new class which will represent the product of two operators in general; such class will address these issues with a more permanent fix. I think the best fix for this would be to add a warning in the documentation or raise a warning telling the user that such behaviour exists and that it will be addressed by a new object to come.
Let me know if you have any other questions or clarifications 👍🏼
Hi @meenu-kri, in the last commits to master
we added the capability of using the new operator arithmetic classes as observables. Thus now you can do:
import pennylane as qml
dev = qml.device('default.qubit',shots=100,wires=3)
@qml.qnode(dev)
def my_circ():
qml.PauliX(0)
return qml.expval(qml.prod(qml.PauliZ(0), qml.PauliZ(0)))
print("Result of my_circ() is:", my_circ())
Result of my_circ() is: 1.0
Expected behavior
The expectation value of
qml.PauliZ(0)@qml.PauliZ(0)
should always be 1 as the square of PauliZ operator is identity.Actual behavior
The output of
qml.expval(qml.PauliZ(0)@qml.PauliZ(0))
(with as well as withoutshots
) for state|1>
is -1.Additional information
No response
Source code
Tracebacks
No response
System information
Existing GitHub issues