Encoding Classical Data
Before a quantum computer can process classical data, that data must be encoded into a quantum state. This translation step — sometimes called a feature map or data embedding — is one of the most important design choices in quantum machine learning (QML). Different encodings trade off circuit depth, expressibility, and how much classical information fits into the state.
Why encoding matters
A classical dataset is a list of real-valued feature vectors. A quantum circuit operates on qubits, which are complex unit vectors in Hilbert space. Encoding bridges the two worlds by choosing a map
The encoded state is then processed by a parameterized quantum circuit (the variational ansatz) whose output is measured to produce a prediction. The encoding determines which transformations of the data are "easy" for the quantum circuit to implement and which kernel functions become efficiently computable.
Angle encoding
The simplest and most hardware-friendly strategy is angle encoding: assign one qubit per feature and rotate that qubit by an angle equal to the feature value. For a single feature and the rotation gate,
the encoded single-qubit state starting from is
For a -feature vector we use qubits and apply to qubit independently:
Because the qubits are not entangled, the full state is a product state. The Born rule then tells us that the probability of measuring qubit in state is
which varies smoothly with . This is directly useful: a downstream parameterized layer can learn to weight these probabilities differently for different classes.
Expressibility and limitations
Angle encoding with a single rotation per qubit traces a great circle on the Bloch sphere (all amplitudes remain real; no relative phase is introduced). Extending to two angles per qubit — for example — reaches any point on the Bloch sphere, but doubles the number of parameters and the circuit depth. The single-rotation variant used here sacrifices that extra expressibility in exchange for simplicity. Either way, angle encoding requires as many qubits as features. For large datasets (millions of features) that is impractical on near-term devices. Amplitude encoding addresses this by storing features in qubits, but at the cost of a deep state-preparation circuit. For the moderate-size problems that current quantum hardware can address, angle encoding is the standard starting point.
Try it
Encode the two-feature vector into a two-qubit state using angle encoding. Apply to qubit 0 and to qubit 1. The grader checks the full statevector.
After a correct run you should see qubit 0 in the state and qubit 1 in . The measurement probability for qubit 0 in is , and for qubit 1 it is .
Sign in on the full site to ask questions and join the discussion.