TopicIntermediateEstablished concept

Data Encoding

Data Encoding

Data encodingData Encoding: Data encoding is the conversion of a classical vector x into a quantum state ψ(x)⟩ by an x-dependent circuit; its best-known forms are basis encoding, amplitude encoding… is the conversion of a classical vector $x$ into a quantum stateQuantum State: The pure quantum state of an n-qubit system is a unit vector in the Hilbert space ℂ^2^n, defined up to a global phase, and it determines the probabilities of all possibl… $|\psi(x)\rangle$ by an $x$-dependent circuit; its best-known forms are basis encodingBasis Encoding: Basis encoding converts a classical bitstring directly into a computational basis state: a bit equal to 1 corresponds to applying X to the corresponding qubit., amplitude encodingAmplitude Encoding: Amplitude encoding places a normalised vector of 2ⁿ elements in the amplitudes of n qubits, compressing the data exponentially in the number of qubits, but its general p… and angle encodingAngle Encoding: Angle encoding sets each real feature as the angle of a single-qubit rotation, such as RY(xᵢ), producing a separable product state with constant depth that needs one qub….

Before a quantum model can process classical data, the data must be encoded in a quantum state. This is called data encoding or loading, and it is an essential part of the model rather than a mere preliminary step, because it determines the space of functions the model can represent.

Basis encoding: a bit string $b$ is represented by the basis state $|b\rangle$. It is simple and suits binary data, but it needs one qubitQubit: The qubit is the unit of quantum information: a two-level system whose state is a unit vector α0⟩+β1⟩ in ℂ^2. per bit.

Amplitude encoding: a vector $x\in\mathbb{R}^N$ is normalised and loaded into the amplitudes: $|\psi(x)\rangle=\tfrac{1}{\|x\|}\sum_{i}x_i|i\rangle$. It needs only $\lceil\log_2N\rceil$ qubits, which is tempting, but preparing such a general state requires, in the general case, a circuit with a number of gates of order $N$, so the exponential saving in qubits may be lost to the cost of preparation. This is one of the most important practical limits of many proposed algorithms.

Angle encoding: each feature is encoded in a rotation angle on a separate qubit, such as $$R_Y(x_i)|0\rangle=\cos\tfrac{x_i}{2}|0\rangle+\sin\tfrac{x_i}{2}|1\rangle.$$ It needs one qubit per feature and a constant-depth circuit, so it suits NISQ devices. Because rotations are periodic, it is advisable to scale the features to a range such as $[0,\pi]$, as the lab does in the Iris experiment, so that different values do not coincide.

More complex feature maps, such as the ZZ map, use entangling gates whose phase depends on the product of two features, introducing non-linear interactions between features. The encoding can also be repeated between trainable layers (data re-uploading), increasing the frequencies the model can represent.

A general rule: the resulting quantum model is a function of $x$ largely determined by the encoding map. If a feature is encoded with a single Pauli rotation, any expectation value is a first-degree trigonometric polynomial in that feature, i.e. of the form $a+b\cos x+c\sin x$, whatever trainable circuit follows. So choosing the encoding is a design decision as important as choosing the architecture of a classical neural network.

In the lab you can compare angle encoding with the ZZ map on the same datasets to see the effect of encoding directly.

x = (x₀, x₁, x₂)|0⟩RY(x0)|0⟩RY(x1)|0⟩RY(x2)|φ(x)⟩
Encoding a data vector x in qubit rotation angles

Mathematical formulation

$$|\psi(x)\rangle=\bigotimes_{i}R_Y(x_i)|0\rangle,\qquad |\psi_{\text{amp}}(x)\rangle=\frac{1}{\|x\|}\sum_i x_i|i\rangle$$

Worked example

  1. Amplitude encoding of the vector $x=(3,4)$: $\|x\|=5$, so $|\psi\rangle=0.6|0\rangle+0.8|1\rangle$, and the measurement probabilities are $0.36$ and $0.64$. One qubit is enough for a two-dimensional vector.
  1. Angle encoding of the feature $x=\pi/2$: $R_Y(\pi/2)|0\rangle=\cos\tfrac{\pi}{4}|0\rangle+\sin\tfrac{\pi}{4}|1\rangle=|+\rangle$, so $\langle Z\rangle=\cos x=0$.
  1. For a two-feature sample $(x_1,x_2)=(0,\pi)$ with angle encoding: $R_Y(\pi)|0\rangle=|1\rangle$ for qubit 1 and $|0\rangle$ for qubit 0, so the state is $|10\rangle$ in the order $q_1q_0$.

Try it yourself: Data Encoding Lab

Loading the simulator…

The full experiment page

Test your understanding

The quiz needs JavaScript.

Related topics

References

  1. Maria Schuld; Francesco Petruccione (2021). Machine Learning with Quantum Computers. Springer (Quantum Science and Technology) doi:10.1007/978-3-030-83098-4
  2. Xanadu (2025). What is quantum machine learning?. PennyLane pennylane.ai
  3. IBM Quantum (2025). Quantum Machine Learning (course). IBM Quantum Learning quantum.cloud.ibm.com