Error on trying to do the exercise PF 3.3

I had an error when trying to do the PF 3.3. The exercise asks: For the same Bell circuit as before, build a 2-qubit device and return the probabilities for the tensor observable <Z_1 tensor_product z_2>. Don’t use shots, we’ll want the analytic value instead.

my attempt


dev = qml.device('default.qubit', wires = 2) # Define a two-qubit device here

@qml.qnode(dev)
def circuit():
    """
    This quantum function implements a Bell state and
    should return the probabilities for the PauliZ 
    observable on both qubits, using a single measurement
    """
    qml.H(wires=0)
    qml.CNOT(wires=[0,1])
    return qml.expval(qml.Z(wires = 0) @ qml.Z(wires = 1)) # Add your measurement here

print(circuit())

it returns 0.9999999999999998. I saw that it should return 1. It’s happening a round-off error here because it is saying that the measurement isn’t right.

Hi @mickpires, welcome to the forum!
The question is asking you to return the probabilities and you are returning the expectation value. It is not a rounding error, it is indeed the measurement being incorrect.
See the table in the theory of that Codebook section, you have counts, sample, expectation value, probability.
Let me know if this worked for you.

1 Like

Thanks. I didn’t pay attention hehe