Quantum data encoding determines how many qubits your model needs, how difficult state preparation will be, and what your measurements actually tell you. This guide compares basis, amplitude, angle, and Hamiltonian encoding, then shows how to estimate resource costs and choose an approach for a real dataset.
Overview
Quantum data encoding maps classical information, such as feature vectors, labels, graph variables, or physical parameters, into a quantum state or quantum operation. The encoding is not a neutral preprocessing step: it becomes part of the algorithm's cost and can strongly affect trainability, noise sensitivity, and interpretability.
There is no universally best quantum feature map. A practical choice depends on four questions:
- How many classical features must be represented?
- Can the data be normalized, discretized, or reduced without losing useful information?
- Will the target algorithm benefit from amplitudes, phases, rotations, or a problem Hamiltonian?
- Can the resulting circuit run within the depth and connectivity limits of your simulator or hardware?
The table below gives a first-pass comparison. The circuit-depth and state-preparation columns are qualitative because implementation cost depends on the compiler, hardware connectivity, available native gates, and the structure of the data.
| Method | Typical qubit estimate | Preparation cost | Normalization | Good fit | Main caution |
|---|---|---|---|---|---|
| Basis | log2(number of discrete states), or roughly one qubit per binary variable | Low to moderate for structured bitstrings | Not required for bit values | Discrete search, binary constraints, combinatorial variables | Continuous values need discretization; indexing and bit order matter |
| Amplitude | ceil(log2(number of vector entries)) | Often high for arbitrary vectors | Required: vector must have unit Euclidean norm | Compact representation of dense vectors and state-based algorithms | Loading the data can dominate the algorithm |
| Angle | Usually one qubit per feature, with possible feature reuse | Usually low and predictable | Scaling to a rotation range is required | Variational circuits and near-term quantum machine learning | Qubit count grows with feature count |
| Hamiltonian | Set by physical or logical variables, not simply vector length | Depends on evolution, ansatz, and term decomposition | Parameters must use consistent units and scale | VQE, QAOA, simulation, and optimization problems | Encoding and objective Hamiltonian are closely coupled |
Basis and amplitude encoding describe a state directly. Angle encoding places values into gate parameters. Hamiltonian encoding represents a problem through operators whose expectation value, ground state, or time evolution is useful to the algorithm. That distinction is often more important than the label attached to a framework utility.
How to estimate
Use a repeatable resource estimate before writing a large experiment. Start with the raw feature count d, then record the following quantities:
- Logical qubits. For amplitude encoding, use n = ceil(log2(d)) and pad the vector to 2n entries. For angle encoding, begin with one qubit per simultaneously encoded feature. For basis encoding, distinguish between the number of binary variables and the number of discrete states being indexed.
- Encoding layers. Count how many times each feature is loaded. A single angle layer is cheaper than repeatedly re-uploading features between variational layers, but repeated encoding may improve expressivity in some models.
- State-preparation depth. Do not estimate amplitude encoding from qubit count alone. An arbitrary state generally requires a substantial gate sequence, while a sparse or structured state may admit a shorter preparation circuit.
- Measurement burden. A model that predicts an expectation value may need fewer measured observables than one that reconstructs many output probabilities. Include the number of observables and shots in the experiment plan.
- Noise and connectivity overhead. Two-qubit gates, routing operations, and repeated measurements can matter more than the nominal encoding formula on hardware.
A useful comparison metric is an encoding budget:
Encoding budget = qubits + weighted circuit depth + measurement cost.
The weights are project-specific. For a simulator, qubit count may dominate memory. For hardware, two-qubit depth and total execution time may deserve greater weight. Keep the assumptions visible so that a later comparison is still meaningful.
Inputs and assumptions
Before selecting a quantum feature map, create a small data profile:
- Shape: number of rows, features, categories, graph nodes, or physical variables.
- Domain: binary, integer, bounded continuous, periodic, sparse, or dense.
- Precision: how many bits or meaningful decimal places are needed after preprocessing.
- Distribution: whether features are concentrated near a narrow range or contain outliers.
- Target: classification, regression, optimization, sampling, simulation, or search.
- Execution environment: ideal statevector simulator, tensor-network simulator, noisy simulator, or hardware.
For angle encoding, scale each feature to a stated interval, such as [0, pi] or [-pi, pi], and apply the same rule to training and test data. Scaling is an assumption, not a cosmetic detail: it determines the rotation angles and therefore the circuit's sensitivity to feature changes.
For amplitude encoding, normalize each vector x using x' = x / ||x||. If the vector has fewer than 2n entries, pad it using a documented convention, commonly zeros. Compare the normalized vectors carefully: normalization removes overall magnitude, so magnitude may need to be supplied as a separate feature or retained in the classical post-processing path.
For basis encoding, define the bit ordering explicitly. A binary value such as 011 can be interpreted differently if the framework uses a different least-significant-bit convention. Test one small known input before running a full dataset.
For Hamiltonian encoding, write down the operator terms and coefficient units. In a QAOA or VQE workflow, separate the cost Hamiltonian from the mixer or ansatz. This makes it easier to determine whether a poor result comes from the data representation, the optimizer, or the circuit architecture.
Worked examples
Example 1: Ten continuous features
Suppose each record contains ten scaled continuous features and the goal is a variational classifier. A straightforward angle encoding uses ten qubits for one simultaneous feature layer. A PennyLane-style implementation is conceptually:
qml.AngleEmbedding(features, wires=range(10), rotation='Y')
The feature vector must contain ten values, each already mapped to the selected angle range. If the variational circuit has six layers and reloads all features in every layer, the data-loading operation occurs six times. That may improve model capacity, but it also increases depth and the number of noisy rotations.
Example 2: The same data with amplitude encoding
Ten values fit into the next power-of-two state dimension, 16, so the qubit estimate is ceil(log2(10)) = 4. Pad the vector with six zeros and normalize it. A framework utility may look like:
qml.AmplitudeEmbedding(padded_vector, wires=range(4), normalize=True)
This saves six logical qubits compared with the simple angle layout, but it does not automatically make the experiment cheaper. Arbitrary state preparation can require a deeper circuit than ten single-qubit rotations. Use amplitude encoding when the compact state representation is valuable and you have a credible preparation method, not only because the qubit formula is attractive.
Example 3: Binary optimization variables
Consider six yes-or-no decisions in a scheduling problem. Basis encoding can represent one candidate assignment as the six-qubit computational-basis state |b0b1...b5>. The initial state can be prepared with X gates on the positions containing 1. If the algorithm searches over assignments, however, the cost Hamiltonian and mixer usually provide the more important design choices. Encoding the six bits is inexpensive; defining and measuring the objective may be the dominant work.
Example 4: Hamiltonian representation
For a small Ising-style objective, represent the problem as terms such as hiZi and JijZiZj. The number of qubits follows the number of logical variables, while circuit depth depends on how the terms are grouped and implemented. This is not a replacement for basis or angle encoding in every workflow; it is a way to express the objective so that VQE or QAOA can optimize or sample it.
Validate every example in the selected SDK version. Framework names and argument conventions can change, so keep version information with the experiment and consult the relevant quantum SDK compatibility checklist. For simulator experiments, compare ideal and noisy results using the guidance in our simulator comparison.
When to recalculate
Revisit the encoding decision whenever the dataset, algorithm, or execution target changes. Recalculate qubits and depth after feature selection, dimensionality reduction, added precision, or a change from one-hot categories to integer indices. Recheck normalization when preprocessing changes, especially if a pipeline begins retaining feature magnitude.
Rebenchmark when moving from an ideal simulator to a noisy simulator or hardware. Connectivity, native gates, transpilation, measurement error, and mitigation can change the practical ranking of encodings. An encoding that is compact in qubits may still be a poor hardware choice if its preparation circuit is deep. See the quantum circuit benchmarking guide and error-mitigation workflow when comparing runs.
As a practical decision rule, start with angle encoding for a small, bounded continuous feature set and a variational prototype; use basis encoding for naturally binary or discrete variables; investigate amplitude encoding when state preparation is structured and qubit savings matter; and use Hamiltonian encoding when the problem is naturally an energy, constraint, or operator objective. Record the feature shape, scaling rule, qubit count, encoding depth, observables, shot budget, SDK version, and backend assumptions. That record turns a one-off feature-map experiment into a comparison you can recalculate after the next data or tooling change.