Primitives: Sampler vs Estimator

Intermediate Quantum Primitives
Created by Pavel · 11.03.2026 at 14:32 UTC

Modern quantum SDKs split what you ask into primitives. A sampler returns bitstring statistics; an estimator returns expectation values for chosen observables. That split is not cosmetic—it decides whether your classical post-processing sees histograms or scalars.

Pick the primitive that matches the loss: variational objectives written with $\mathbb{E}[O]$ belong with an estimator workflow, while generative checks often want full distributions. Course materials live in [1].


Sources

University approvals: 0
Tasks
Question 1

Which primitive is designed for expectation values?

Hint

Name suggests estimation of observables.

Question 2

Which primitive should you use to obtain outcome distribution over bitstrings?

Hint

Sampling outcomes.

Question 3

For a loss based on $\mathbb{E}[Z]$ across parameterized circuits, preferred primitive is:

Hint

Loss directly uses expectation values.

Question 4

Sampler outputs are closest to which data type?

Hint

Think counts/probabilities.

Question 5

In one phrase: Estimator is to observables as Sampler is to ____.

Hint

Outcome frequencies/probabilities.

Question 6

From 4096 sampler shots, bitstring '11' appears 1024 times. What is the estimated probability of '11'?

Hint

Frequency divided by total shots.

Question 7

You are training with loss $L = \sum_i w_i \cdot \mathbb{E}[O_i]$. Which primitive aligns most directly with this objective?

Hint

Loss is expressed in expectation values.

Question 8

When might Sampler be preferred over Estimator in analysis workflows?

Hint

Think histogram-level diagnostics.

Question 9

Implement shot_probability(count: int, shots: int) -> float returning count / shots. Raise ValueError if shots <= 0 or count < 0 or count > shots.

Expression-mode tests; stdlib only.

Hint

Validate inputs before dividing.

Starter code is prefilled; replace TODO blocks with your solution.
2 test cases will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Quantum Primitives
  • Difficulty: Intermediate
  • Completed: 0 users
Creator
Pavel
Pavel