Quantum Data Encoding
Maya finally has a quantum circuit worth using. Now the real question: how does her actual molecule data get inside it? This module tours nine real ways to answer that — plus the one everyone eventually asks about and nobody has fully solved.
Module 7 ended with Maya sold on the theory. Now she's staring at a spreadsheet of real molecule data and a blank quantum circuit, with no idea how one becomes the other. That's this module.
Why Encoding Is Everything
This is the step most beginner tutorials rush past, and it's a mistake. Data encoding — sometimes called a quantum feature map or quantum embedding — is the bridge between Maya's spreadsheet and an actual quantum state. Get it wrong, and no amount of clever training afterward can fix it.
- It's not a technical footnote. Research consistently shows the encoding choice can matter as much as, or more than, the trainable circuit that follows it.
- Every encoding trades off the same four things: qubit count needed, circuit depth (which affects noise sensitivity), how practical it is to load real data, and how expressive the resulting feature space is.
- There's no single "best" encoding — only the right encoding for your data type and your hardware budget.
- This module tours nine real strategies, roughly in the order most QML courses and papers introduce them.
Basis Encoding
This is basis encoding — mapping an n-bit binary string directly onto n qubits' computational basis states. Nothing clever, nothing lossy. Try it yourself below.
def basis_encode(bits):
for i, b in enumerate(bits):
if b == 1:
qml.PauliX(wires=i)
- Exact, no information loss — the qubit state literally spells out the classical bit string.
- Qubit-hungry. A 64-bit feature vector costs 64 full qubits — zero compression.
- Best fit: genuinely discrete or binary data — yes/no flags, one-hot categories — not continuous measurements like bond angles.
Angle Encoding
Angle encoding maps a classical feature x onto a rotation gate — typically Ry(x) — applied to a qubit starting at |0⟩. Drag the slider and watch the qubit's state vector actually turn.
- One feature per qubit. Simple, shallow circuits — friendly to today's noisy hardware.
- Limitation: only uses a single rotation axis of each qubit's available state space — far less "data-dense" than amplitude encoding.
- The most common first encoding choice in real QML experiments, precisely because it's this easy to implement.
Dense Angle Encoding
Dense angle encoding extends standard angle encoding by applying two rotation gates per qubit, e.g. Ry(x₁) then Rz(x₂). Same feature count, half the qubits.
- Roughly halves qubit count compared to standard angle encoding, for the same amount of data.
- Trade-off: a slightly deeper circuit per qubit — two gates instead of one.
- A practical middle ground between angle encoding's simplicity and amplitude encoding's extreme compactness (next chapter).
Amplitude Encoding
Play with the four sliders below — they represent a length-4 classical vector. Watch it auto-normalize into a valid quantum state spread across 2 qubits.
- Extraordinary compression: 1,024 numbers fit into just 10 qubits.
- The catch: preparing an arbitrary amplitude-encoded state generally needs a circuit whose depth also scales with the vector's size — and reading the data back out is limited by measurement statistics. The "free lunch" isn't entirely free.
- Still one of the most-cited encoding strategies in QML papers, precisely because of this theoretical compactness.
IQP Encoding
Instantaneous Quantum Polynomial (IQP) encoding applies a layer of Hadamards, then diagonal phase gates whose angles depend on products of features — capturing feature interactions directly in the encoding step, not just raw values.
- Captures interactions: angle encoding only sees x₁, x₂, x₃... individually — IQP also sees x₁·x₂, x₁·x₃, and so on, encoded as phase.
- Believed classically hard to simulate (Shepherd–Bremner) — the theoretical basis of an early real-hardware quantum-kernel classification demo.
- The honest caveat: "hard to simulate classically" doesn't automatically mean "better real-world ML performance" — remember Module 7's hype-o-meter.
- Popular in quantum kernel methods, which you previewed in Module 6 and will use directly in Module 9.
Hamiltonian Encoding
Hamiltonian encoding embeds data into the coefficients of a Hamiltonian H(x), then evolves the state under e^(−iH(x)t). Drag the slider — it plays the role of a coupling strength pulled straight from data — and watch the state precess faster or slower.
- Natural fit for genuinely physical data — molecular Hamiltonians, interaction strengths, coupling constants — exactly Maya's kind of chemistry data.
- Connects directly to quantum simulation and VQE, which return in Module 9's algorithm list and Module 11's advanced applications.
- More hardware-demanding: accurately simulating time evolution typically needs deeper circuits (via Trotterization).
QSample Encoding
Drag the bars on the left to shape a classical probability distribution. Watch the right side — the "matching" quantum state — mirror it automatically, because that's exactly what QSample encoding guarantees.
- Goal: prepare a state where measuring it reproduces a target classical distribution — the squared amplitude of each basis state matches its classical probability.
- Related to state-preparation routines like the Grover–Rudolph method.
- Useful whenever an algorithm needs to "start from" a real distribution — risk models in finance, population distributions in epidemiology-style data.
- Not the same as amplitude encoding: amplitude encoding cares about raw vector values; QSample encoding specifically targets reproducing a probability distribution on measurement.
QRAM — The Loading Problem
QRAM (Quantum Random Access Memory) is a proposed architecture for loading classical data into superposition efficiently — addressing multiple memory cells at once and retrieving their contents in superposition. Toggle the address bits below to see how a QRAM tree is supposed to route to one memory cell.
- Many "quantum advantage" claims for QML — including some readings of amplitude encoding's compactness — quietly assume fast, efficient QRAM access as a prerequisite. That assumption is genuinely contested.
- The proposed "bucket-brigade" architecture requires physical components that scale with dataset size, and remains largely theoretical at useful scale on real hardware today.
- This is one of the field's honest open problems — not a solved supporting technology.
Data Re-uploading
Drag the layer slider — each added layer is another pass of "encode, then train" stitched into the same small circuit. Watch the function it can represent get visibly richer.
- Not one pass — several. Data-encoding gates and trainable parameterized gates alternate, repeated across layers in a single circuit.
- Surprising theoretical result (Schuld et al.): a single-qubit circuit with enough re-uploading layers can approximate any bounded function — each layer effectively adds another frequency term to a Fourier-series-like expansion.
- Practical payoff: boosts a circuit's expressivity without needing more qubits — genuinely valuable on today's small NISQ devices.
- Ties the whole module together: any encoding from this chapter list — angle, amplitude, IQP — can be re-uploaded for extra expressive power.
Module 8 Assessment
Ten synthesis questions, one per chapter. Your result adapts to your whole session — chapters where you struggled above get flagged for review here, regardless of how this final round goes.