Skip to content

About

HHL quantum linear solver for 4x4 systems in Qiskit, following the circuit of Cao et al.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Quantum Linear Solver (HHL)

A Qiskit implementation of the HHL algorithm for solving a 4x4 linear system A x = b. The circuit follows Cao et al., Quantum circuit design for solving linear systems of equations.

What the script does

quantum_linear_solver/quantum_linear_solver.py runs the whole pipeline:

  1. Defines a Hermitian 4x4 matrix A and a vector b, and normalises both by |b|.
  2. Computes the exact solution with NumPy for reference.
  3. Builds the HHL circuit: state preparation of |b>, phase estimation with controlled HamiltonianGates on a 4-qubit clock register, controlled RY rotations on an ancilla, and the inverse phase estimation.
  4. Runs 30,000 shots on the Aer simulator and keeps the shots where the ancilla is measured as 1.
  5. Rebuilds an approximate solution vector from those counts and compares it with the exact one.

The run uses r = 6 and t = 3π.

Output

Results are written to quantum_linear_solver/output/:

  • results.txt: exact solution, quantum solution, norm of the difference, raw counts
  • circuit.txt: text drawing of the full circuit
  • a histogram of the measured counts

In the committed run the quantum estimate is still far from the exact answer (norm of difference ≈ 0.83). The circuit structure is the main point of this repo. The rotation parameters r and t need tuning to get a closer match.

Run it

python -m venv .venv
source .venv/bin/activate
pip install qiskit qiskit-aer numpy matplotlib
python quantum_linear_solver/quantum_linear_solver.py

Reference

Y. Cao, A. Daskin, S. Frankel, S. Kais, Quantum circuit design for solving linear systems of equations, arXiv:1110.2232.

About

HHL quantum linear solver for 4x4 systems in Qiskit, following the circuit of Cao et al.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages