Quantum computing and AIMiddleLesson 3037 min read

Bits and qubits

A bit is 0 or 1. A qubit is described by two numbers called amplitudes, but when you look at it you still get only 0 or 1. Learn what that really means.

Lesson in motion

In 60 seconds

Bits and qubits

A bit is 0 or 1. A qubit is described by two numbers called amplitudes, but when you look at it you still get only 0 or 1. Learn what that really means.

1/4
In simple words
A light switch is either off or on. That is a bit: 0 or 1. A qubit is more like a spinning coin before it lands. While it spins, we describe it with numbers that say how likely heads or tails is. When it lands, you see only heads or tails. The comparison is not perfect, but it is a good start: a qubit has a richer state than a bit, and looking at it gives only one plain answer.
Every normal computer, from your phone to a UPI server, works with bits. A bit is always exactly 0 or exactly 1. Eight bits make a byte. With 3 bits you can store one of 8 patterns: 000, 001, 010, 011, 100, 101, 110, 111. With n bits there are 2n patterns, but the bits hold only one of them at a time.

What a qubit is

A qubit (quantum bit) is a tiny physical system with two clear states that we call |0⟩ and |1⟩. The strange-looking brackets are just labels, read as "ket 0" and "ket 1". Engineers build qubits in several ways, for example tiny superconducting circuits kept very cold, single charged atoms (ions) held by electric fields, or particles of light.
A qubit's state is written with two numbers, called amplitudes:
A qubit statetext
state = a|0⟩ + b|1⟩

a = amplitude for 0
b = amplitude for 1
rule: |a|² + |b|² = 1
The rule at the bottom is important. When you measure the qubit, you get 0 with probability |a|² and 1 with probability |b|². The two probabilities must add up to 1. For now you can think of a and b as ordinary numbers, possibly negative. In general they can also be complex numbers; the next lesson shows that lightly.
BitQubit
What it can be0 or 1Any state a|0⟩ + b|1⟩ with |a|² + |b|² = 1
What you read out0 or 1, exactly as stored0 or 1, at random, with chances |a|² and |b|²
Can you copy it?Yes, as often as you likeNo: an unknown qubit state cannot be copied (the no-cloning theorem)
Numbers needed to describe n of themn bits2ⁿ amplitudes (for a general state of n qubits)

Clearing up a common myth

Myth
  • A qubit is 0 and 1 at the same time, so it holds twice the information
  • A quantum computer tries every answer at once and picks the best
  • Qubits are magic, and nobody understands them
What is actually true
  • A qubit has a state with two amplitudes, but one measurement gives you just one bit
  • Measuring gives one random outcome; a good quantum algorithm uses interference to make the right answers likely
  • Quantum mechanics is a precise, well-tested theory with clear maths, the same maths you will use in this track
So where does the power come from? From two things you will meet soon. First, the amplitudes of many qubits can interfere: like waves in water, they can add up or cancel out. Second, qubits can be entangled, so that n qubits together need 2ⁿ amplitudes to describe. Clever algorithms steer the interference so that wrong answers cancel and right answers get stronger. This only works for some problems.
Note
Measuring changes the qubit. After you measure and get 1, the qubit is now in state |1⟩. Measure again straight away and you get 1 again. The original amplitudes are gone. This is why you cannot "peek" at a qubit to read its amplitudes.

Checking a state

Python: is this a valid qubit state?python
import numpy as np

states = {
    "|0>":              [1.0, 0.0],
    "equal mix":        [1 / np.sqrt(2), 1 / np.sqrt(2)],
    "60/40 style":      [0.6, 0.8],
    "not valid":        [0.5, 0.5],
}

for name, (a, b) in states.items():
    total = abs(a) ** 2 + abs(b) ** 2
    print(f"{name:12s} a={a:.3f} b={b:.3f}  |a|^2+|b|^2 = {total:.3f}")
Run it. The last one fails the rule: 0.5² + 0.5² = 0.5, not 1. It is not a real qubit state. The "60/40 style" state gives 0 with probability 0.36 and 1 with probability 0.64.
Try this. Find numbers a and b so that the qubit gives 0 with probability 0.25. (Hint: a = 0.5. What must b be?)

Watch and read more

Lab

Two small Python functions: one that lists all classical bit patterns, and one that checks if two amplitudes form a valid qubit state.

~20 min

The problem

Run this in the browser, or with Python 3 and numpy.

  1. Finish bit_patterns(n) so it returns a list of every n-bit string, for example bit_patterns(2) gives ["00", "01", "10", "11"]. (Hint: itertools.product("01", repeat=n).)
  2. Finish is_valid_state(a, b) so it returns True only when |a|² + |b|² is 1. Allow a tiny rounding error, for example 1e-9.
  3. Print how many patterns there are for n = 1 to 10. Write one sentence: a register of 10 bits holds how many of these patterns at once?

Practice lab

Edit the code and run it. Python runs in your browser — nothing is sent to our server.

Output

No output. Add print(...) to see values.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1If a qubit has two amplitudes that can be any valid numbers, why can't we store a whole book in one qubit?Reveal

Because we can never read the amplitudes directly. One measurement gives one bit, and it destroys the old state. Even with many copies of a state you would need many measurements to estimate the amplitudes roughly, and the no-cloning theorem says you cannot make copies of an unknown state. A known result (Holevo's bound) says one qubit can carry at most one classical bit of readable information in this setting.

Q2A friend says: "Two amplitudes means a qubit is 50% zero and 50% one." When is that true, and when is it wrong?Reveal

It is only true for states where |a|² = |b|² = 0.5, such as a = b = 1/√2. Other states give other chances, like 36% and 64%. And even for equal chances, the signs (and phases) of the amplitudes matter: 1/√2 and −1/√2 give the same chances when measured, but behave differently when gates are applied, because they interfere differently.

Please sign in to continue.

Questions people ask

Is a qubit just a bit we are unsure about?

No. A bit you are unsure about is really 0 or 1, and you just do not know which. A qubit's amplitudes can interfere with each other, and experiments show effects that no "hidden 0 or 1" explanation can produce in general. Lesson 3 comes back to this.

Why do qubits need to be kept so cold or so isolated?

Any tiny disturbance from the outside world, such as heat, stray light or vibration, can disturb the amplitudes. This is called noise or decoherence. Cold and isolation reduce it, but no one has removed it fully. The last lesson covers this.

Can I have a qubit at home?

Not a real one, but you can use a simulator on your own computer, which is what this track does. Some organisations also let students run small programs on real quantum hardware over the internet; check what is currently offered.

What does the |0⟩ notation mean?

It is called Dirac or "bra-ket" notation. |0⟩ is just a name for the state that always gives 0 when measured. In code we write it as the list [1, 0], and |1⟩ as [0, 1].

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress