Qml.expval function

Hello,

I have a question about qml.expval function.

When I run qml.expval function, the result of qml.expval is the same regardless of the value of the parameter shots.
qml.expval doesn’t seems to run a quantum circuit.
Does qml.expval use the Born rule to calculate expectation values?

Hi @snuffkin,

Welcome! And thanks for your question.

Indeed, qml.expval uses the Born rule to calculate expectation values. Note that are two different scenarios for how it does this, depending on the settings for the device you are using.

If you are running an “analytic” simulation (the default), it will compute the expectation value exactly (up to numerical precision) using standard linear algebra.

If you are running a simulator in a “non-analytic” manner (this can be changed by using the analytic keyword argument when creating a device), it will estimate the expectation value by sampling shots number of times from the final probability distribution of the measurement operator, and using these samples to estimate the expval.

If you are using hardware, it also (naturally) uses the samples to estimate the expectation value empirically.

1 Like

Thank you!

If I set analytic=False and execute, it seems to run a quantum circuit.

Thanks for your help and detailed explanations.