View on GitHub
Open this notebook in GitHub to run it yourself
Quantum Matrix Inversion (or Quantum Linear Solver) via QSVT provides a framework for solving linear systems exponentially faster than known classical methods under certain conditions [1]. The algorithm employs a polynomial transformation of singular values to block-encode the inverse of a matrix, which can then be applied on a prepared quantum state to solve a linear equation. Given an efficient routine to embed the classical matrix as a quantum function (block-encoding), this algorithm gives a clean and optimal way to implement matrix inversion compared to other quantum methods. Quantum linear solvers based on block-encoding have many applications, e.g., in Plasma Physics and Fluid Dynamics.In this demo we will restrict ourselves to matrices of size , with . A generalization to arbitrary can be done by completing the matrix into a larger one, or modifying the QSVT routine to an arbitrary . We emphasize that compared to the basic HHL algorithm, the QSVT approach is not restricted to Hermitian matrices. The QSVT algorithm is based on the idea of block-encoding a matrix into a larger unitary: where is some scaling factor, which is sometimes necessary for this unitarity completion. Given an access to , matrix inversion with QSVT implements a block-encoding for the inverse of Subsequently, we can use this unitary to solve a linear system, , by applying it on an initially prepared state (the state identifies the block in which the matrix is encoded). Up to post-selection we have: In more detail, Singular Value Decomposition (SVD) of a matrix is defined by where and are unitary matrices, and is a diagonal matrix that contains the singular values of (The square root of the eigenvalues of ). A singular value polynomial transform refers to where is a polynomial with a well-defined parity. The QSVT routine allows to block-encode such singular value polynomial transforms, based on the Quantum Signal Processing (QSP) approach. For the case of matrix inversion, we have the identities, from which we can deduce that: Applying a QSVT of an odd polynomial that approximates , on the block-encoding of , gives the matrix inversion of . Below we demonstrate how to implement a quantum linear solver for a specific problem. As we will see, the input of the algorithm is block-encoding of the matrix , and its effective condition number , with being the minimal singular eigenvalue. Using theComplexity: Using QSVT, matrix inversion requires queries of the block-encoding unitary, where is the precision parameter. Typically, an efficient block-encoding scales as , resulting in an overall complexity for the QSVT linear solver. This improves exponentially in upon the original Harrow–Hassidim–Lloyd (HHL) algorithm, and exponentially in compared to classical linear solvers, while matching known lower bounds for quantum linear solvers [2]. (As with all quantum linear solvers, extracting the full solution state removes the speedup; the advantage arises when only global properties such as expectation values, overlaps, or samples are required.)
- Input: An matrix with condition number (the ratio between the maximal and minimal singular values), and a vector prepared as a quantum state.
- Promise: The matrix is well-conditioned (invertible, with bounded spectrum) and can be efficiently block-encoded in a unitary (see technical note at the end of this demo).
- Output: A quantum state proportional to , encoding the solution of the linear system .
Keywords: Linear systems, Quantum Singular Value Transformation (QSVT), Block encoding, Matrix inversion, Exponential speedup, Oracle/Query complexity.
qsvt_inversion function from the open-library and some classical auxiliary functions from our qsp application, allow to easily implement the algorithm, given those two inputs.
Example: Block-encoded matrix in a random unitary
Setting an Example
We start by defining a specific problem: a matrix, its block encoding, and its condition number. We take a very simple usecase: define a random unitary of size , taking its upper block as the block-encoded matrix that we want to invert.Output:
Block-encoding
Next, we define the quantum functions required for the algortihm. It is instructive to work with aQSrtuct to represent the quantum variable for the block-encoding.
block at state zero, which identify the block in which the matrix is encoded, and a function that block encodes our matrix.
(Recall that for inversion we shall block-encode . However, the qsvt_inversion function handles this internally, by passing the inverse ).
Output:
Finding QSVT angles for the approximated inverse function
We need to find a polynomial approximation to the function. Notice that the function is exploding as goes to 0, which breaks the rules for the existence of QSP polynomial, which must be bounded by 1 in . However, we can limit the polynomial to approximate only at the relevant range , i.e., in the interval that contains the singular values of the block-encoded matrix. The target function we need to approximate is thus: where as defined below, and a scaling factor of 1/2 was added to get an easier convergence for the corresponding QSVT angles. We can see that in the relevant range. According to Ref. [2], a degree of is sufficient to approximate with an error . Below, we use theqsp_approximate function to get the approximated polynomial.
This function approximates as a sum of Chebyshev polynomials, making sure the resulting polynomial is bounded by 1 in the entire range . Subsequently, we call the qsvt_phases to get the corresponding QSVT phases.

Output:
Solving a linear equation
Next, we solve an instance of a linear equation . For this, we define some arbitrary vector.Output:
qsvt_inversion with the parameters defining our specific problem:
Output:

qsvt_aux. Therefore, we need to post-select on qsvt_state.block and qsvt_aux being zero, if we want to obtain a state .
Note that the additional block qubit was already filtered as part of the execution call.
| qsvt_state.state | qsvt_state.block | qsvt_aux | amplitude | magnitude | phase | probability | bitstring | |
|---|---|---|---|---|---|---|---|---|
| 7 | 0 | 0 | 0 | -0.184047-0.225847j | 0.29 | -0.72π | 0.084880 | 0000 |
| 5 | 1 | 0 | 0 | -0.013748-0.016870j | 0.02 | -0.72π | 0.000474 | 0010 |
| 6 | 2 | 0 | 0 | -0.084568-0.103776j | 0.13 | -0.72π | 0.017921 | 0100 |
| 0 | 3 | 0 | 0 | 0.154944+0.190135j | 0.25 | 0.28π | 0.060159 | 0110 |
Comparing to the expected result
Finally, we verify our quantum solution, by comparing it to the expected classical one.