Amplitude Encoding: What It Saves in Qubits, and What It Costs

Amplitude Encoding: What It Saves in Qubits, and What It Costs

Amplitude encoding represents an N-entry vector with about log2(N) qubits, but state preparation and measurement still take resources.

Amplitude encoding puts the values of a classical vector into the amplitudes of a quantum state. When the vector has N entries and N is a power of two, the state needs only log2(N) qubits. If N is not a power of two, pad the vector with zeros and use ceil(log2(N)) qubits.

That compact representation is useful, but it does not make data loading free. Here is what the encoding means, how to prepare a tiny example, and what the qubit count leaves out.

Normalize before loading

Quantum states must have total probability one, so their amplitudes must have squared magnitudes that sum to one. For a real data vector, this means dividing by its Euclidean length. Consider v = [1, 2, 2, 0]. Its length is 3, so the encoded state is:

|psi> = (1/3)|00> + (2/3)|01> + (2/3)|10> + 0|11>

The four amplitudes live in the four computational basis states of two qubits. Measuring in that basis gives probabilities equal to the squared amplitudes: 1/9, 4/9, 4/9, and 0. The overall length of the original vector is not stored in the state. If that scale matters to an application, keep it separately.

Prepare the state in Qiskit

Qiskit provides StatePreparation for loading an amplitude vector into a circuit. The example normalizes v, prepares two qubits, then prints the resulting basis probabilities.

import numpy as np
from qiskit import QuantumCircuit
from qiskit.circuit.library import StatePreparation
from qiskit.quantum_info import Statevector

values = np.array([1, 2, 2, 0], dtype=float)
amplitudes = values / np.linalg.norm(values)

qc = QuantumCircuit(2)
qc.append(StatePreparation(amplitudes.tolist()), [0, 1])

state = Statevector.from_instruction(qc)
print(np.round(state.probabilities(), 6))

Expected output:

[0.111111 0.444444 0.444444 0.      ]

The hidden cost

Amplitude encoding can save qubits: an N-entry vector fits into about log2(N) qubits. But an arbitrary vector still has to be prepared. Generic state preparation can require work that grows with N, while special structure in the data can sometimes help. A small qubit count alone does not guarantee a faster end-to-end algorithm.

Readout also matters. A measurement gives one sample from the encoded probability distribution, not a list of all amplitudes. Recovering detailed information can take many shots, and relative signs or complex phases need measurements beyond a single computational-basis readout. Amplitude encoding is most useful when the later quantum computation can work with the encoded state without first extracting every entry again.

Further reading