【代码贡献】Add HHL solver for linear systems (Ax=b)#21
Open
mnn31 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements HHL for solving Ax = b. The package init already had a
commented-out
# from . import HHLslot 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.