Quantum Linear Systems
The HHL algorithm (Harrow-Hassidim-Lloyd, 2009) solves linear systems on a quantum computer:
- Encode as a quantum state
- Use quantum phase estimation to find eigenvalues of
- Apply controlled rotations to encode
- Uncompute to obtain
Complexity: where is the condition number and is the precision.
This provides exponential speedup over classical for sparse systems.
Quantum Phase Estimation for Eigenvalues
Quantum phase estimation (QPE) extracts eigenvalues of a unitary :
- Prepare eigenstate with eigenvalue
- Apply controlled- operations
- Inverse QFT to extract
The eigenvalue is encoded in the ancilla register with precision using ancilla qubits.
HHL Algorithm Detail
The HHL algorithm steps:
- Encode in QPE register
- QPE extracts eigenvalues into ancilla register
- Controlled rotation:
- Uncompute QPE to disentangle ancilla
- Measure ancilla: if , remaining register is
The algorithm requires qubits and gates for sparse .
Limitations of HHL
HHL limitations:
- Input encoding: preparing may be as hard as solving
- Output encoding: result is in quantum state, not classical vector
- Sparsity requirement: must be efficiently implementable as Hamiltonian
- Condition number: runtime scales as
- Non-sparse matrices: not applicable for dense matrices
These limitations mean HHL is not a universal speedup for linear systems.
Variational Quantum Linear Solver
Variational quantum linear solver (VQLS) addresses HHL limitations:
- Prepare ansatz
- Minimize
- Use hybrid quantum-classical optimization
Advantages: no input encoding requirement, NISQ-compatible, no phase estimation needed.
The catch sits in the cost function. Evaluating on hardware means measuring overlaps, and the standard construction uses a Hadamard test with an ancilla to estimate the real and imaginary parts of , which costs several circuit evaluations per term of written as a sum of Pauli strings. A matrix with non-zero Pauli coefficients therefore needs circuits per cost evaluation, and more for each parameter-shift gradient step. Choose an ansatz whose depth grows slowly with , keep the observable local, and treat the number of cost evaluations as a budgeted resource: 500 parameters at 1,000 shots each is half a million circuit executions per gradient descent step.
Quantum Algorithms for Differential Equations
Quantum algorithms for ODEs/PDEs:
- Hamiltonian simulation: evolve
- Linear systems: solve for differential operators
- Variational methods: parameterized circuits for PDE solutions
The Schrodinger equation is naturally quantum, giving exponential speedup for quantum simulations.
Python: HHL Simulation
import numpy as np
def hhl_simulation(A, b):
# Simplified HHL algorithm simulation.
# Classical simulation of HHL
# 1. Diagonalize A
eigenvalues, eigenvectors = np.linalg.eigh(A)
# 2. Express b in eigenbasis
b_eig = eigenvectors.conj().T @ b
# 3. Invert eigenvalues (with regularization)
epsilon = 1e-10
inv_eigenvalues = np.where(np.abs(eigenvalues) > epsilon, 1/eigenvalues, 0)
# 4. Compute x in eigenbasis
x_eig = inv_eigenvalues * b_eig
# 5. Transform back
x = eigenvectors @ x_eig
return x
# Test: solve Ax = b
A = np.array([[2, 1], [1, 3]], dtype=complex)
b = np.array([1, 0], dtype=complex)
x = hhl_simulation(A, b)
print(f"Ax = {A @ x}")
print(f"b = {b}")
print(f"Error: {np.linalg.norm(A @ x - b):.2e}")
Why HHL Needs Thousands of Repetitions
The controlled rotation prepares , and must satisfy for every eigenvalue that can appear, which forces . The ancilla therefore ends in with probability averaged over the components of , and any run that lands in is discarded and repeated. For a matrix with condition number , that success probability is about in the worst case, so obtaining a single sample of already costs attempts before precision is considered. This is the origin of the factor in every published HHL runtime.
Precision costs qubits the same way. Resolving each eigenvalue to needs ancilla qubits, and each of the controlled powers adds another phase-estimation round. Worked together: 6 ancilla qubits give 6-bit eigenvalue resolution, and a problem with then demands roughly 10,000 repetitions of the full circuit to collect statistics. On a fault-tolerant machine that is ordinary arithmetic; on today's devices it is far out of reach.
Worked Example: A 2Ã2 System End to End
Take A = [[4, 1], [1, 3]] with b = [1, 2]. The exact solution is , so and â a concrete target for checking any simulation of a linear solver. The eigenvalues are , that is 4.618 and 2.382, giving : an easy problem by any measure. Now swap the diagonal for [1000, 0] and [0, 1.001] and the same pipeline faces , which squares into about a million circuit repetitions. The conditioning of the matrix, not its size, dominates the cost â and it is the first quantity to estimate before anyone claims a quantum advantage for a linear system.
import numpy as np
def condition_number(A):
s = np.linalg.svd(A, compute_uv=False)
return s[0] / s[-1]
def hhl_resources(n, kappa, eps):
# ancilla qubits needed for eigenvalue precision 2^-eps,
# plus the expected number of repetitions from post-selection
ancilla = int(np.ceil(np.log2(n))) + int(np.ceil(-np.log2(eps)))
return ancilla, int(np.ceil(kappa ** 2))
A = np.array([[4.0, 1.0], [1.0, 3.0]])
b = np.array([1.0, 2.0])
x = np.linalg.solve(A, b)
print(f"x = {x}, residual = {np.linalg.norm(A @ x - b):.2e}")
print(f"condition number = {condition_number(A):.3f}")
for eps in [1e-2, 1e-4, 1e-8]:
ancilla, repeats = hhl_resources(2 ** 14, 100, eps)
print(f"N=2^14, kappa=100, eps={eps:.0e} -> {ancilla} ancillas, {repeats:,} repeats")
The residual printed for the 2Ã2 system is at machine precision, which is exactly what HHL does not deliver: its answer is a quantum state that must be sampled, so the classical comparison is between expectation values, not between two printed vectors.
Classical Baselines to Beat
A quantum linear-solver claim only matters relative to a tuned classical method:
| Problem shape | Classical method | Cost | When a quantum speedup is plausible |
|---|---|---|---|
| Dense | LU factorization | time, memory | Only at very large , and only if loading the matrix is free |
| Sparse, positive definite | Conjugate gradient | iterations | When is enormous and matrix-vector products are cheap |
| Sparse, matrix-free | GMRES or multigrid | Problem dependent | Rarely; multigrid is already optimal for many PDE discretizations |
| Parameterized family | Reduced-order models | Linear in family size | When the family is exponentially large and structure is known |
Conjugate gradient deserves particular attention, because it converges in iterations rather than , so an HHL-style method has to beat that bar rather than a naive baseline. An honest accounting must also price the classical work of preparing and of reading the answer out of the register â both exponential in the worst case, and both routinely omitted from speedup diagrams.
When Quantum Numerical Methods Earn Their Place
Three cases survive the comparison. First, when the matrix is given as a quantum oracle rather than as classical data â a Hamiltonian you can simulate but cannot write down entry by entry â the input problem disappears and only the output bottleneck remains. Second, when the quantity of interest is a single expectation value rather than a full vector, because estimating one number needs far fewer samples than tomography. Third, when the matrix family is exponentially large and the target application tolerates sampling error, for example screening molecular geometries where each candidate only needs an energy to a fixed absolute accuracy. Outside those cases the classical column of the table above wins, and it will keep winning until fault tolerance removes the repetition overhead entirely.
Common Mistakes
Quoting the HHL runtime without the post-selection repetitions
Fix: Include the kappa-squared factor that comes from the ancilla success probability, not just the phase-estimation gate count
Claiming a speedup against a naive matrix-vector product
Fix: Compare against conjugate gradient or multigrid, which already reach near-optimal complexity for the same problem class
Ignoring the cost of loading the right-hand side into a quantum state
Fix: State explicitly whether preparing the input state is assumed free, and price the data-access model in the comparison
Expecting HHL to print a solution vector
Fix: The output is a quantum state; extract expectation values or amplitudes with enough samples, and compare those against classical expectations
Key Takeaways
- HHL solves sparse linear systems by combining quantum phase estimation, a controlled rotation by the inverse eigenvalue, and uncomputation
- Post-selection forces a success probability near 1/kappa squared, which is where the headline kappa-squared runtime factor comes from
- Preparing and reading out quantum states remain the two bottlenecks that classical algorithms do not pay
- VQLS replaces phase estimation with a variational loop, trading circuit depth for many cost-function evaluations
- Conjugate gradient and multigrid are the classical bars any quantum linear-solver claim must clear, not the naive O(n) baseline