Quantum Data Encoding Methods: Basis, Angle, Amplitude, and Hamiltonian Encoding Explained
data encodingquantum machine learningquantum feature mapsPennyLaneQiskitquantum circuits

Quantum Data Encoding Methods: Basis, Angle, Amplitude, and Hamiltonian Encoding Explained

SSmart QBit Labs Editorial Team
2026-11-06
8 min read

Compare basis, angle, amplitude, and Hamiltonian encoding, estimate qubit costs, and choose a practical method for quantum machine learning.

Choosing a quantum data encoding method is a resource decision, not merely a syntax choice. This guide compares basis, angle, amplitude, and Hamiltonian encoding, shows how to estimate qubit and circuit requirements, and provides a practical Python workflow for selecting an approach before building a quantum machine learning experiment.

Overview

Quantum data encoding converts classical values into a quantum state or into the parameters of a quantum operation. The encoding determines what information the circuit can access, how many qubits are required, how much preprocessing is needed, and how difficult the experiment may be to run on a simulator or quantum processing unit.

There is no universally best encoding. A small vector of bounded sensor readings may fit naturally into angle encoding, while a discrete bit string may be a good candidate for basis encoding. Amplitude encoding can represent many values with relatively few qubits, but state preparation may be expensive. Hamiltonian encoding is useful when the data describes a physical system, an operator, or coefficients in an optimization and simulation problem.

Use the following high-level comparison as a first filter. Actual gate counts and depths depend on the framework, state-preparation routine, hardware connectivity, compiler, and whether the circuit is simulated or executed on a QPU.

MethodTypical inputQubit estimateCost and constraintsUseful applications
Basis encodingBinary or categorical values represented as bitsUsually one qubit per bitSimple preparation; values must be discretized or binaryCombinatorial states, bit strings, search problems
Angle encodingReal-valued vector with bounded or scaled featuresOften one qubit per feature, though features can be reusedRequires scaling; circuit depth grows with repetitions and entangling layersSmall tabular datasets, variational classifiers, feature maps
Amplitude encodingReal or complex vector interpreted as state amplitudesFor a vector of length N, ceil(log2 N) qubitsRequires normalization and usually nontrivial state preparationCompact state representations, algorithmic demonstrations
Hamiltonian encodingOperator coefficients, physical parameters, or an energy functionDepends on the system or problem graphRequires a valid operator decomposition and evolution or measurement strategyVQE, quantum simulation, QAOA-style optimization

Encoding is only the first part of a quantum model. A useful experiment also needs a circuit ansatz, measurements, an optimizer, a classical baseline, and a reproducible evaluation procedure. For model assessment, see the guide to evaluating quantum machine learning models.

How to estimate encoding cost

Start with the shape and meaning of the data rather than the framework function you want to call. Record four quantities:

  1. Feature count: Let d be the number of scalar features after preprocessing.
  2. State-vector length: Let N be the number of values to represent as amplitudes.
  3. Repetitions: Let L be the number of times the feature map or variational block is applied.
  4. Measurement budget: Let S be the number of shots used for each circuit evaluation when sampling is required.

For basis encoding, if the input is already a bit string of length b, a first estimate is q = b qubits. If an integer ranges from 0 through M - 1, storing its binary representation requires q = ceil(log2 M) qubits, assuming the circuit can work with all bit patterns or otherwise handles unused states.

For angle encoding, the common first estimate is q = d qubits when each feature controls one rotation. Some feature maps reuse features across rotation axes or layers, so qubit count can be lower than d, but circuit depth and parameter count may increase. If the feature map is repeated L times, count the repeated rotation and entangling operations when estimating depth.

For amplitude encoding, choose N as the length of the vector after padding. The qubit estimate is:

q = ceil(log2 N)

If N is not a power of two, pad the vector to the next power of two. Then normalize it so that the sum of squared magnitudes equals one:

sum(|xᵢ|²) = 1

This qubit advantage does not automatically mean a lower total cost. Preparing an arbitrary amplitude state can require many gates, and the preparation routine may dominate the circuit. Treat the state-preparation method as a separate line item in your resource estimate.

Hamiltonian encoding needs a different calculation. Represent the operator as a sum of implementable terms, such as Pauli products:

H = sumᵢ cᵢ Pᵢ

Here, the number of system qubits is determined by the modeled system, while the number of terms affects measurement groups, circuit construction, and the cost of estimating an expectation value. For a broader worksheet covering qubits, depth, shots, and runtime, use the quantum circuit resource estimation guide.

Inputs and assumptions

Before selecting an encoding, inspect the dataset with a short checklist:

  • Data type: Is each value binary, categorical, continuous, sparse, or a coefficient in a physical model?
  • Range: Do features have comparable ranges, or will one feature dominate a rotation angle?
  • Dimension: Can the feature count fit the available qubit budget, or is dimensionality reduction required?
  • Precision: Does the application need exact values, coarse bins, or only relative magnitudes?
  • Structure: Are relationships between features more important than individual values?
  • Execution target: Are you testing with a state-vector simulator, a shot-based simulator, or hardware?

Scaling is especially important for angle encoding. A common assumption is to map a feature x from a known interval [a, b] to an angle in [0, pi] or [-pi, pi]. The mapping should be fitted using training data and applied consistently to validation and test data. Avoid using information from the test set to determine scaling parameters.

Basis encoding requires a deliberate discretization policy. For example, a continuous measurement might be converted to a threshold bit, but that conversion can discard information. Amplitude encoding preserves relative values in the state vector, but the measurement process does not expose every amplitude directly; the circuit must be designed to extract the information relevant to the task.

Hamiltonian encoding should be reserved for data with an operator or energy interpretation. For an ordinary table of unrelated business features, calling a weighted sum a Hamiltonian does not by itself create a useful quantum advantage. Define what each term means and how its expectation value will be measured.

Worked examples

Example 1: selecting an encoding with Python

The following small selector estimates a first-pass choice. It is intentionally a planning tool, not a benchmark. The thresholds are assumptions that you can change for your device and experiment.

import math


def recommend_encoding(kind, feature_count, vector_length=None,
                        max_qubits=8, values_are_scaled=False):
    if kind == "binary":
        qubits = feature_count
        return {
            "method": "basis",
            "estimated_qubits": qubits,
            "fits_budget": qubits <= max_qubits,
            "next_step": "Verify discretization and unused bit patterns."
        }

    if kind == "continuous":
        qubits = feature_count
        return {
            "method": "angle",
            "estimated_qubits": qubits,
            "fits_budget": qubits <= max_qubits,
            "next_step": "Scale every feature to a documented angle range."
        }

    if kind == "state_vector":
        if vector_length is None or vector_length < 1:
            raise ValueError("vector_length must be positive")
        padded_length = 1 << (vector_length - 1).bit_length()
        qubits = math.ceil(math.log2(padded_length))
        return {
            "method": "amplitude",
            "padded_length": padded_length,
            "estimated_qubits": qubits,
            "fits_budget": qubits <= max_qubits,
            "next_step": "Normalize the vector and estimate state-preparation cost."
        }

    if kind == "operator":
        return {
            "method": "Hamiltonian",
            "estimated_qubits": "depends on the modeled system",
            "fits_budget": "review operator size",
            "next_step": "Decompose the operator and count measurable terms."
        }

    raise ValueError("kind must be binary, continuous, state_vector, or operator")


print(recommend_encoding("continuous", feature_count=4, max_qubits=6))
print(recommend_encoding("state_vector", feature_count=0,
                         vector_length=10, max_qubits=6))

For the continuous example, the first estimate is four qubits and angle encoding. For a state vector of length 10, padding produces a length of 16, so amplitude encoding needs four qubits. The second option saves qubits but still requires a realistic state-preparation estimate.

Example 2: a minimal PennyLane comparison

Framework APIs change, so confirm the installed version's documentation before moving code into production. The following pattern illustrates the conceptual difference between angle and amplitude encoding:

import pennylane as qml
from pennylane import numpy as np

features = np.array([0.2, -0.7, 0.4])

angle_dev = qml.device("default.qubit", wires=3)

@qml.qnode(angle_dev)
def angle_circuit(x):
    qml.AngleEmbedding(x, wires=range(3), rotation="Y")
    return qml.expval(qml.PauliZ(0))

amplitudes = np.array([0.2, -0.7, 0.4, 0.1])
amplitudes = amplitudes / np.linalg.norm(amplitudes)
amplitude_dev = qml.device("default.qubit", wires=2)

@qml.qnode(amplitude_dev)
def amplitude_circuit(x):
    qml.AmplitudeEmbedding(x, wires=range(2), normalize=False)
    return qml.expval(qml.PauliZ(0))

print(angle_circuit(features))
print(amplitude_circuit(amplitudes))

The angle circuit uses one feature per qubit in this example. The amplitude circuit uses four normalized values on two qubits. These outputs are not directly comparable as model quality measurements: they come from different state representations and need task-specific readout, training, and evaluation.

In a real quantum machine learning tutorial, compare each encoding against the same classical baseline, train-validation split, optimizer budget, and measurement settings. That prevents a compact encoding from appearing better simply because it received a different experimental setup. For algorithm context, the quantum algorithms reference explains where variational and optimization circuits fit into broader workflows.

When to recalculate

Revisit the encoding decision whenever the dataset, circuit, or execution target changes. Recalculate when feature engineering changes d, when padding changes the amplitude vector length N, when the number of encoding layers L increases, or when a new hardware backend imposes a smaller qubit limit or different connectivity.

Also revisit preprocessing when the data distribution shifts. New minimum and maximum values can invalidate an angle-scaling rule. New sparse or categorical features may make basis encoding more appropriate, while a reduction in feature count may make a simpler angle map practical. If the task changes from classification to simulation or optimization, reconsider Hamiltonian encoding rather than carrying over a machine-learning feature map.

Keep a small encoding record in your project repository with the original feature shape, scaling ranges, padding rule, normalization method, qubit formula, circuit depth, shot count, and framework version. Re-run the estimate before each meaningful experiment. Then test the smallest defensible circuit first, compare it with a classical baseline, and expand only when the added encoding cost has a clear experimental purpose.

Related Topics

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

Smart QBit Labs Editorial Team

Quantum Computing Editors

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.