View on GitHub
Open this notebook in GitHub to run it yourself
- The resulting linear equation reads:

In this notebook we solve the Poisson problem with the HHL quantum linear solver. We utilize similar ideas appearing in Ref.[2], where a quantum cosine and a quantum sine transforms [3] are performed towards achieving scalable implementation.
Building the Algorithm with Classiq
The HHL algorithm essentially applies a matrix inversion. Here we treat the Laplacian matrix, which can be diagonalized by quantum sine and cosine transforms. Thus, the matrix to invert is diagonal. The four main quantum blocks of the algorithm are thus (see Figure 2):- Prepare the amplitudes of the source term on a quantum variable.
- Perform QST and QCT at the beginning of the computation.
- Perform matrix inversion for a diagonal matrix.
- Uncompute the QST and QCT at the end of the computation.

Diagonal Hamiltonian Calculation
The eigenvalues of the Poisson equation with Dirichlet boundary conditions in the x direction and Neumann boundary conditions in the y direction are given by where and and . The HHL algorithm requires the application of an Hamiltonian simulation . In this notebook this quantum block is implemented using the Suzuki-Trotter built-in function. We start with defining a function that gets and and returns the corresponding Hamiltonian. The decomposition of the diagonal matrix to the Pauli basis is done using the Walsh Hadamard transform.Hamiltonian Evolution for QPE
The HHL is based on a QPE applied on . For this, we need to define a function implementing for an integer power . Since in our case the Hamiltonian is diagonal, an exact implementation is given by the first order Suzuki-Trotter formula, where in addition .Sine and Cosine Transforms
For the system treated in this notebook, diagonalization of the Laplacian is given by appying a quantum sine (cosine) transform on the () dimension. We define a quantum function for implementing this, using the open library functions:Matrix Inversion
Finally, we define a matrix inversion using a QPE routine, similar to the example given in the basic HHL notebook.Example: Non-separable Source Term
We solve an example with a square grid of . For the source term we take a non-separable vector that represents the function We choose , which satisfies the boundary conditions.
QArray[QNum,2]. In the more general case one can define a QStruct with two QNum variable of different sizes
Output:
Executing and Plotting the Result
We run the quantum program on a statevector simulator to retrieve the full solution.