Quantum Data Encoding Guide: Choose and Implement Feature Maps for QML
quantum machine learningquantum data encodingquantum feature mapsQiskitPennyLanequantum circuits

Quantum Data Encoding Guide: Choose and Implement Feature Maps for QML

qqbit.vision Editorial Team
2026-11-09
8 min read

Compare basis, angle, amplitude, and re-uploading feature maps with qubit estimates, preprocessing rules, and Qiskit and PennyLane examples.

Choosing a quantum feature map is a resource and modeling decision, not just a circuit-coding detail. This guide explains how to encode classical data with basis, angle, amplitude, and data re-uploading methods, how to estimate qubit and gate requirements, and how to test the choice in Qiskit or PennyLane.

Overview

Quantum data encoding converts a classical feature vector into the parameters or states of a quantum circuit. A feature map is the circuit that performs this conversion. The encoded state is then used by a variational circuit, a kernel calculation, a measurement routine, or another quantum machine learning workflow.

There is no universally best encoding. The right choice depends on the number of features, their type and range, the available qubits, circuit-depth limits, simulator or hardware constraints, and the model you plan to train. A useful first decision is whether your data should be represented as computational-basis values, rotation angles, amplitudes, or repeated inputs interleaved with trainable layers.

MethodTypical qubit requirementMain constraintGood starting use
Basis encodingApproximately one qubit per binary featureFeatures must be discretized or binaryBinary inputs and small combinatorial problems
Angle encodingOften one qubit per feature, or fewer with batchingValues need a defined numeric rangeSmall real-valued feature vectors
Amplitude encodingCeiling of log2 of the vector lengthState preparation and normalizationExperiments where qubit count is the primary constraint
Data re-uploadingUsually a small fixed registerMore layers, measurements, and optimization workCompressing many features into repeated circuit inputs

These estimates describe the logical encoding only. Measurement operations, entangling layers, basis changes, error mitigation, compilation, and hardware connectivity can add substantial overhead. For a broader hybrid workflow, see hybrid quantum-classical workflow patterns.

How to estimate

Before writing a circuit, record four quantities: the number of samples, the number of features per sample, the feature ranges, and the maximum qubit budget. Then estimate the encoding with the following steps.

1. Count the logical inputs

Let d be the number of features after preprocessing. For angle encoding, a straightforward design uses d qubits and applies one parameterized rotation per feature. If features are grouped or processed in batches, the register can be smaller, but each sample requires multiple circuit evaluations or sequential encoding stages.

For amplitude encoding, a vector of length L requires at least ceil(log2(L)) qubits. If L is not a power of two, pad the vector to the next power of two. For example, a six-value vector is padded to length eight and needs three qubits. The padding convention should be documented because it becomes part of the model definition.

2. Estimate encoding depth and gate count

A simple angle map has a depth that is roughly one rotation layer, although transpilation and device connectivity may change that result. A basis map may use X gates for bits whose value is one, with depth depending on parallelism. Amplitude encoding generally requires a more involved state-preparation circuit; its practical cost should be measured after compilation rather than inferred from the qubit count alone.

For data re-uploading, use a simple planning formula:

encoding layers × rotations per layer + trainable layers × trainable gates

This is a planning estimate, not a hardware benchmark. Also estimate the number of evaluations in training. If a circuit is executed with S shots, a batch contains B samples, and optimization requires E circuit evaluations per step for T steps, a basic shot count is:

total shots ≈ S × B × E × T

Gradient methods, parameter-shift rules, finite differences, batching strategies, and framework execution modes can alter E. Treat it as an experiment-specific input and record how it was obtained.

3. Check whether the encoding preserves useful information

Encoding more values does not guarantee a better model. Scaling can make a major difference for angle maps: if a feature is sent directly into a rotation, large or inconsistent ranges can produce rapidly varying angles. Normalize features using a rule that can be applied identically to training, validation, and production data. Common choices include mapping values to a bounded interval or standardizing them before applying a fixed angle scale.

Amplitude encoding requires a normalized vector. For a real vector x, compute its norm and use x / ||x|| when the norm is nonzero. Decide how to handle zero vectors and record whether padding occurs before or after normalization. Do not assume that normalization is harmless: it removes overall scale, which may carry meaning in the original data.

4. Compare trainability, not only resource counts

Feature maps interact with the trainable ansatz and the optimizer. A deeper map may express richer interactions but can increase noise, execution time, and optimization difficulty. A compact angle map is often a useful baseline because it is easy to inspect and debug. Data re-uploading can represent repeated nonlinear transformations with a small register, but its additional layers create more opportunities for unstable training.

Use the same preprocessing, optimizer settings, shot budget, validation split, and stopping rule when comparing encodings. Otherwise, an apparent feature-map improvement may actually come from a different experimental budget.

Inputs and assumptions

Create a short encoding specification before implementation. It should include:

  • Dataset shape: samples, raw features, retained features, and any feature grouping.
  • Feature types: binary, categorical, ordinal, continuous, sparse, or missing.
  • Preprocessing: imputation, encoding, scaling, clipping, dimensionality reduction, and padding.
  • Map definition: gates, rotation axes, repetitions, trainable parameters, and entangling operations.
  • Resource budget: logical qubits, compiled depth, two-qubit gates, shots, and expected circuit evaluations.
  • Evaluation: baseline model, validation metric, random seeds, and simulator or hardware backend.

A practical rule is to retain a classical baseline. If a simple classical model performs similarly with lower operational cost, the quantum circuit may still be useful for learning or research, but the result should not be presented as evidence of application-level advantage.

Minimal angle encoding in Qiskit

The following circuit maps one real feature to one Y-axis rotation. The scaling rule is explicit so it can be replaced with the rule used by your dataset pipeline.

from qiskit import QuantumCircuit
import numpy as np

x = np.array([0.20, -0.70, 0.45])
qc = QuantumCircuit(len(x))

# Example convention: x is already scaled to a moderate range.
for qubit, value in enumerate(x):
    qc.ry(float(value), qubit)

print(qc.draw())

This example is intentionally small. A production experiment should validate the range of every feature, apply the same transformation at inference time, and inspect the transpiled circuit for the selected backend. The Qiskit circuit visualizer guide can help with that inspection.

Minimal amplitude encoding in PennyLane

PennyLane provides a direct state-preparation operation for normalized data. The following example pads a three-value vector to four amplitudes and normalizes it.

import pennylane as qml
from pennylane import numpy as np

x = np.array([0.2, -0.4, 0.7])
x = np.pad(x, (0, 1))
norm = np.linalg.norm(x)
if norm == 0:
    raise ValueError("A zero vector cannot be amplitude encoded")
x = x / norm

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def circuit():
    qml.AmplitudeEmbedding(x, wires=[0, 1], normalize=False)
    return qml.probs(wires=[0, 1])

print(circuit())

State-preparation decomposition and differentiation behavior can vary by operation and framework version. Verify the compiled circuit and gradient path in the environment used for the experiment rather than relying only on the source-level circuit.

Worked examples

Example A: twelve continuous features

Suppose each sample has 12 continuous features and the available logical budget is 12 qubits. A direct angle map uses 12 qubits and one rotation per feature. If the circuit adds two entangling layers, record the map and ansatz separately: the encoding cost is not the total model cost. Start with one encoding repetition, compare it with two, and measure validation performance against compiled depth and two-qubit gate count.

Example B: a 20-value compressed representation

Amplitude encoding reduces the register requirement to five qubits because 20 values are padded to 32. That looks attractive from a qubit-count perspective, but the state-preparation circuit may be much more expensive than 20 simple rotations. The decision should therefore compare compiled depth, gate types, execution evaluations, and validation results—not just five qubits versus 12.

Example C: 50 features with four available qubits

A direct one-feature-per-qubit angle map does not fit. Options include classical dimensionality reduction to four features, processing the input in 13 groups with a defined aggregation strategy, or using data re-uploading across several layers. Each option changes the model and should be described explicitly. Re-uploading is not equivalent to encoding all 50 values simultaneously; it is a sequential representation with a larger depth and potentially different optimization behavior.

For each comparison, keep a table with columns for map name, preprocessing, qubits, encoding repetitions, compiled depth, two-qubit gates, shots, training evaluations, validation score, and failure notes. This makes the experiment reproducible and helps separate a feature-map decision from a backend or optimizer decision. For interpretation of sampled outputs, see quantum measurement and readout guidance.

Encoding documentation template

Dataset version:
Raw feature count:
Retained feature count:
Feature preprocessing:
Encoding method:
Qubit count:
Padding or batching rule:
Value-to-gate mapping:
Encoding repetitions:
Ansatz and entanglers:
Simulator or hardware target:
Shots per circuit:
Gradient method:
Training evaluation estimate:
Validation metric:
Known limitations:

When to recalculate

Revisit the estimate whenever the dataset, preprocessing pipeline, framework, or execution target changes. A new feature-selection step can alter qubit requirements. A changed normalization range can alter rotation behavior. A framework release can change supported operations, differentiation methods, decomposition, or transpilation output. A different simulator or hardware target can change the effective depth and measurement budget.

Recalculate before comparing published or internal results if any of these inputs changes:

  • the number or order of features;
  • scaling, clipping, imputation, or padding rules;
  • the number of encoding repetitions or trainable layers;
  • shots, batch size, gradient method, or optimizer evaluation strategy;
  • the SDK version, device model, compiler settings, or backend connectivity;
  • the validation split, metric, or classical baseline.

As a final workflow, choose a simple angle or basis baseline, document its assumptions, compile it for the intended target, and record the actual resources. Then test amplitude encoding or data re-uploading only when they address a clear constraint, such as a limited qubit budget or a need to model repeated feature interactions. This keeps quantum data encoding decisions measurable, reviewable, and suitable for the next dataset rather than tied to a single notebook.

Related Topics

#quantum machine learning#quantum data encoding#quantum feature maps#Qiskit#PennyLane#quantum circuits
q

qbit.vision Editorial Team

Quantum Computing Editor

Senior editor and content strategist. Writing about technology, design, and the future of digital media. Follow along for deep dives into the industry's moving parts.