Basis Encoding
Basis encoding stores classical bitstrings directly as computational basis states, the simplest and most transparent way to load discrete data into a circuit.
Bits to basis states
Basis encoding takes a classical bitstring and prepares the corresponding computational basis state: the integer 5, written 101 in binary, becomes the state |101>. Each classical bit sets one qubit to |0> or |1> using at most a single X gate. It is the most literal correspondence between classical and quantum data, and the foundation for algorithms that expect data in the basis, such as quantum arithmetic and search.
Superposition over a dataset
Basis encoding becomes powerful when combined with superposition: a single register can hold a uniform superposition over many data records, sum_j |x_j>, letting an algorithm process the whole dataset in one pass through interference. This is the setting many textbook quantum speedups assume, though preparing such a superposition efficiently is itself nontrivial and often the hidden cost.
- Simplicity: preparation uses only X gates, one per set bit, so depth is minimal.
- Interpretability: measurement returns exactly the stored bitstring, unlike amplitude encoding.
- Qubit hunger: it needs one qubit per bit of precision per feature, making it expensive for high-precision real-valued data.
- Discreteness: it fits categorical and integer data naturally, real numbers only after quantization.
# Basis encoding of the bitstring 1011 (schematic)
def basis_encode(bits):
for i, b in enumerate(bits):
if b == 1:
qml.PauliX(wires=i) # flip qubit i to |1>
# basis_encode([1,0,1,1]) prepares |1011>
Where it fits
Basis encoding is the natural input format for fault-tolerant algorithms that manipulate numbers arithmetically and for oracle-based routines that mark solutions. It is less common in near-term variational classifiers, which favor the smoother, differentiable geometry of angle encoding, because a basis-encoded input is a discrete point with no gradient with respect to the data.
Choosing among encodings
Basis, angle, and amplitude encoding trade qubit count against preparation depth and differentiability. Basis is cheapest in gates but hungriest in qubits and non-differentiable in the data; it is the right tool for discrete, algorithmic tasks and the wrong one for smooth regression. The encoding overview compares them side by side.