Lesson 1 of 15

Qubits

The Quantum Bit

A classical bit is either 0 or 1. A qubit (quantum bit) can be in a superposition of both states simultaneously — until it is measured.

We represent a qubit as a pair of amplitudes [alpha, eta] where:

  • alphaalpha is the amplitude for the 0angle|0 angle state
  • eta is the amplitude for the 1angle|1 angle state
  • |alpha|^2 + |eta|^2 = 1 (the probabilities must sum to 1)

The two basis states are:

StateNotationVector
Zero$0
angle$[1.0, 0.0]
One$1
angle$[0.0, 1.0]
def ket_zero():
    return [1.0, 0.0]  # |0⟩

def ket_one():
    return [0.0, 1.0]  # |1⟩

zero = ket_zero()
one = ket_one()
print(zero)    # [1.0, 0.0]
print(one)     # [0.0, 1.0]

The alpha (alphaalpha) amplitude is at index 0 and beta (eta) is at index 1.

Your Task

Implement ket_zero() and ket_one() that return the two computational basis states as two-element lists of floats. Then implement amplitude_zero(state) and amplitude_one(state) that extract the respective amplitudes.

Python runtime loading...
Loading...
Click "Run" to execute your code.