Quantum data encoding determines how classical values become qubit states, so it affects qubit count, circuit depth, runtime, trainability, and hardware noise. This guide compares basis, angle, amplitude, and feature-map encoding, then gives you a repeatable method for choosing and validating an approach in Qiskit, PennyLane, Cirq, or another quantum SDK.
Overview
A quantum circuit cannot consume a spreadsheet, image, or feature vector directly. Before an algorithm can process classical data, an encoding circuit must map that data to a quantum state. The mapping is part of the model design, not just a preprocessing detail.
The main choices differ in what they preserve and what they cost:
- Basis encoding represents discrete bits as computational-basis states such as |0101⟩.
- Angle encoding maps numerical features to rotation angles on one or more qubits.
- Amplitude encoding stores normalized values in the amplitudes of a quantum state.
- Feature-map encoding applies a parameterized circuit designed to transform features into phases, rotations, or entanglement patterns. It is often used as the data-embedding layer of a quantum machine-learning model.
No method is universally best. A useful selection starts with the dataset: its type, dimension, scale, sparsity, precision requirements, and whether the data is static or repeatedly loaded during training.
| Method | Qubit cost | Circuit depth | Normalization | Data-loading overhead | Typical SDK support |
|---|---|---|---|---|---|
| Basis | Often one qubit per binary feature or bit | Low to moderate, depending on state preparation | Not required for binary values | Usually low for binary inputs; higher when discretizing numbers | Broad support in Qiskit, Cirq, PennyLane, and hardware-oriented SDKs |
| Angle | Often one qubit per feature, or fewer with feature reuse | Low for a single layer; increases with repeated layers | Scale values into a valid angle range | Usually modest and easy to inspect | Broad support through rotation gates and embedding templates |
| Amplitude | Approximately log2 of the vector length, subject to padding | Can be high for general state preparation | Required: the vector must have unit norm | Potentially high; state preparation can dominate the circuit | Available in major SDKs, with implementation details varying |
| Feature map | Depends on feature count and map design | Moderate to high when repeated or entangling | Usually scale features for the chosen gates | Depends on the map and number of repetitions | Supported through built-in templates or custom parameterized circuits |
These are planning ranges rather than guarantees. A hardware-native transpiler, connectivity constraints, decomposition choices, and measurement strategy can change the final circuit substantially.
How to estimate encoding cost
Use a small worksheet before writing the full model. The goal is to estimate resources using the same inputs each time you compare encodings.
- Count the usable features. Let
dbe the number of values entering the quantum circuit after ordinary classical preprocessing. - Set the qubit budget. Record the maximum number of qubits available on your simulator target or intended hardware.
- Estimate repetitions. A feature map repeated
rtimes can multiply rotation and entangling operations, even when the qubit count stays fixed. - Estimate shots. If an experiment uses
smeasurement shots and evaluatesecircuit instances, a simple execution estimate iss × e. Include optimizer iterations when training a variational model. - Separate loading from computation. Record gates used to encode the data separately from gates used by the algorithm. This shows whether the encoding is consuming most of the circuit budget.
- Check the compiled circuit. Logical gate counts are only an initial estimate. Transpilation, routing, and native-gate decomposition may increase depth.
For basis encoding, begin with the number of bits needed to represent each input. For angle encoding, begin with the number of mapped rotations. For amplitude encoding, choose a vector length that fits the available state dimension: n qubits represent up to 2^n amplitudes, although padding and state-preparation details affect the practical result. For a feature map, multiply the base map cost by the number of repetitions and add the cost of entangling operations.
Keep a record of the same metrics for every candidate: qubits, total gates, two-qubit gates, depth before compilation, depth after compilation, parameter count, shots, and validation accuracy or objective value. This turns “which encoding is better?” into a reproducible comparison rather than a guess.
Inputs and assumptions
Your encoding decision depends on more than the number of columns in a dataset. Document these inputs before selecting a method:
- Data type: Binary and categorical data may fit basis encoding, while continuous data often fits angle or feature-map encoding more naturally.
- Dimension: High-dimensional vectors may look attractive for amplitude encoding because of its logarithmic qubit requirement, but the state-preparation circuit can be expensive.
- Value range: Angle rotations need a deliberate scaling rule. For example, map each training feature using statistics from the training split only, then apply the same transformation to validation and test data.
- Normalization: Amplitude encoding requires a normalized vector. Handle zero vectors, padding, and numerical precision explicitly rather than relying on an SDK default.
- Repeated loading: In a training loop, encoding cost is paid repeatedly. A method that is acceptable for one demonstration may be inefficient when evaluated thousands of times.
- Noise and connectivity: Deep circuits and additional two-qubit gates are more difficult to evaluate reliably on constrained hardware. Compare compiled circuits, not only abstract diagrams.
- Algorithm compatibility: The encoding should expose useful relationships to the algorithm. A compact representation is not automatically informative.
SDK support should be checked at the version used by your project. Names, parameter conventions, and feature-map templates can change. For migration work, compare the circuit produced by each framework rather than assuming similarly named templates are identical. The quantum SDK comparison and migration guide and circuit portability guide provide useful follow-up checklists.
Worked examples
Example 1: Binary classification with eight binary features
Suppose each record contains eight binary values. Basis encoding can represent the record directly with about eight data qubits, assuming one qubit per bit. The loading circuit is straightforward, and measurement results have an easy interpretation. Its limitation is that it does not naturally preserve a continuous distance between values; any numerical feature must first be discretized.
Angle encoding could also use eight qubits, mapping each feature to a rotation. This adds a scaling step but may be more appropriate if the binary values are really thresholded measurements that you want to treat as numerical inputs. Compare both methods with the same classifier, train-test split, shot budget, and random seeds.
Example 2: A 16-value numerical vector
Amplitude encoding can place up to 16 values into the amplitudes of four qubits, after normalization. That qubit reduction is useful when qubits are scarce. However, general state preparation may create a deeper circuit than four layers of simple rotations. Angle encoding would commonly use 16 qubits for one feature per qubit, but its loading circuit may be shallower and easier to inspect.
A practical comparison is therefore not “four qubits versus 16 qubits.” Measure both alternatives after compilation, then compare depth, two-qubit gates, execution time or job size where available, and model quality. If amplitude preparation dominates the circuit, its lower qubit count may not provide a practical advantage.
Example 3: A small variational classifier
For six scaled continuous features, begin with one angle rotation per feature and a shallow entangling layer. Then test a feature map that reuses the six features across two layers. The second design may provide richer interactions but also introduces more parameters, gates, and opportunities for optimization difficulty.
Use a fixed evaluation protocol: identical data splits, preprocessing, initialization policy, optimizer limits, shot settings, and stopping criteria. Save the encoding configuration with each result. Reproducibility practices such as explicit seeds, metadata, and circuit snapshots are covered in the quantum experiment reproducibility guide.
When to recalculate
Revisit the encoding whenever an input to the decision changes. Recalculate after adding or removing features, changing normalization, increasing feature-map repetitions, switching simulators or hardware targets, changing shot counts, or replacing a variational ansatz. Recheck it when an SDK changes a template or gate decomposition, because the same high-level encoding can compile differently across versions and backends.
Use this practical checklist:
- Write down feature count, value ranges, sparsity, and preprocessing rules.
- Choose two or three plausible encodings rather than committing immediately.
- Build a small circuit for each and inspect qubits, depth, and two-qubit gates.
- Compile for the intended target and record the post-compilation metrics.
- Run a controlled pilot with identical data and evaluation settings.
- Test robustness with altered seeds or a second data split.
- Store the encoding choice, SDK version, circuit metrics, and assumptions with the experiment.
Start with the simplest encoding that preserves the information your algorithm needs. Move to amplitude encoding or a richer feature map only when the expected benefit justifies its loading and circuit costs. When debugging unexpected results, inspect the encoded state or intermediate circuit before changing the optimizer; an unsuitable or incorrectly scaled data map can make a sound algorithm appear ineffective. For additional diagnostics, see the quantum circuit debugging guide and the guide to parameterized quantum circuits in Python.