Code
qcr:2606.53797.1

HHL Linear Systems Algorithm

The Harrow-Hassidim-Lloyd (HHL) algorithm is a quantum routine for solving systems of linear equations of the form Ax = b, where A is a Hermitian matrix and b a known vector. Rather than returning the full solution vector classically, it prepares a quantum state proportional to the inverse of A applied to b, which can then be used to estimate expectation values or other linear functionals of the solution, offering an exponential speedup over classical solvers for suitable sparse, well-conditioned systems. This Cirq example implements the complete algorithm across three qubit registers: a single ancilla, an eigenvalue register, and a memory register that holds the input vector and ultimately the solution. It proceeds in the classic three stages: quantum phase estimation to write the eigenvalues of A into the register, a controlled rotation of the ancilla by an angle proportional to the inverse eigenvalue, and uncomputation via inverse phase estimation to disentangle the registers. The script constructs the circuit for a concrete Hermitian matrix and input vector, simulates it, and reports the expectation values of Pauli operators on the recovered solution state. It is an excellent worked example of how phase estimation and controlled rotations combine to perform linear algebra on a quantum computer.
Linear Algebra
Qubit
Circuit-based
Uploaded 3 days ago
17
Views
Citing this entry? Use this QCR ID
Uploaded by
QL
QCR Librarian

Overview

quantumlib/Cirq
49901228
README.md

HHL Linear Systems Algorithm

The Harrow-Hassidim-Lloyd (HHL) algorithm is a quantum routine for solving systems of linear equations of the form Ax = b, where A is a Hermitian matrix and b a known vector. Rather than returning the full solution vector classically, it prepares a quantum state proportional to the inverse of A applied to b, which can then be used to estimate expectation values or other linear functionals of the solution, offering an exponential speedup over classical solvers for suitable sparse, well-conditioned systems. This Cirq example implements the complete algorithm across three qubit registers: a single ancilla, an eigenvalue register, and a memory register that holds the input vector and ultimately the solution. It proceeds in the classic three stages: quantum phase estimation to write the eigenvalues of A into the register, a controlled rotation of the ancilla by an angle proportional to the inverse eigenvalue, and uncomputation via inverse phase estimation to disentangle the registers. The script constructs the circuit for a concrete Hermitian matrix and input vector, simulates it, and reports the expectation values of Pauli operators on the recovered solution state. It is an excellent worked example of how phase estimation and controlled rotations combine to perform linear algebra on a quantum computer.

Run it

pip install -r requirements.txt
python hhl.py

Source and license

Imported from examples/hhl.py in quantumlib/Cirq at v1.6.1, under the Apache License 2.0. Original authors: The Cirq Developers. The upstream LICENSE is included alongside this example.

Join the Discussion

Comments (0)

No comments yet. Be the first to share your thoughts!

Indexed by QCR Librarian

This entry was created automatically from publicly available records. QCR links to public sources and only stores repository content where the license permits redistribution.

Publication

doi:10.48550/arxiv.0811.3171
Quantum algorithm for solving linear systems of equations

Aram W. Harrow, Avinatan Hassidim, Seth Lloyd

Versions

v1 Latest
Jun 15, 2026
qcr:2606.53797.1

Cite all versions? Use the base QCR ID to always reference the latest version of this entry.

Tools used

Cirq

Keywords

hhl
linear-systems
phase-estimation
linear-algebra
quantum-speedup

You may also like5