DeepPractise
DeepPractise

Cost Functions & Expectation Values

Track: Variational & NISQ Algorithms · Difficulty: Intermediate · Est: 13 min

Cost Functions & Expectation Values

Overview

Variational algorithms need a way to decide whether a parameter choice is “good.” That’s the role of a cost function.

In many variational quantum settings, the cost is built from expectation values estimated by running the circuit many times.

This matters in the NISQ era because measurement is expensive:

  • each evaluation of the cost requires shots
  • shot noise creates uncertainty
  • noise in gates and readout biases the estimate

So variational algorithms are constrained not only by depth, but also by how costly it is to measure their objective.

Intuition

Cost functions are scores

A cost function is a single number summarizing performance. Lower (or higher) is better.

Examples of what a cost might represent (high-level only):

  • how well a state matches a target property
  • how large an error is
  • how “stable” a constraint is

Expectation values as objectives

Quantum measurements are random. So you usually can’t get a stable score from one shot. Instead, you estimate an average outcome over many shots.

That average is an expectation value.

Measurement cost and shot noise

If you run SS shots, your estimate has statistical uncertainty. More shots generally means:

  • less randomness in the estimate
  • more time/cost

This creates a real tradeoff:

  • cheap estimates are noisy
  • accurate estimates are expensive

Classical optimization loop

Because the cost is noisy, the optimizer is operating in a noisy environment. That affects:

  • step sizes
  • convergence
  • the number of iterations needed

Formal Description

We define expectation values and how they are estimated.

Expectation value (operational definition)

Suppose a circuit prepares a state that depends on parameters θ\theta. You measure an observable OO (a quantity you can estimate from measurement outcomes).

The ideal expectation value is conceptually:

  • “the average value you would get if you repeated the experiment many times”

In practice you estimate it by sampling:

  1. run the circuit
  2. measure
  3. repeat SS times
  4. average the measured values

That average is your estimate of O\langle O \rangle.

Cost as a function of expectation values

Many costs look like:

  • C(θ)C(\theta) is built from one or more expectation values

Even if you don’t write explicit formulas, the structure is:

  • parameters θ\theta → quantum circuit → measurement samples → estimated expectation(s) → cost

Why this is NISQ-relevant

NISQ constraints show up directly:

  • sampling makes costs noisy
  • device noise biases the estimate
  • deeper circuits increase both noise and sampling requirements

So “evaluate the cost” is not a cheap operation. It is a full experimental workload.

Worked Example

You want to minimize a cost that depends on the probability of measuring 1 on a qubit.

Suppose you run S=100S=100 shots and observe 37 ones. Then your estimated probability is:

  • p^=0.37\hat{p}=0.37

If you instead run S=10,000S=10{,}000 shots and observe 3,720 ones:

  • p^=0.372\hat{p}=0.372

The second estimate is more stable but much more expensive.

This illustrates a core variational reality:

  • optimization is limited by how quickly you can estimate costs reliably

Turtle Tip

Turtle Tip

In variational algorithms, “compute the cost” really means “run many circuits and average noisy outcomes.” The cost is a measured quantity, not a free calculation.

Common Pitfalls

Common Pitfalls
  • Forgetting that shot noise is part of the optimization problem. The optimizer is driven by noisy estimates.
  • Using too few shots and overreacting to randomness, causing unstable updates.
  • Ignoring measurement cost when designing objectives (too many terms can make evaluation prohibitively expensive).

Quick Check

Quick Check
  1. Why do variational algorithms often use expectation values instead of single-shot outcomes?
  2. What tradeoff does shot count create?
  3. Why can a noisy cost function make optimization harder?

What’s Next

Next we discuss why training can be difficult even when everything is well-defined: local minima, shot noise, hardware noise, and optimizer sensitivity. These challenges explain why variational methods can be practical but also frustrating.