AI Launch Lab
Sign in FR Get updates

Quantum computing basics · Lesson 3 of 3

Measurement and shots

Measuring a qubit gives a single 0 or 1, and the superposition is gone. To learn the probabilities, a quantum computer runs the same program many times; each run is called a shot, and the results are counted.

We can simulate this with random numbers: draw a number between 0 and 1; if it is below p0, the result is 0, otherwise 1. With enough shots the share of zeros approaches p0, but never exactly: real results always carry this statistical noise, on top of the hardware’s own errors.

Using a fixed seed makes the random numbers repeatable, which helps when checking work.

Your turn

Write measure(state, shots, seed), which simulates that many shots and returns {0: count, 1: count}. Use rng = random.Random(seed) and rng.random().

Loading Python (about 12 MB, once)…

    Checks

    • ○ [1, 0] always measures 0
    • ○ counts add up to the shots
    • ○ an equal superposition gives about half zeros

    Output

    ← Previous lesson All courses