In PennyLane, the following circuit returns the expectation value of the
PauliZ observable on qubit (wire) 1:
def my_quantum_function(x, y): qml.RZ(x, wires=0) qml.CNOT(wires=[0, 1]) qml.RY(y, wires=1) return qml.expval(qml.PauliZ(1))
What if I instead wanted to return the expectation value of an operator $H = Z_1Z_2$ that acts on the first and the second qubit? How might I do that?
It is my understanding that qubits 1 and 2 are "correlated" because of the CNOT, so $\left\langle Z_1 Z_2 \right\rangle \neq \left\langle Z_1 \right\rangle \left\langle Z_2 \right\rangle$. Does this mean I have to define a custom operator? Or does
[qml.expval(qml.PauliZ(i)) for i in range(2)] achieve what I want? Thanks for any help.
Note: The above example function was taken from the PennyLane measurements documentation.