【代码贡献】Add VQLS variational solver for linear systems#28
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.
Adds VQLS (variational quantum linear solver, Bravo-Prieto et al.) for solving
Ax = b with Hermitian A. It's the NISQ-style counterpart to the HHL module I
submitted in #21 — same problem, but no ancilla or clock register: a
hardware-efficient RY/CZ ansatz is trained to minimize the global cost
1 - |<b|A|x>|^2 / <x|A^2|x>. Relates to #13.
The implementation decomposes A into Pauli strings classically, then evaluates
the cost from circuits: the denominator via expval_pauli_operator on A^2 (built
with PauliOperator arithmetic), the numerator overlaps <b|P_l|x> by appending
the encoder circuit's dagger and reading the all-zeros amplitude, same trick
QSVR uses for its kernel overlaps. Optimizer is scipy (SLSQP default),
following how QAOA drives its parameters. Seeded initial parameters so runs
are reproducible.
Checked against numpy.linalg.solve: fidelity 1.0 on 2x2 and 4x4 systems
(diagonal and tridiagonal), final costs around 1e-12, deterministic across
repeat runs with the same seed. Non-convergence is loud: converged=False plus
a warning, never a silently wrong answer. One limitation, noted in the
docstring: the real RY ansatz only reaches real solution vectors, so
complex-Hermitian systems with complex solutions report low fidelity honestly
rather than converging.
Tests cover the solve cases, cost convergence, and input validation
(non-Hermitian and non-power-of-2 raise ValueError). There's a doctest on the
class matching the HHL doctest's example system.