Skip to content

【代码贡献】Add HHL solver for linear systems (Ax=b)#21

Open
mnn31 wants to merge 1 commit into
OriginQ:developfrom
mnn31:feature/hhl-linear-solver
Open

【代码贡献】Add HHL solver for linear systems (Ax=b)#21
mnn31 wants to merge 1 commit into
OriginQ:developfrom
mnn31:feature/hhl-linear-solver

Conversation

@mnn31

@mnn31 mnn31 commented Jun 8, 2026

Copy link
Copy Markdown

Implements HHL for solving Ax = b. The package init already had a
commented-out # from . import HHL slot reserved, so this just fills it in.
Relates to #13.

HHL(A, b).run() returns the normalized solution for Hermitian A. Standard
pipeline: amplitude-encode b, QPE on A (Oracle(e^{iAt}) for the controlled
evolutions, the existing plugin.QFT for the inverse), controlled RY eigenvalue
inversion on an ancilla rotating by 2*arcsin(C/lambda), inverse QPE to uncompute
the clock, then post-select the ancilla on |1>. t and C default to values from
A's spectrum but you can override both.

Checked solutions against numpy.linalg.solve. Fidelity is 1.0 on the diagonal
cases and the well-conditioned 2x2s; the [[3,1],[1,2]] case sits at ~0.9999
because its eigenvalues don't land exactly on the clock grid at 4 qubits, which
is the usual HHL resolution thing and improves with more clock qubits. Noted
that in the docstring.

Tests in Test_HHL_HHL.py cover the above plus input validation (non-Hermitian
and non-power-of-2 sizes raise ValueError). There's a doctest on the class too.

One limitation: A has to be Hermitian for now. Non-Hermitian works via the usual
dilation trick but I left that out to keep the diff small.

@mnn31 mnn31 changed the title Add HHL solver for linear systems of equations 【代码贡献】Add HHL solver for linear systems (Ax=b) Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant