liveBook · Manning

Probability theory

As explained in Building Quantum Software with Python

An outcome probability is the probability assigned to a particular measurement outcome or specified combination of outcomes.

Probability assigns a likelihood to each possible measurement outcome. In a quantum computation, the state carries one probability for every outcome; repeated executions produce outcome frequencies that approach those encoded probabilities. A single run still returns only one outcome, so probability describes expected distributions rather than a prediction of an individual measurement. section 1.4.2 section 3.4

Figure 1.8 The stages of a computation with a probabilistic bit. In this example, the initial probability that the outcome will be tails is 0.7. During the computation, the probability that the outcome will be tails is changed to 0.3. For example, each time the same computation is repeated (the coin is tossed), we get one outcome according to these encoded probabilities. If we perform 10 repetitions (tosses), we expect to see roughly 7 heads and 3 tails. The more tosses we perform, the closer we expect the distribution of outcomes to be to the encoded probabilities.
figure

Use the variable-bias coin as a developer-friendly model: computation changes an outcome distribution, while each measurement samples one result from it. section 1.4.2

Quantum probabilities are derived from amplitudes, not stored independently. Each outcome has a complex amplitude with magnitude and direction; its probability is the squared magnitude, p = |z|². Directions do not directly determine measurement frequency, but they matter when gates recombine amplitudes and thereby change later probabilities. Valid state probabilities add to 1. section 2.2.2 section 4.2.2

Represent and inspect outcome probabilities with a state table:

  • Map each list index to its corresponding outcome and store that outcome’s complex amplitude. section 3.1.3
  • Compute magnitude with abs(amplitude), then square it to obtain the probability. section 3.1.3
  • Display amplitude, direction, magnitude, and probability together when debugging or explaining a state. section 3.1.1

Sampling a single-qubit distribution

A state can assign probabilities 0.71651 to outcome 0 and 0.28349 to outcome 1. Sampling ten measurements may yield seven 0s and three 1s; sampling 1,000 times produces counts closer to the distribution. In Python, pass the outcomes and their squared amplitude magnitudes as weights to random.choices, then count the samples. section 3.4

For n qubits, there are 2ⁿ binary-string outcomes, each with a probability. A uniform distribution gives every outcome equal probability and can be prepared by applying a Hadamard gate to every qubit in a default three-qubit state. More generally, gates alter amplitudes in pairs, changing the resulting probability distribution. section 4.3.4 section 4.2.2

Probability can encode an answer rather than a single digital result. Analog encoding uses the probability of one outcome, or the combined probability of several outcomes; estimating it requires many repeated preparations and measurements, called shots. Optimization and search procedures instead aim to increase the probability of desired outcomes before measurement. section 1.5.3 section 2.5

Amplifying good outcomes with Grover iteration

Grover iteration tracks the combined measurement probability of outcomes selected by a predicate. Starting from a uniform state, repeated oracle-and-inversion steps increase the amplitude—and therefore probability—of good outcomes for an appropriate number of iterations. A classical implementation can sum abs(state[k])**2 over selected indices to assert the combined probability. section 6.1.4

How Building Quantum Software with Python covers it

How deep it goes
Derives probabilities from complex-amplitude magnitudes, implements state tables and sampling, and defers quantum postulates and amplitude-estimation details.
Examples
Uses variable-bias coins, single-qubit sampled counts, three-qubit uniform states, state tables, and Grover good-outcome amplification.
What it assumes
Assumes basic probabilities, binary strings, complex numbers, and trigonometry while requiring no quantum-mechanics or hardware-building background.
What you can do after
Apply it via Python state lists to calculate outcome weights, validate normalization, and sample simulated measurements.
How it connects
Relates probability to quantum states, amplitudes, measurement, quantum gates, uniform distributions, and Grover iteration.

Also explained in

Compare how 16 books explain probability theory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Quantum Software with Python. The section links point to the parts of the book it draws on.