Choosing a quantum data encoding is a modeling decision, not merely a circuit-syntax choice. This guide compares angle, basis, amplitude, IQP, and related quantum feature maps by qubit cost, depth, input constraints, preprocessing, and trainability risk, then gives you a reusable checklist for selecting and benchmarking an encoding for a QML experiment.
Overview
Quantum data encoding converts classical features into a quantum state or into parameters used by a quantum circuit. The encoding determines what information reaches the circuit, how many qubits are needed, how much preprocessing is required, and how difficult the resulting model may be to train.
There is no universally best quantum feature map. A small dataset with binary variables has different requirements from a dense vector with hundreds of continuous features. In practice, the most useful choice usually balances four constraints:
- Representation: Can the circuit express the distinctions that matter in the dataset?
- Resources: How many qubits, gates, circuit layers, and measurements are required?
- Compatibility: Does the encoding accept the feature ranges, data types, and normalization you have?
- Optimization: Can the hybrid model be trained without unstable gradients, excessive sampling noise, or an overly large parameter space?
Start with a classical baseline and a small quantum circuit. If a feature map performs well, you can increase circuit depth or add entangling layers later. This makes the encoding an experimentally testable component rather than an assumption about where a quantum advantage will come from.
Comparison at a glance
| Encoding | Typical qubit requirement | Input constraints | Useful starting scenario | Main caution |
|---|---|---|---|---|
| Angle | Often one qubit per feature per encoding layer | Features must be scaled to suitable rotation angles | Small or medium continuous feature vectors | Repeated rotations can increase depth and may not add useful information |
| Basis | Often one qubit per binary feature | Inputs must be discrete or converted to bits | Binary, categorical, or thresholded data | Binarization can discard magnitude and ordering information |
| Amplitude | For a state vector of length n, roughly log2(n) qubits, subject to valid dimensions | Values must be normalized; vector length usually needs to match a power-of-two state dimension | Compact vectors when qubit count is the primary constraint | State preparation can be deep and may offset the qubit savings |
| IQP-style | Usually tied to the number of encoded features or selected feature groups | Features are scaled for phase and rotation operations | Feature maps combining single-qubit rotations with diagonal entangling structure | Depth, entanglement, and parameter scaling can make training difficult |
These are design patterns rather than guarantees. Actual resource use depends on the framework implementation, decomposition into hardware-native gates, repetition of the feature map, number of entangling layers, and the target backend. For a broader workflow, see how to choose a quantum computing backend.
Checklist by scenario
Scenario 1: You have a small continuous feature vector
Begin with angle encoding. For a vector such as [0.2, -0.6, 0.9], scale each feature into a range appropriate for the rotation gates used by your circuit. Use one qubit per feature as a transparent first experiment, then compare one or more encoding layers.
Angle encoding is easy to inspect: each feature controls a rotation, and the circuit structure remains relatively straightforward. It is a practical choice for a PennyLane tutorial or a first hybrid classifier because you can change the feature scaling without changing the number of qubits. Its limitation is that the qubit count grows with the number of features unless you reduce dimensions, reuse qubits across layers, or select a subset of features.
- Scale continuous inputs consistently between training and inference.
- Record the scaling range as part of the model pipeline.
- Compare a single encoding layer with repeated layers instead of assuming deeper is better.
Scenario 2: Your inputs are binary or naturally categorical
Basis encoding is a direct candidate when each input can be represented as a bit. A zero or one determines the computational-basis state of a qubit. This preserves binary membership clearly, but it is not a free conversion for nonbinary data.
Before choosing basis encoding, ask whether thresholding a continuous feature changes the task. For categorical values, decide whether an ordinal bit representation falsely implies an order. One-hot encoding may preserve category identity more faithfully, but it increases the number of bits and therefore the qubit requirement.
- Define the category-to-bit mapping explicitly.
- Check whether class imbalance is introduced during binarization.
- Keep the classical preprocessing identical across quantum and classical baselines.
Scenario 3: Qubits are scarce but the vector is dense
Amplitude encoding stores a normalized classical vector in the amplitudes of a quantum state. In the ideal state-space description, a vector with a suitable length can be represented using logarithmically many qubits. This makes amplitude encoding attractive when qubit count is the dominant constraint.
The trade-off is state preparation. Loading an arbitrary classical vector into amplitudes can require a substantial circuit, and the preparation cost may be important on simulators and hardware alike. Amplitude encoding also requires careful normalization and dimension handling. If your vector length is not compatible with the feature map or framework operation, you may need padding or a different preprocessing step.
- Normalize each input vector using a documented rule.
- Decide whether padding with zeros changes the model meaningfully.
- Measure state-preparation depth separately from the trainable circuit depth.
- Do not compare qubit counts without comparing total gate cost.
Scenario 4: You want an entangling feature map
IQP-style encodings use structured rotations and diagonal interactions to create a feature-dependent quantum state. They are often used as quantum feature maps or as part of a quantum kernel or variational model. They can encode relationships between features that are not represented by independent rotations alone.
Use this family when you have a reason to test feature interactions, not simply because entanglement sounds more powerful. Begin with a shallow circuit, a small number of features, and a fixed entangling pattern. Compare it with an angle-only circuit using the same data split and evaluation metric.
- Track the number and arrangement of two-qubit gates.
- Test whether added interactions improve validation performance rather than only training performance.
- Watch for optimization problems as depth and parameter count increase.
A practical decision tree
- Are the features already binary? Start with basis encoding. If converting them to bits would lose important information, use scaled angle encoding instead.
- Are there only a few continuous features? Start with angle encoding and a shallow circuit.
- Is reducing qubit count more important than simplifying state preparation? Test amplitude encoding, while reporting its preparation cost.
- Do you specifically want feature interactions or a kernel-style map? Test an IQP-style map against a simpler angle baseline.
- Are there too many features for the available circuit? Apply documented classical feature selection or dimensionality reduction, then benchmark at least two encodings on the same reduced data.
What to double-check
Input ranges and normalization
Encoding operations have mathematical input assumptions. Rotation-based maps need a deliberate scale; amplitude maps need normalized vectors; basis maps need discrete values. Fit preprocessing parameters on the training split only, then apply the same transformation to validation, test, and production data. Otherwise, the encoding experiment can leak information before the quantum model is trained.
Qubit count versus circuit cost
A lower qubit count does not automatically mean a cheaper or more reliable circuit. State preparation, repeated feature-map layers, entangling gates, measurement shots, and transpilation can dominate the practical cost. Inspect the compiled circuit when possible, not just the high-level feature-map name. The quantum circuit transpilation guide provides useful context for this distinction.
Expressivity and trainability
A feature map should create distinctions the model can use, but increasing expressivity can make optimization harder. Deep circuits may produce noisy gradients, overfit a small dataset, or become difficult to execute on a constrained backend. Record training curves, validation results, gradient behavior where available, and circuit depth. Treat these measurements as part of the encoding comparison.
Framework behavior and syntax
Framework constructors and defaults change. Confirm the current documentation for argument names, accepted feature shapes, padding behavior, rotation conventions, differentiation support, and device limitations before copying a code example into a project. In PennyLane, a minimal pattern may look like this:
import pennylane as qml
from pennylane import numpy as np
dev = qml.device('default.qubit', wires=3)
features = np.array([0.2, -0.6, 0.9], requires_grad=False)
@qml.qnode(dev)
def angle_circuit(x):
qml.AngleEmbedding(x, wires=range(3), rotation='Y')
return [qml.expval(qml.PauliZ(i)) for i in range(3)]
# Basis encoding expects binary values.
@qml.qnode(dev)
def basis_circuit(bits):
qml.BasisEmbedding(bits, wires=range(3))
return [qml.expval(qml.PauliZ(i)) for i in range(3)]
Amplitude and IQP-style constructors require additional attention to shape, normalization, and supported arguments. Treat the snippet as a pattern to verify against your installed version, not as a substitute for version-specific documentation. For a complete beginner project, see the PennyLane hybrid classifier tutorial.
Hardware and noise assumptions
Run an initial comparison on a simulator, but do not stop there if deployment on hardware matters. Noise, connectivity, measurement cost, and compilation can change the ranking between encodings. A shallow angle map may be a stronger practical candidate than a theoretically compact but expensive amplitude circuit. If you move to hardware, document the backend, shots, circuit compilation, and any mitigation procedure. See the comparison of quantum error mitigation methods before interpreting noisy results.
Common mistakes
- Choosing by qubit count alone: Include state preparation and compiled gate depth in the resource comparison.
- Skipping a classical baseline: A quantum feature map should be evaluated against a simple classical model using the same split and preprocessing.
- Mixing preprocessing rules: Different scaling or imputation pipelines can make an encoding comparison invalid.
- Encoding every feature automatically: More features can mean more qubits, more depth, and more opportunities for noise. Start with a justified subset or reduced representation.
- Using basis encoding for convenience: Binarization may remove magnitude, distance, and category structure that the task depends on.
- Assuming amplitude encoding is automatically efficient: Count the cost of preparing the state, not only the number of qubits.
- Adding entanglement without an experiment: Compare an IQP-style map with a simpler map under identical evaluation conditions.
- Reporting only training accuracy: Include validation performance, repeated runs where practical, resource metrics, and sensitivity to shot noise.
- Copying outdated framework syntax: Check the installed SDK version and test feature shapes with a minimal circuit before building the full model.
When to revisit
Revisit your quantum data encoding whenever the dataset, feature count, model objective, or execution environment changes. A preprocessing update can make basis encoding more appropriate; a larger feature vector can make angle encoding impractical; a new backend can change the cost of two-qubit gates; and a framework release can alter constructor behavior or supported differentiation paths.
Use this review checklist before each substantial experiment or planning cycle:
- Describe the current feature types, ranges, missing-value policy, and dimensionality.
- Write down why the selected encoding fits those inputs.
- Benchmark the selected map against at least one simpler alternative.
- Record qubits, circuit depth, two-qubit gates, shots, preprocessing time, and state-preparation cost where relevant.
- Compare against a classical baseline using the same data split.
- Validate the code against the current framework and backend configuration.
- Recheck results on the intended simulator or hardware path before drawing conclusions.
The safest default is to start with the simplest encoding that respects the data, then expand the experiment only when the measurements justify it. Keep the preprocessing, circuit definition, backend settings, and evaluation results versioned together. That record makes it easier to switch from angle to amplitude encoding, test an IQP-style map, or reassess the entire feature pipeline when your dataset changes.