Qiskit Fundamentals

Lesson 2 of 8

Qubits and Superposition

A qubit doesn't have to be definitely 0 or definitely 1, it can be in a superposition, a mix of both, described by two numbers (amplitudes) whose squared magnitudes give the probability of measuring each outcome.

The Hadamard gate

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(1)
qc.h(0)  # put the qubit into an equal superposition of |0> and |1>

state = Statevector(qc)
print(state)
print(state.probabilities())  # [0.5, 0.5]
  • qc.h(0) applies the Hadamard gate, it takes a qubit starting at |0> and puts it into an equal superposition, neither definitely 0 nor definitely 1.
  • Statevector(qc) computes the circuit's exact quantum state mathematically, without simulating any randomness, useful for inspecting what a circuit does before introducing measurement noise.
  • state.probabilities() converts the state into the probability of measuring each outcome, here [0.5, 0.5]: a 50% chance of 0, 50% chance of 1.

Measurement collapses superposition

qc_measured = QuantumCircuit(1, 1)
qc_measured.h(0)
qc_measured.measure(0, 0)

# Once measured, the outcome is a single definite bit (0 or 1), chosen randomly
# according to the probabilities above, the superposition is gone.
print(qc_measured.draw())

Before measurement, a qubit in superposition genuinely holds both possibilities at once, that's not just "unknown to us", it's a real physical difference from a classical bit. The instant you measure it, that superposition collapses to one definite outcome, chosen randomly with the probabilities Statevector predicted. You cannot inspect a qubit's superposition without destroying it, this is the core reason quantum algorithms are designed so differently from classical ones.

TIP

Statevector is a teaching and debugging tool, it requires knowing the exact mathematical state, which is only possible on a simulator. Real quantum hardware can only ever give you measurement outcomes, never a peek at the superposition itself.

📝 Qubits and Superposition Quiz

Passing score: 70%
  1. 1.What does the Hadamard gate (h) do to a qubit starting in state |0>?

  2. 2.Measuring a qubit in superposition collapses it to one definite classical outcome.

  3. 3.state.____() converts a Statevector into the probability of measuring each possible outcome.