Curriculum / Quantum Foundations / Your First Qubit

Lesson 2 of 17Code challengeFree+100 XP

Your First Qubit

Create and measure your first quantum circuit.

Your First Qubit

What Is a Qubit, Physically?

Before we write any code, it is worth pausing to ask: what is a qubit, really? The answer is that a qubit is any quantum two-level system, any physical thing that can be in two distinguishable quantum states and cleanly put into a superposition of them. Different companies and labs have chosen wildly different pieces of hardware to play this role:

  • Superconducting qubits (used by IBM, Google, and Rigetti) are tiny loops of superconducting metal chilled to near absolute zero. The "states" are different patterns of microwave energy oscillating in the loop.
  • Trapped ion qubits (IonQ, Quantinuum) are single atoms suspended in a vacuum chamber by electromagnetic fields. The states are two long-lived electronic energy levels of the atom.
  • Photonic qubits (PsiQuantum, Xanadu) use individual particles of light. The states can be horizontal versus vertical polarization, or "photon in path A" versus "photon in path B."
  • Neutral atom qubits (QuEra, Atom Computing) trap individual atoms in grids of laser light.

Every one of these implementations is radically different from the others, but from a programmer's point of view they all look the same: a two-level quantum system you can prepare, manipulate, and measure. The abstraction layer you write code against hides the physics, the same way your Python scripts do not care whether the CPU underneath is Intel or ARM.

Dirac Notation: |0⟩ and |1⟩

Quantum mechanics uses a compact notation called Dirac notation (or "bra-ket" notation) to describe states. A ket looks like |something⟩ and represents a quantum state. The two computational basis states of a qubit are written:

  • |0⟩, the "zero" state (analogous to a classical 0)
  • |1⟩, the "one" state (analogous to a classical 1)

A general qubit state is a superposition |ψ⟩ = α|0⟩ + β|1⟩, where α and β are complex amplitudes satisfying |α|² + |β|² = 1. Whenever you create a new qubit, it starts in the definite state |0⟩, think of it as the computer handing you a freshly reset switch.

Starting state matters

Every qubit in every quantum circuit you write in this course begins in |0⟩. If you want it to start somewhere else, you have to apply a gate to move it there. There is no 'set to 1' instruction, you flip it with an X gate instead.

The QuantumCircuit Object

In code, you build quantum programs by creating a circuit object and adding operations to it. The constructor takes two arguments:

qc = QuantumCircuit(n, m)  # n qubits, m classical bits
  • n is the number of qubits. They are numbered 0 to n−1, and all of them start in |0⟩. The full starting state of an n-qubit register is |00...0⟩.
  • m is the number of classical bits. These are ordinary (non-quantum) bits that will hold the outcomes when you measure. You need classical bits because measurement results are classical information, a definite 0 or 1 that your program can branch on, print, or store.

For this lesson we want a single qubit and a single classical bit to store its measurement:

qc = QuantumCircuit(1, 1)

Reading a Circuit Diagram

Quantum circuits are drawn as horizontal lines (one per qubit), with time flowing left to right. Gates are boxes placed on the lines at the moment they are applied, and a measurement looks like a little meter symbol that routes its result onto a classical bit line. An empty circuit with a single measurement looks like this:

        ┌─┐
q_0: ───┤M├
        └╥┘
c_0: ════╩═

The M box is the measurement. Nothing happens to the qubit before it, so it is still in its initial state when it gets measured.

What Measurement Actually Does

Measurement is the moment the quantum world coughs up a classical answer. Before measurement, a qubit in state α|0⟩ + β|1⟩ carries information about both outcomes. The act of measuring is not a gentle "read out the value." It is violent: the superposition collapses to one of the basis states, and the one you get is chosen probabilistically according to the Born rule, |0⟩ with probability |α|², |1⟩ with probability |β|². After the measurement, the qubit is definitely in whichever state you observed, and any previous superposition is gone for good.

qc.measure(0, 0)  # Measure qubit 0, store the result in classical bit 0

Because quantum outcomes are random, we run the whole circuit many times and count how often each result appears. Each run is called a shot. With 1000 shots, we get a little histogram that estimates the true probabilities.

Your Challenge

Create a quantum circuit with 1 qubit and 1 classical bit. Measure the qubit and simulate it 1000 times. Since the qubit starts in |0⟩ and you apply no gates, every shot should produce the result "0".

Expected output: all measurements should be state "0".

Up next

Next: the Pauli-X (NOT) gate, the quantum equivalent of a classical NOT.

How this lesson works

A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.

Part of: Quantum Foundations

Learn the basics: qubits, gates, superposition, and measurement.

Take this lesson free

Create a free account and start this lesson in your browser. No credit card, no installation.