# Qml.expval function

**URL:** <https://discuss.pennylane.ai/t/qml-expval-function/483>\
**Category:** PennyLane Help\
**Created:** [July 19, 2020, 9:20pm UTC](https://discuss.pennylane.ai/t/qml-expval-function/483 "2020-07-19T21:20:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snuffkin](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/snuffkin/32/242_2.png) [@snuffkin](https://discuss.pennylane.ai/u/snuffkin)\
**Post date:** [July 19, 2020, 9:20pm UTC](https://discuss.pennylane.ai/t/qml-expval-function/483/1 "2020-07-19T21:20:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![nathan](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/nathan/32/85_2.png) [@nathan](https://discuss.pennylane.ai/u/nathan)\
**Post date:** [July 19, 2020, 9:39pm UTC](https://discuss.pennylane.ai/t/qml-expval-function/483/2 "2020-07-19T21:39:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![snuffkin](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/snuffkin/32/242_2.png) [@snuffkin](https://discuss.pennylane.ai/u/snuffkin)\
**Post date:** [July 19, 2020, 9:47pm UTC](https://discuss.pennylane.ai/t/qml-expval-function/483/3 "2020-07-19T21:47:59Z")

</div>

Thank you!

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

Thanks for your help and detailed explanations.
