Quantum data encoding determines how many qubits, gates, measurements, and optimization steps your experiment needs. This guide compares basis, amplitude, angle, and feature-map encoding, then gives a repeatable worksheet and code patterns for choosing an approach that matches your data, circuit budget, and target hardware.
Overview
A classical dataset cannot be passed directly into a quantum circuit. Before a circuit can process it, a classical vector, category, image, graph, or time series must be mapped to qubit states or gate parameters. That mapping is called quantum data encoding, quantum feature encoding, or, in many machine-learning workflows, a feature map.
There is no universally best encoding. The right choice depends on the information you need to preserve, the number of available qubits, the cost of state preparation, the noise of the target device, and the optimization behavior of the complete algorithm. A compact encoding can be impractical if its preparation circuit is too deep; a hardware-friendly encoding can be wasteful if it requires one qubit per feature.
| Method | Typical qubit cost | Depth and practicality | Normalization | Best starting use |
|---|---|---|---|---|
| Basis encoding | Often proportional to the number of binary values; categorical domains may require additional representation | Usually shallow to prepare, especially for computational-basis states | Not required for bit strings | Binary, discrete, or constraint data |
| Amplitude encoding | For a vector of length 2n, n qubits can represent the amplitudes | State preparation may be deep and data-dependent; hardware sensitivity can be significant | Required: the vector must be scaled to unit norm | Experiments where qubit count is the main constraint and state preparation is acceptable |
| Angle encoding | Often one or several features per qubit, depending on rotations and repetitions | Generally simple and hardware-friendly; depth grows with feature layers | Not required, but feature scaling is important | Continuous, low- to medium-dimensional features |
| Feature-map encoding | Depends on the chosen rotation, entangling, and repetition pattern | Ranges from shallow local rotations to deep entangling circuits | Depends on the underlying map | Quantum machine-learning models that need interactions between features |
Feature-map encoding is best understood as a circuit design family rather than one mathematically fixed encoding. An angle-encoding layer may be the first part of a feature map, followed by entanglers, nonlinear transformations, or repeated data re-uploading. When comparing methods, separate the data injection step from the trainable ansatz that follows it.
How to estimate
Estimate an encoding before implementing the full algorithm. The aim is not to predict every gate exactly; it is to identify whether the proposed representation fits the available qubits and an acceptable circuit budget.
- Measure the effective feature dimension. Count numerical values after preprocessing, not raw columns. One-hot encoding can expand a small categorical table substantially, while aggregation or projection can reduce it.
- Estimate qubits. For amplitude encoding, a vector of length d requires enough qubits to represent the chosen state dimension, commonly
ceil(log2(d))when padding to a power of two. For angle encoding, begin with approximately one qubit per feature per rotation layer, then account for feature grouping or re-uploading. Basis encoding usually follows the number of bits needed to represent each discrete value. - Estimate repetitions and depth. For angle and feature-map circuits, multiply the number of data-injection layers by the number of rotations per feature and add entangling layers. For amplitude encoding, treat state preparation as a separate cost rather than assuming that the low qubit count means a shallow circuit.
- Estimate measurements. A variational model may require many circuit evaluations for each optimizer step. Include the number of observables, shots per circuit, parameter-shift or other gradient evaluations, and any validation runs. Encoding choice affects this total indirectly through circuit depth and the number of trainable parameters.
- Check the hardware path. Compare the estimated two-qubit gates, connectivity requirements, supported basis gates, and maximum practical depth with the target simulator or processor. A circuit that works as an ideal statevector simulation may behave differently with finite shots and noise.
A useful first-pass budget is:
total circuit work ≈ circuits per optimization step × shots per circuit × optimization steps
This is a planning approximation, not a runtime guarantee. Compilation, queueing, batching, gradient strategy, and backend implementation can change the actual cost.
Inputs and assumptions
Record these inputs before selecting an encoding. Keeping them explicit makes the decision repeatable when the dataset or backend changes.
- Data type: binary, categorical, continuous, sparse, dense, sequential, image-like, or graph-structured.
- Effective dimension: the number of values entering the quantum circuit after imputation, scaling, encoding, and optional dimensionality reduction.
- Value range: bounded values are easier to map consistently to rotation angles. Decide whether outliers are clipped, transformed, or handled separately.
- Precision requirement: ask whether small differences in a feature must remain distinguishable after encoding and measurement.
- Qubit budget: include only usable qubits if the target device has connectivity, calibration, or reserved-qubit constraints.
- Depth and noise budget: set a provisional maximum for one- and two-qubit layers, then revise it after compiling a representative circuit.
- Algorithm interface: determine whether the circuit needs a basis state, an expectation value, a kernel overlap, a probability distribution, or a trainable model.
- Simulation method: statevector, shot-based, tensor-network, or hardware execution changes which circuit sizes are practical. See the quantum simulator comparison when choosing a validation path.
Practical code patterns
The following PennyLane-style patterns show the conceptual shape of each method. Names and options can vary across SDK releases, so confirm the installed version's documentation before moving code into production.
# Basis: x is a bit string such as [1, 0, 1]
qml.BasisState(x, wires=range(len(x)))
# Amplitude: v must be normalized, or normalized explicitly
v = v / np.linalg.norm(v)
qml.AmplitudeEmbedding(v, wires=range(n_qubits), normalize=False)
# Angle: scale each feature into a chosen angle interval
scaled = scale_features(x, low=-np.pi, high=np.pi)
qml.AngleEmbedding(scaled, wires=range(len(scaled)), rotation="Y")
# Feature map: encode, then add trainable structure
qml.AngleEmbedding(scaled, wires=wires, rotation="Y")
for wire in wires:
qml.RY(theta[wire], wires=wire)
for pair in entangling_pairs:
qml.CNOT(wires=pair)
For Qiskit, Cirq, or another SDK, use the same design sequence: preprocess outside the circuit, map values to gates, compile a small representative circuit, and inspect depth and two-qubit gate counts. Do not compare frameworks only by the convenience of an embedding function; compare the compiled circuit on the backend you intend to use.
Worked examples
Example 1: A binary classification table
Suppose a dataset has six continuous features and a binary label. A sensible baseline is angle encoding with six qubits and one rotation per feature, followed by a shallow trainable circuit. Standardize the training features, apply the same transformation to validation and test data, and keep the first circuit shallow enough to compare against a classical baseline.
If six qubits are unavailable, reduce the features before encoding or group features deliberately. Avoid silently dropping columns: measure validation performance and document which information was removed. If feature interactions are important, test a second version with a small entangling layer rather than immediately increasing repetitions.
Example 2: A discrete configuration problem
For a problem represented by binary decisions, basis encoding can be a natural fit. Each bit is placed directly in a computational-basis state, and the circuit can evaluate a cost function or apply an optimization routine. This avoids the normalization step required by amplitude encoding and makes the input semantics easy to inspect.
Check, however, whether the algorithm expects a superposition of candidate solutions. Preparing one basis state per candidate is different from preparing a distribution over many candidates. The encoding and the algorithm must agree on what a measured bit string means.
Example 3: A dense vector with a strict qubit limit
Assume a dense vector has many components but the experiment can access only a small number of qubits. Amplitude encoding may look attractive because a vector of length 2n can be represented with n qubits. First normalize and pad the vector if necessary, then benchmark state preparation separately from the model circuit. If preparation dominates depth or introduces too many two-qubit gates, an angle-encoding baseline using selected or compressed features may be the more informative experiment.
Use identical preprocessing, train-validation splits, shot settings, and evaluation metrics when comparing the two approaches. Otherwise, an apparent encoding advantage may actually come from a different data pipeline or measurement budget.
When to recalculate
Revisit the encoding whenever an input to the estimate changes. At minimum, recalculate after a major SDK release, a backend change, a new feature map, a different preprocessing pipeline, or a change in shot and optimizer settings. Hardware compilation can alter depth, gate counts, and connectivity overhead, so recompile representative circuits rather than relying on an old estimate.
For an ongoing project, review the decision on a regular six-month cycle and after meaningful benchmark changes. Repeat the worksheet when:
- the dataset gains or loses features;
- categorical handling changes the effective dimension;
- the target backend has a different qubit layout or native-gate set;
- training becomes unstable, gradients become uninformative, or validation performance stalls;
- the experiment moves from an ideal simulator to finite shots or real hardware.
Before execution, run a small preflight: validate feature ranges, assert vector normalization where required, test the encoded state or probabilities, compile the circuit, and compare depth and two-qubit gates with your budget. The quantum circuit testing guide can help turn these checks into regression tests. For hardware runs, use the real-hardware preflight checklist, then review noise and measurement effects separately from encoding quality.
The practical default is simple: start with the least complicated encoding that preserves the information your algorithm needs, establish a reproducible baseline, and increase compression or circuit expressivity only when measurements justify it. That approach makes quantum data encoding a testable engineering decision rather than a choice based on qubit count alone.