DeepPractise
DeepPractise

Expectation Values from Circuits

Track: Quantum Gates & Circuits · Difficulty: Beginner · Est: 15 min

Expectation Values from Circuits

Overview

When you run a circuit, you typically get raw measurement samples (bitstrings). But many quantum workflows care about a different quantity:

  • an expectation value like Z\langle Z \rangle or X\langle X \rangle.

This page addresses the practical problem:

  • how to turn raw samples into a meaningful numeric summary of the state.

Expectation values are central because they compress many samples into a single number that can be compared, optimized, or tracked across circuit variations.

Intuition

A measurement outcome is discrete (0 or 1). An expectation value is the average value of a quantity over many shots.

In classical probability, if you flip a biased coin and record 1 for heads and 0 for tails, then:

  • the average of many trials estimates the probability of heads.

In quantum measurement, we often want averages of observables like Z or X. These are “two-outcome measurements” with outcomes usually treated as +1+1 or 1-1.

So the workflow is:

  1. run the circuit many times,
  2. map each measured bit to a number (+1+1 or 1-1),
  3. average.

That average is the estimated expectation value.

Formal Description

Raw samples vs expectation values

  • Raw samples: a list of measured outcomes, like 0, 1, 0, 0, 1.
  • Expectation value: a single number summarizing the average of a measurement.

Computing Z\langle Z \rangle conceptually

For a single qubit, measuring in the computational basis corresponds to measuring the Z observable. We use the mapping:

  • outcome 0 corresponds to eigenvalue +1+1
  • outcome 1 corresponds to eigenvalue 1-1

If you take NN shots and obtain outcomes b1,,bNb_1,\dots,b_N with bi{0,1}b_i\in\{0,1\}, define

zi={+1if bi=01if bi=1z_i = \begin{cases} +1 & \text{if } b_i=0\\ -1 & \text{if } b_i=1 \end{cases}

Then the estimated expectation value is

Z^=1Ni=1Nzi.\widehat{\langle Z \rangle} = \frac{1}{N}\sum_{i=1}^{N} z_i.

Interpretation:

  • if you see mostly 0 outcomes, Z\langle Z \rangle is near +1,
  • if you see mostly 1 outcomes, Z\langle Z \rangle is near −1,
  • if outcomes are balanced, it is near 0.

Computing X\langle X \rangle conceptually

To measure X, you measure in the X basis. A practical way to do this using standard computational-basis measurement is:

  • apply H before measurement,
  • then measure in the computational basis.

This works because H maps the X basis to the Z basis. So:

  • “measure X” can be implemented as “apply H, then measure Z.”

Then you use the same +1/1+1/-1 mapping and average.

We’re not doing heavy operator math here. The key idea is: change basis, then sample, then average.

Worked Example

Suppose you run a single-qubit circuit and measure in the computational basis. You take N=8N=8 shots and get:

0, 0, 1, 0, 1, 0, 0, 0

Counts:

  • six 0 outcomes
  • two 1 outcomes

Convert to +1/1+1/-1 values:

  • each 0 contributes +1
  • each 1 contributes −1

So the sum is 6(+1)+2(1)=46\cdot(+1) + 2\cdot(-1) = 4. The average is

Z^=4/8=0.5.\widehat{\langle Z \rangle} = 4/8 = 0.5.

Interpretation:

  • the circuit produced a state biased toward 0|0\rangle in the Z basis,
  • but not perfectly; an expectation value of 0.5 is between +1 and 0.

Turtle Tip

Turtle Tip

To compute an expectation value from shots: map outcomes to numbers, then average. Histograms are great for intuition, but expectation values are often what algorithms actually consume.

Common Pitfalls

Common Pitfalls
  • Don’t average raw bits (0/1) when you mean Z\langle Z \rangle. Use the +1/1+1/-1 mapping.
  • Don’t forget basis: computational-basis measurement naturally gives Z information. To estimate X, you must effectively measure in the X basis (for example via a basis-change gate).

Quick Check

Quick Check
  1. If all shots return 0, what is Z\langle Z \rangle?
  2. Conceptually, how can you measure X using only computational-basis measurement?

What’s Next

Expectation values are one way quantum computation outputs a useful number. Next we discuss the broader picture: quantum computation is typically hybrid. After measurement, classical post-processing turns samples and expectation values into decisions, updates, and final results.