Quantum machine-learning results depend as much on how classical data enters a circuit as on the model that follows. This guide compares basis, angle, amplitude, and feature-map encoding, then gives you a repeatable way to estimate qubit count, circuit depth, loading cost, trainability, and baseline performance before committing to a quantum experiment.
Overview
Data encoding, also called quantum feature mapping, converts a classical feature vector into a quantum state or gate sequence. The encoding is not a neutral preprocessing step: it determines the number of qubits, the gates applied for every sample, the scale of the parameters, and often the difficulty of optimizing a variational circuit.
There is no universally best quantum machine-learning data encoding. Choose the method that matches the dataset and the experiment you can actually run. A small tabular dataset may work well with angle encoding because it is easy to inspect and requires relatively few qubits. Amplitude encoding can represent many values with fewer qubits, but state preparation may be expensive and requires normalized input. Basis encoding is useful when features are binary or categorical after a deliberate conversion, while richer feature maps add data-dependent interactions through repeated rotations and entangling gates.
| Method | Qubits for n features | Typical input | Main trade-off |
|---|---|---|---|
| Basis | Often n bits for direct representation | Binary or discretized data | Simple state preparation, but discretization can discard information |
| Angle | Usually n, or fewer with feature reuse | Scaled real-valued features | Clear and hardware-friendly, but qubit count grows with features |
| Amplitude | Ceiling(log2 n) for a length-n vector | Normalized real or complex vectors | Compact representation, but loading can dominate the circuit |
| Feature map | Depends on the chosen map and feature reuse | Scaled features with interactions | Can express richer structure while increasing depth and optimization cost |
These qubit counts are planning estimates, not guarantees. Padding, ancillary qubits, measurements, hardware connectivity, transpilation, and repeated encoding layers can all increase resource requirements.
How to estimate
Use the same dataset, split, metric, optimizer budget, and classical baseline for every encoding. Otherwise, a comparison may measure experimental setup rather than representation quality.
1. Count the effective features
Let n be the number of features presented to the quantum circuit after preprocessing. Do not use the raw column count if you have removed columns, reduced dimensions, grouped categories, or selected a subset. For angle encoding without feature reuse, the initial qubit estimate is q = n. If one qubit receives several features across sequential rotations, q can be smaller, but circuit depth increases.
For amplitude encoding, a vector of length n needs a state space with at least n amplitudes. The qubit estimate is q = ceil(log2(n)), so pad the vector to a power of two when necessary. This compact qubit count does not mean the data is cheap to load.
2. Estimate circuit work per sample
For a rough budget, record encoding layers, trainable layers, entangling gates, measurements, and shots. A useful first-pass estimate is:
total circuit evaluations = samples × training steps × parameter-shift evaluations × shots
The parameter-shift factor depends on the differentiation method and the number of independently differentiated parameters. Adjoint or backpropagation-based simulation may use a different cost model, and hardware execution may add queue or batching considerations. Treat this formula as a comparison tool rather than a billing calculation.
3. Score the experiment on more than accuracy
Track validation performance, training stability, wall-clock time, circuit depth, two-qubit gate count, shots, and the number of failed or noisy runs. A quantum model that matches a classical baseline with substantially greater experimental cost has not necessarily demonstrated an advantage. The baseline is part of the result, not an optional afterthought.
4. Test data loading separately
For amplitude encoding in particular, benchmark state preparation independently from the variational ansatz. If the state-preparation circuit is deeper than the trainable circuit, report that fact. On a simulator, direct state initialization may hide the cost of preparing the state on hardware. Use a realistic preparation method when resource estimates are the goal.
Inputs and assumptions
Basis encoding
Basis encoding maps a binary vector to a computational-basis state. For example, the vector [1, 0, 1] can correspond to a basis state such as |101>, subject to the SDK's bit-order convention. It is a natural choice for binary constraints and discrete search spaces. Real-valued features must be thresholded, binned, or otherwise discretized first. Record the rule, because changing a threshold changes the learning problem.
Angle encoding
Angle encoding maps feature values to rotation angles, commonly through gates such as RY(x), RX(x), or RZ(x). Scale features into a bounded interval appropriate for the selected rotation convention. Standardization alone does not guarantee a suitable angle range, so inspect the transformed minimum and maximum. If features have very different scales, a large feature can dominate the rotations and make optimization harder.
Amplitude encoding
Amplitude encoding places a normalized vector into the amplitudes of a quantum state. For a real vector x, use x / ||x||2, and pad to a power-of-two length when required. Handle the zero vector explicitly rather than dividing by zero. Preserve the normalization procedure in the experiment record; normalizing each sample and normalizing a whole dataset are different operations.
Amplitude encoding can reduce the logical qubit count, but arbitrary state preparation may require many operations. It is therefore best treated as a representation-and-loading trade-off, not an automatic compression advantage.
Feature maps
A feature map is a circuit design that encodes data, often with single-qubit rotations followed by entangling operations. Repeating the map can increase expressivity and depth. Some maps encode pairwise or higher-order interactions through data-dependent phases. Start with one encoding layer and a shallow ansatz, then add complexity only when an ablation shows a benefit.
When using PennyLane or Qiskit, pin the environment for a reproducible notebook and check the installed documentation for current operator names, differentiation interfaces, and feature-map constructors. APIs and backend capabilities change over time; a saved notebook should state its package versions and device configuration.
Worked examples
Example A: eight scaled tabular features
Suppose a binary classification dataset has eight numeric features after preprocessing. A direct angle-encoding experiment starts with eight qubits and one rotation per feature. Add a four-layer ansatz and estimate depth after transpilation rather than relying only on the logical circuit diagram. For a first comparison, use the same optimizer, training steps, shots, and train-validation split for a shallow angle map and a two-layer feature map.
An amplitude-encoding version needs a vector of length eight, so it also fits exactly into three logical qubits because 2^3 = 8. However, include the state-preparation circuit in the resource report. If state preparation creates substantially more gates or noise than the angle circuit, the lower qubit count may not produce a better end-to-end experiment.
Example B: three binary features
For three binary features, basis encoding offers a direct interpretation: each sample selects one of eight computational-basis states. Angle encoding also works, but it introduces a continuous rotation representation for values that are already binary. Compare them with a classical logistic-regression baseline and inspect whether the quantum circuit learns anything beyond the discrete lookup structure.
A repeatable notebook workflow
- Load one fixed dataset and create a documented train-validation-test split.
- Apply preprocessing using training data only, then transform the other splits.
- Create separate functions for basis, angle, amplitude, and feature-map encoding.
- Assert shape, range, normalization, qubit count, and bit-order assumptions.
- Run a classical baseline before training quantum models.
- Use the same seed policy, optimizer budget, metric, and stopping rule for each encoding.
- Record accuracy or the task-appropriate metric alongside depth, gates, shots, runtime, and parameter count.
- Repeat promising configurations with more than one seed and report variation rather than only the best run.
For implementation checks, pair this workflow with a circuit-testing process such as quantum program testing and regression checks. Use a circuit resource-estimation guide to separate logical resources from backend-specific overhead, and consult the hybrid quantum-classical training template when connecting a circuit to a larger optimization loop.
When to recalculate
Revisit the comparison whenever the effective feature count changes, a new preprocessing rule is introduced, the circuit depth or encoding repetition changes, or the model moves from a simulator to a hardware backend. Recalculate when you change shots, differentiation, batching, optimizer, or the number of training steps as well. These changes alter the cost and can alter the apparent ranking between encodings.
Refresh the notebook after major PennyLane, Qiskit, simulator, or backend changes, and review it on a regular maintenance cycle of roughly six months even when the dataset is unchanged. Verify constructor syntax, supported autodiff interfaces, state-preparation behavior, transpilation results, and measurement conventions against the installed versions. Do not compare old benchmark numbers with new ones unless the environment and protocol are recorded.
The practical decision rule is straightforward: begin with the simplest encoding that preserves the information your task needs, establish a classical baseline, and increase circuit expressivity only when the measurements justify it. Keep the preprocessing, resource estimates, and evaluation protocol in the notebook so the comparison can be rerun when the data, SDK, or backend changes.