The Bottleneck: Data Encoding
In Quantum Machine Learning (QML), one of the most critical challenges is Data Encoding — the process of converting classical data into quantum states that a quantum computer can process.
This guide walks through interactive quantum encoding visualization and simulation of every major encoding strategy, so you can learn exactly how classical vectors map to qubit states in real time. Whether you're exploring amplitude encoding, angle encoding, basis encoding, or phase encoding, each method makes different trade-offs between circuit depth, qubit count, and expressibility.
If we have a classical dataset X of N-dimensional vectors, we need to map this data into the amplitudes or phases of a quantum system using a feature map.
Normalization and Information Loss: In classical machine learning, we often use min-max normalization. In quantum computing, however, the length of a quantum state vector must equal 1:
‖ψ‖ = √( ⟨ψ|ψ⟩ ) = 1
This means raw data must always be normalized, which can sometimes lead to a loss of relative magnitude information between different data points.
1. Basis Encoding
Basis Encoding is the most straightforward approach. It represents each classical bit as a separate qubit, mapping a classical bit-string directly into a computational basis state of a quantum system.
For example, the classical vector (5, 7, 0):
- 5 → 0101
- 7 → 0111
- 0 → 0000
The overall 12-bit string becomes a 12-qubit computational basis state:
|010101110000⟩
Resource Cost: Requires N × log₂(max(x)) qubits for an N-dimensional feature vector. It is extremely expensive in terms of qubit count, making it difficult to scale on near-term hardware.
2. Amplitude Encoding
Amplitude Encoding is exponentially more compact. It encodes a normalized classical N-dimensional data vector directly into the amplitudes of an n-qubit quantum system.
|ψ⟩ = (1/α) Σ x_i |i⟩
Where α is the normalization constant, and |i⟩ is the i-th computational basis state. Because n qubits can represent 2ⁿ basis states, we only need log₂(N) qubits.
Example: Encode (4, 8, 5)
- Normalization: α = √(4² + 8² + 5²) = √105
- Encoded state:
|ψ⟩ = (1/√105) * ( 4|00⟩ + 8|01⟩ + 5|10⟩ + 0|11⟩ )
The Catch: While Amplitude Encoding provides an exponential space advantage, preparing this state requires data loading circuits consisting of O(N) or O(2ⁿ) CNOT gates, eliminating the exponential speedup during data preparation.
3. Angle Encoding
Angle Encoding maps classical features directly to the rotation angles of individual qubits. We assign one qubit per feature, applying a rotation gate (usually Ry or Rx) to a qubit initialized in the |0⟩ state.
|x_k⟩ = Ry(x_k) |0⟩ = cos(x_k / 2)|0⟩ + sin(x_k / 2)|1⟩
If we encode N features into N qubits, the tensor product state looks like:
|x⟩ = ⨂ ( cos(x_k)|0⟩ + sin(x_k)|1⟩ )
Best Practice: Since angles are periodic, you should rescale your classical data into the range [0, 2π] or [-π, π] before encoding.
4. Phase Encoding
Phase Encoding is related to Angle Encoding, but instead of rotating the qubit's measurement probabilities (which happens around the X or Y axis), we rotate it purely along the Z-axis, encoding the data into the phase of the quantum state.
Data is mapped with a phase-rotation gate: P(φ) = e^(iφ/2) Rz(φ).
This requires two steps to be measurable:
- Apply a Hadamard Gate to place the qubit into superposition: H|0⟩ = |+⟩
- Apply the Phase Gate: P(φ)
The resulting state:
|x_k⟩ = (1/√2) * ( |0⟩ + e^(i * x_k)|1⟩ )
This method uses a circuit depth of 2 per qubit and maps features into the complex phase space.
5. Dense Angle Encoding
Dense Angle Encoding mixes Angle Encoding and Phase Encoding to achieve a slightly higher density: mapping two features into a single qubit.
For a single qubit, we map one feature x_j using the Y-axis rotation, and the other feature x_k using the Z-axis (Phase) rotation:
|ψ⟩ = Rz(x_k) Ry(x_j) |0⟩
This results in the state:
|ψ⟩ = cos(x_j / 2)|0⟩ + e^(i * x_k) sin(x_j / 2)|1⟩
By packing two features into one qubit, we can encode a 12-feature dataset into just 6 qubits.
Test Your Knowledge
Which encoding strategy requires the LEAST amount of qubits for a 1024-dimensional classical vector?
Why is Min-Max normalization problematic for quantum systems without adjustment?
In Dense Angle Encoding, how many features can be encoded per single qubit?
See It Live
You can visualize Amplitude, Angle, and Basis encodings in our interactive quantum encoding simulator. Watch the Bloch spheres react instantly to your classical data inputs — no setup required.