Amplitude Encoding
Overview
Amplitude encoding is the most compact quantum data encoding: it stores N classical values in just log2(N) qubits by encoding them as probability amplitudes of a quantum state. The compression is in qubit count only: preparing a general state costs O(2^n) gates and reading the amplitudes back costs many shots, so any speedup depends on how the data is loaded and what is measured.
The encoding maps a normalized vector [a0, a1, a2, a3] to the quantum state:
|psi> = a0|00> + a1|01> + a2|10> + a3|11>
The amplitudes must satisfy the normalization constraint: sum(|ai|^2) = 1.
Exponential Compression
The defining feature of amplitude encoding is logarithmic qubit scaling:
| Qubits | Values Encoded | Compression |
|---|---|---|
| 2 | 4 | 2x |
| 3 | 8 | 2.7x |
| 4 | 16 | 4x |
| 10 | 1,024 | 102x |
| 20 | 1,048,576 | 52,429x |
Qubit count grows only logarithmically with the data size; whether a whole algorithm is faster depends on state preparation and readout costs (see below).
The Circuit
Using Qiskit's initialize (automatic decomposition)
PYTHONqc = QuantumCircuit(2) qc.initialize([a0, a1, a2, a3], [0, 1]) # Qiskit handles decomposition
Manual Decomposition (Mottonen method)
CODE┌─────────┐ ┌─────────┐ q_0: ───────────────┤ Ry(θ0x) ├─────┤ Ry(θ1x) ├ ┌────────┐┌───┐└────┬────┘┌───┐└────┬────┘ q_1: ┤ Ry(θ1) ├┤ X ├─────■─────┤ X ├─────■───── └────────┘└───┘ └───┘
- RY(theta1) on qubit 1: Splits amplitude between |0x> and |1x> subspaces, with theta1 = 2 arccos(sqrt(a0^2 + a1^2))
- X + CRY + X (qubit 1 controls qubit 0, flipped so it fires when qubit 1 is 0): Within |0x>, distributes between |00> and |01>, with theta0x = 2 arccos(a0 / sqrt(a0^2 + a1^2))
- CRY (qubit 1 controls qubit 0): Within |1x>, distributes between |10> and |11>, with theta1x = 2 arccos(a2 / sqrt(a2^2 + a3^2))
create_amplitude_encoding_manual builds exactly this circuit. For non-negative data such as [1, 2, 3, 4] it reproduces the target amplitudes exactly: compared with Qiskit's initialize on the exact simulator statevector, for [1, 2, 3, 4] and 200 random non-negative vectors, the largest probability error was below 1e-15 and the fidelity was 1. For data with negative values the probabilities still match, but a negative a1 or a3 comes out positive (the circuit prepares [a0, |a1|, a2, |a3|]), because each half-angle comes from arccos.
Encoding Example
Data: [1, 2, 3, 4]
Normalized: [0.1826, 0.3651, 0.5477, 0.7303]
Measurement probabilities:
| State | Amplitude | Probability |
|---|---|---|
| |00> | 0.1826 | 3.3% |
| |01> | 0.3651 | 13.3% |
| |10> | 0.5477 | 30.0% |
| |11> | 0.7303 | 53.3% |
Running the Circuit
PYTHONfrom circuit import ( run_circuit, create_amplitude_encoding, create_amplitude_encoding_manual, normalize_data, verify_encoding, ) # Encode and measure result = run_circuit(data=[1.0, 2.0, 3.0, 4.0]) print(f"Normalized: {result['normalized_amplitudes']}") print(f"Measured: {result['measured_probs']}") # Manual decomposition (explicit RY, CRY and X gates); for non-negative # data it prepares the same state as initialize qc = create_amplitude_encoding_manual([1.0, 2.0, 3.0, 4.0]) # Verify encoding correctness. The manual-decomposition check compares the # exact statevector with a 1e-9 tolerance, so a wrong decomposition fails v = verify_encoding(data=[1.0, 2.0, 3.0, 4.0]) print(f"All checks passed: {v['passed']}")
State Preparation Cost
The tradeoff for exponential compression is state preparation complexity:
| Method | Depth | Gates | Notes |
|---|---|---|---|
| General (Mottonen) | O(2^n) | O(2^n) | Exact, but expensive |
| Approximate (qRAM) | O(poly(n)) | O(poly(n)) | Requires quantum RAM |
| Special structure | O(poly(n)) | O(poly(n)) | Exploits data patterns |
For small datasets (2-4 qubits), exact preparation is practical. For larger datasets, approximate methods or structured data are needed.
Advantages
- Exponential compression: N values in log2(N) qubits
- Natural for QML: Feature vectors map directly to quantum states
- Linear-algebra access: One gate acts on all 2^n amplitudes at once, but a measurement returns a single sample, so useful output needs interference and repeated runs
- Inner product access: Overlap between encoded states gives similarity
Challenges
- State preparation cost: General preparation is O(2^n) gates
- Readout bottleneck: Extracting all amplitudes requires O(2^n) shots
- Normalization requirement: Data must be L2-normalized
- No classical readout shortcut: Cannot efficiently extract arbitrary amplitudes
Comparison with Other Encodings
| Encoding | Qubits for N values | Depth | Readout |
|---|---|---|---|
| Amplitude | log2(N) | O(N) | Hard |
| Angle | N | O(1) | Easy |
| Basis | N | O(1) | Easy |
| Dense Angle | N/2 | O(1) | Easy |
Applications
- Quantum machine learning: Feature vector encoding for QML algorithms
- Quantum simulation: Initial state preparation for Hamiltonian simulation
- Quantum search: Oracle input preparation for Grover's algorithm
- Quantum linear algebra: Loading data for HHL and related algorithms
Learn More
- Supervised Learning with Quantum Computers (Schuld & Petruccione, 2018)
- Transformation of Quantum States Using Uniformly Controlled Rotations (Mottonen et al., 2005)
- Quantum Embeddings for Machine Learning (Lloyd et al., 2020)