Skip to content

【代码贡献】Add VQLS variational solver for linear systems#28

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

【代码贡献】Add VQLS variational solver for linear systems#28
mnn31 wants to merge 1 commit into
OriginQ:developfrom
mnn31:feature/vqls-linear-solver

Conversation

@mnn31

@mnn31 mnn31 commented Jul 13, 2026

Copy link
Copy Markdown

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.

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