Quantum Linear Algebra · Chapter 1

Block Encoding

Quantum computers can only apply unitary (reversible, norm-preserving) operations, yet most useful matrices in linear algebra are not unitary. Block encoding is the trick that gets around this: you hide the matrix \(A\) you care about as one corner block of a bigger unitary \(U_A\), run \(U_A\) on a quantum computer, and recover \(A\ket{b}\) by measuring a few extra "ancilla" qubits. This chapter builds the idea from scratch and shows concrete circuits for encoding unitaries, density matrices, Gram matrices, and sparse matrices.

≈ 30 min read8 worked examplesOriginal PDF ↗

1.1 Motivation

In this section we describe a generic toolbox for implementing matrix calculations on a quantum computer in an operational way, representing the vectors as quantum states. The matrix arithmetic methodology proposed carries out all calculations in an operational way, such that the matrices are represented by blocks of unitary operators of the quantum system, and thereby can in principle result in exponential speedups — in terms of the dimension of the matrices.

Here the results are presented in an intuitively structured way. First we define how to represent arbitrary matrices as blocks of unitaries, and show how to efficiently encode various matrices this way.

In quantum algorithms, the quantum gates that are applied to quantum states are necessarily unitary operations. However, one often needs to apply a linear transformation to some encoded data that is not represented by a unitary operator, and furthermore one generally needs coherent access to these non-unitary transformations. How can we encode such a non-unitary transformation within a unitary operator? Block-encoding works by embedding the desired linear operator as a suitably normalized block within a larger unitary matrix, such that the full encoding is a unitary operator, and the desired linear operator is given by restricting the unitary to an easily recognizable subspace. To be useful for quantum algorithms, this block encoding must also be realized by some specific quantum circuit acting on the main register and additional ancilla qubits.

Block-encodings are ubiquitous within quantum algorithms; they have both benefits and drawbacks. They are easy to work with, since one can efficiently perform manipulations of block encodings, such as taking products or convex combinations. On the other hand, this improved working efficiency comes at the cost of having more limited access. For example, if a matrix is stored in classical random access memory, the matrix entries can be explicitly accessed with a single query to the memory, whereas if one only has access to a block-encoding of the matrix, estimating a matrix entry to precision \(\epsilon\) requires \(\mathcal{O}(1/\epsilon)\) uses of the block-encoding unitary in general (by using the amplitude estimation subroutine).

Block-encodings also provide a layer of abstraction that assists in the design and analysis of quantum algorithms. One can simply assume access to a block-encoding and count the number of times it is applied. To run the algorithm, it is necessary to choose a method for implementing the block-encoding. There are many ways of constructing block-encodings that could be suited to the structure of the input. For instance, there are efficient block-encoding strategies for density matrices, positive operator-valued measures (POVMs), Gram matrices, sparse-access matrices, matrices that are stored in quantum data structures, structured matrices, and operators given as a linear combination of unitaries (with a known implementation). We discuss these constructions below. For unstructured, dense matrices, the strategy from Gram matrices can be instantiated using state-preparation and quantum random access memory (QRAM) as subroutines.

The one-sentence summary: gates must be unitary, but the matrices we want to use usually aren't. So we sneak the matrix into the top-left corner of a bigger unitary, apply that unitary, and post-select on the ancilla qubits reading zero. That post-selection is what "restricts the unitary to an easily recognizable subspace" means in practice.

1.2 Introduction

In order to perform matrix computations, we must first address the problem of the input model: how do we get access to information in a matrix \(A\in \mathbb{C}^{N \times N}\) (\(N=2^n\)), which is generally a non-unitary matrix, into the quantum computer? One possible input model is given via the unitary \(e^{\iota \tau A}\) (if \(A\) is not Hermitian, in some scenarios we can consider its Hermitian version via the dilation method).

Many standard linear algebra problems can be solved on a quantum computer using recently developed quantum linear algebra algorithms that make use of block encodings and quantum eigenvalue / singular value transformations.

A block encoding embeds a properly scaled matrix of interest \(A\) in a larger unitary transformation \(U\) that can be decomposed into a product of simpler unitaries and implemented efficiently on a quantum computer. Although quantum algorithms can potentially achieve exponential speedup in solving linear algebra problems compared to the best classical algorithm, such a gain in efficiency ultimately hinges on our ability to construct an efficient quantum circuit for the block encoding of \(A\), which is difficult in general, and not trivial even for well-structured sparse matrices. In this chapter, we talk about how efficient quantum circuits can be explicitly constructed for some well-structured sparse matrices and discuss a few examples and strategies used in these constructions.

In recent years, a new class of quantum algorithms has been developed to solve standard linear algebra problems on quantum computers. These algorithms use the technique of block encoding, to embed a properly scaled matrix \(A\) of interest in a larger unitary matrix \(U_A\) applied to a carefully prepared initial state and performing measurements on a subset of qubits. Furthermore, if \(A\) is Hermitian, by using the technique of the quantum eigenvalue transformation, one can block encode a certain matrix polynomial \(p(A)\) by another unitary \(U_{p(A)}\) efficiently using \(U_A\) as the building block. This procedure can be generalized to non-Hermitian matrices \(A\) using a technique called singular value transformation. The larger unitary \(U_{p(A)}\) can be decomposed into a product of simpler unitaries consisting of \(2\times 2\) single-qubit unitaries, multi-qubit controlled-NOTs, \(U_A\) and its Hermitian conjugate. Because approximate solutions to many large-scale linear algebra problems such as linear systems of equations, least squares problems and eigenvalue problems (produced by iterative methods) can often be expressed as \(p(A)v_0\) for some initial vector \(v_0\), the possibility to block encode \(p(A)\) will enable us to solve these problems on a quantum computer that performs unitary transformations.

In order to implement these quantum linear algebra algorithms, we need to further express the block encoding matrix \(U_A\) as a product of simpler unitaries, i.e. we need to express \(U_A\) as an efficient quantum circuit. Although it is suggested that such a quantum circuit can be constructed in theory for certain sparse matrices, the proposed construction relies on the availability of an "oracle" that can efficiently block encode both the nonzero structure of \(A\) and the numerical values of the nonzero matrix elements. However, for a general sparse matrix \(A\), finding these "oracles" is entirely non-trivial. Even for sparse matrices that have a well-defined non-zero structure and a small set of nonzero matrix elements, encoding the structure and matrix elements by an efficient quantum circuit is not an easy task.

In this chapter, we provide a few accessible examples of how to explicitly construct efficient quantum circuits for some well-structured sparse matrices. In particular, we give some general strategies for writing down the oracles for the non-zero structure and non-zero matrix elements of those matrices. In addition we will also provide circuit diagrams and show how these circuits can be easily constructed using Python Qiskit.

The block encoding of \(A\) is not unique. We will show a few different encoding schemes and the corresponding quantum circuits. For a sparse matrix \(A\) that has at most \(s\) nonzero elements per column, which we refer to as an \(s\)-sparse matrix, the general strategies we use to construct a quantum circuit actually block encode \(A/s\). For many applications, the extra scaling factor does not introduce significant issues.

1.3 Query model for matrix entries

The query model for sparse matrices is based on certain quantum oracles. In some scenarios, these quantum oracles can be implemented all the way to the elementary gate level. Throughout the discussion we assume \(A\) is an \(n\)-qubit, square matrix, and

\[ \|A\|_{max}=\max_{ij}|A_{ij}|\lt 1 \]

If \(\|A\|_{max}\geq 1\), we can simply consider the rescaled matrix \(\tilde{A}/\alpha\) for some \(\alpha\gt\|A\|_{max}\). To query the entries of a matrix, the desired oracle takes the following general form

\[ O_A\ket{0}\ket{i}\ket{j}=\left(A_{ij}\ket{0}+\sqrt{1-|A_{ij}|^2}\ket{1}\right)\ket{i}\ket{j} \]

In other words, given \(i,j\in[N]\) and a signal bit \(0\), \(O_A\) performs a controlled rotation (controlling on \(i,j\)) of the signal bit, which encodes the information in terms of the amplitude of \(\ket{0}\).

However, the classical information in \(A\) is usually not stored natively in terms of such an oracle \(O_A\). Sometimes it is more natural to assume that there is an oracle

\[ \tilde{O}_A\ket{0^{d'}}\ket{i}\ket{j}=\ket{\tilde{A}_{ij}}\ket{i}\ket{j} \]

where \(\tilde{A}_{ij}\) is a \(d'\)-bit fixed point representation of \(A_{ij}\), and the value of \(\tilde{A}_{ij}\) is either computed on the fly with a quantum computer, or obtained through an external database. In either case, the implementation of \(\tilde{O}_A\) may be challenging, and we will only consider the query complexity with respect to this oracle.

Using classical arithmetic operations, we can convert this oracle into an oracle

\[ {O'}_A\ket{0^d}\ket{i}\ket{j}=\ket{\tilde{\theta}_{ij}}\ket{i}\ket{j} \]

where \(0\leq \tilde{\theta}_{ij}\lt 1\), and \(\tilde{\theta}_{ij}\) is a \(d\)-bit representation of \(\theta_{ij}=\arccos(A_{ij})/\pi\). This step may require some additional work registers not shown here.

Now using the controlled rotation, the information of \(\tilde{A}_{ij}\), \(\tilde{\theta}_{ij}\) has now been transferred to the phase of the signal bit. We should then perform uncomputation and free the work register storing such intermediate information \(\tilde{A}_{ij}\), \(\tilde{\theta}_{ij}\). The procedure is as follows:

\[\begin{aligned} \ket{0}\ket{0^d}\ket{i}\ket{j}&\xrightarrow{O'_A}\ket{0}\ket{\tilde{\theta}_{ij}}\ket{i}\ket{j}\\ &\xrightarrow{CR}\left(A_{ij}\ket{0}+\sqrt{1-|A_{ij}|^2}\ket{1}\right)\ket{\tilde{\theta}_{ij}}\ket{i}\ket{j}\\ &\xrightarrow{(O'_A)^{-1}}\left(A_{ij}\ket{0}+\sqrt{1-|A_{ij}|^2}\ket{1}\right)\ket{0^d}\ket{i}\ket{j} \end{aligned}\]

From now on, we will always assume that the matrix entries of \(A\) can be queried using the phase oracle \(O_A\) or its variants.

1.4 Block Encoding

Block encoding is a technique for embedding a properly scaled nonunitary matrix \(A \in \mathbb{C}^{N\times N}\) into a unitary matrix \(U_A\). Note that by a properly scaled \(A\), we mean that \(A\) is scaled to satisfy \(\|A\|_2=\sigma_{max} \leq 1\). Without such a scaling, a block encoding of \(A\) may not exist because the singular values of any submatrix blocks of a unitary matrix must be bounded by \(1\). Furthermore, if there are some constraints on the type of unitary it can construct — e.g. the type of quantum gates available on a quantum computer — we may not be able to find \(U_A\) that block encodes \(A\) exactly. In this chapter, we assume that \(A\) has already been properly scaled, and there are no constraints on the quantum gates we can use to construct a quantum circuit representation of the unitary matrix \(U_A\).

The simplest example of block encoding is the following: assume we can find an \((n+1)\)-qubit unitary \(U\) (i.e. \(U\in\mathbb{C}^{2N \times 2N}\)) such that

\[ U_A=\begin{bmatrix}A & * \\ * & * \end{bmatrix} \]

Here \(*\) means that the corresponding entries are irrelevant (yet to be determined). Then for any \(n\)-qubit quantum state \(\ket{b}\), we can consider the state

\[ \ket{0,b}=\ket{0}\ket{b}=\begin{bmatrix}b \\ 0 \end{bmatrix} \]

and

\[ U_A\ket{0,b}=\begin{bmatrix}Ab\\ * \end{bmatrix}=\ket{0}A\ket{b}+\ket{1}\ket{*} \]

Here the unnormalized state \(\ket{\perp}=\ket{1}\ket{*}\) can be written as \(\ket{1}\ket{\psi}\) for some unnormalized state \(\ket{\psi}\), that is irrelevant to the computation of \(A\ket{b}\). In particular, it satisfies the orthogonality relation

\[ (\bra{0}\otimes I_n)\ket{\perp}=0 \]

In order to obtain \(A\ket{b}\), we need to measure qubit \(0\) and only keep the state if it returns \(0\). This can be summarised into the following quantum circuit.

|0⟩ ──────────╭──────╮────── M
              │      │
              │  U_A │
|b⟩ ──────────╰──────╯──────  A|b⟩ / ‖A|b⟩‖   (upon measuring 0)
Figure — Circuit for block encoding \(A\) using one ancilla qubit. Applying \(U_A\) to \(\ket{0}\ket{b}\) and measuring the top qubit as \(0\) leaves the bottom register in the normalized state \(A\ket{b}/\|A\ket{b}\|\).

Note that the output state is normalized after the measurement takes place. The success probability of obtaining \(0\) from the measurement can be computed as

\[ p(0)=\|A\ket{b}\|^2=\braket{b|A^{\dagger}A|b} \]

So the missing information of the norm \(\|A\ket{b}\|\) can be recovered via the success probability \(p(0)\) if needed. We find that the success probability is only determined by \(A\ket{b}\), and is independent of other irrelevant components of \(U_A\).

Note that we may not need to restrict the matrix \(U_A\) to be an \((n+1)\)-qubit matrix. If we can find any \((n+m)\)-qubit matrix \(U_A\) so that

\[ U_A=\begin{bmatrix} A & * & \ldots & * \\ * & * & \ldots & * \\ \vdots & \vdots & \vdots & \vdots \\ * & * & \ldots & * \end{bmatrix} \]

Here each \(*\) stands for an \(n\)-qubit matrix, and there are \(2^m\) block rows/columns in \(U_A\). The relation above can be written compactly using the braket notation as

\[ A=(\bra{0^m}\otimes I_n)U_A(\ket{0^m}\otimes I_n) \]

since \(\bra{0^m}\otimes I_n\) will be a block row vector with the identity matrix (of size \(2^n \times 2^n\)) at the first entry and \(0\) everywhere else. Similarly, \(\ket{0^m} \otimes I_n\) will be a block column vector with the identity matrix at the first entry and \(0\) everywhere else. Thus, the above expression can be thought of as being simplified to

\[ \bra{0^m}\otimes I_n=\begin{bmatrix} 1 & 0 & \ldots & 0\end{bmatrix} \otimes \begin{bmatrix} 1 & 0 & \ldots & 0 \\ 0 & 1 & \ldots & 0 \\ \vdots & \vdots & \ddots & 0 \\ 0 & 0 & \ldots & 1 \end{bmatrix}=\begin{bmatrix} I_n & 0 & 0 & \ldots & 0 \end{bmatrix} \]

where \(I_n\) is the \(n\)-qubit identity matrix of size \(2^n\times 2^n\) and \(0\) indicates block matrices of size \(2^n \times 2^n\) with all entries \(0\). Thus, \(\bra{0^m}\otimes I_n\) is a matrix of size \(2^n \times 2^{n+m}\). Similarly for \(\ket{0^m} \otimes I_n\), we get

\[ \ket{0^m}\otimes I_n=\begin{bmatrix} 1 \\ 0 \\ \vdots \\ 0\end{bmatrix} \otimes \begin{bmatrix} 1 & 0 & \ldots & 0 \\ 0 & 1 & \ldots & 0 \\ \vdots & \vdots & \ddots & 0 \\ 0 & 0 & \ldots & 1 \end{bmatrix}=\begin{bmatrix} I_n \\ 0 \\ 0 \\ \vdots \\ 0 \end{bmatrix} \]

Thus, on putting it all together we get

\[ (\bra{0^m}\otimes I_n)U_A(\ket{0^m}\otimes I_n)=\begin{bmatrix} I_n & 0 & 0 & \ldots & 0 \end{bmatrix}U_A\begin{bmatrix} I_n \\ 0 \\ 0 \\ \vdots \\ 0 \end{bmatrix}=A \]

The above expression can be thought of as simply picking the first \(n\) columns of \(U_A\) and then the first \(n\) rows. A necessary condition for the existence of \(U_A\) is \(\|A\| \leq 1\). (Note: \(\|A\|_{max}\leq 1\) does not guarantee that \(\|A\|\leq 1\).) However, if we can find a sufficiently large \(\alpha\) and \(U_A\) so that

\[ A/\alpha = (\bra{0^m}\otimes I_n)U_A(\ket{0^m}\otimes I_n) \]

then, measuring the \(m\) ancilla qubits and given that all \(m\) qubits return \(0\), we still obtain the normalized state \(\frac{A\ket{b}}{\|A\ket{b}\|}\). The number \(\alpha\) is hidden in the success probability:

\[ p(0^m)=\frac{1}{\alpha^2}\|A\ket{b}\|^2=\frac{1}{\alpha^2}\braket{b|A^{\dagger}A|b} \]

So if \(\alpha\) is chosen to be too large, the probability of obtaining all \(0\)s from the measurement can be vanishingly small.

Why the scaling factor \(\alpha\)? A unitary never stretches a vector, so any block sitting inside it must have norm at most \(1\). If your matrix is "too big", you shrink it by \(\alpha\) first. The price is paid at measurement time: the bigger \(\alpha\), the rarer the all-zero ancilla outcome, so you have to run the circuit more times to succeed.

Our goal is to build a unitary operator that gives coherent access to an \(M \times M\) matrix \(A\) (we will later relax the assumption that \(A\) is square), with normalization \(\alpha\geq \|A\|\), where \(\|A\|\) denotes the spectral norm of \(A\). As the name suggests, block encoding is a way of encoding the matrix \(A\) as a block in a larger unitary matrix:

\[ U_A = \begin{bmatrix} A/\alpha & * \\ * & * \end{bmatrix} \]

More precisely, we say that the unitary \(U_A\) is an \((\alpha,a,\epsilon)\)-block-encoding of the matrix \(A\in \mathbb{C}^{M\times M}\) if

\[ \|A-\alpha(\bra{0}^{\otimes a}\otimes I)U_A(\ket{0}^{\otimes a}\otimes I)\|\leq \epsilon \]

where \(a\in\mathbb{N}\) is the number of ancilla qubits used for embedding the block-encoded operator, and \(\alpha,\epsilon\in\mathbb{R}_{+}\) define the normalization and error, respectively. Note that \(\alpha\geq \|A\|-\epsilon\) is necessary for \(U_A\) to be unitary. This can be shown using two facts: that \((\bra{0}^{\otimes a}\otimes I)U_A(\ket{0}^{\otimes a}\otimes I)\leq 1\) since it is an embedding in the top-left block of the unitary \(U_A\), and using the property of norms that \(\|A+B\|\leq\|A\|+\|B\|\). Given

\[\begin{aligned} \|A-\alpha (\bra{0}^{\otimes a}\otimes I)U_A(\ket{0}^{\otimes a}\otimes I)\| &\leq \epsilon \end{aligned}\]

let \(\widetilde{A} =(\bra{0}^{\otimes a}\otimes I)U_A(\ket{0}^{\otimes a}\otimes I)\). Dividing by the positive real scalar \(\alpha\) on both sides of the inequality we get

\[ \left\|\frac{A}{\alpha} - \frac{\widetilde{A}}{\alpha}\right\|\leq \frac{\epsilon}{\alpha} \]

Now, using the inequality \(\|\frac{\widetilde{A}}{\alpha}\|\leq 1\), and adding this inequality on both sides we get

\[ \left\|\frac{\widetilde{A}}{\alpha}\right\|+\left\|\frac{A}{\alpha} - \frac{\widetilde{A}}{\alpha}\right\|\leq 1+\frac{\epsilon}{\alpha} \]

Now, using the property that \(\|A+B\|\leq \|A\|+\|B\|\), we get

\[\begin{aligned} \left\|\frac{\widetilde{A}}{\alpha}+\frac{A}{\alpha} - \frac{\widetilde{A}}{\alpha}\right\|\leq \left\|\frac{\widetilde{A}}{\alpha}\right\|+\left\|\frac{A}{\alpha} - \frac{\widetilde{A}}{\alpha}\right\| &\leq 1+\frac{\epsilon}{\alpha}\\ \implies \left\|\frac{A}{\alpha}\right\|&\leq 1+\frac{\epsilon}{\alpha}\\ \implies \|A\|&\leq \alpha + \epsilon \end{aligned}\]

Upon rearranging this gives us \(\alpha \geq \|A\|-\epsilon\). The definition above can be extended for general matrices, though additional embedding or padding may be needed (e.g., to make the matrix square).

Once a block-encoding is constructed, it can be used in a quantum algorithm to apply the matrix \(A\) to a quantum state by applying the unitary \(U_A\) to the larger quantum system. The application of the block-encoding can be thought of as a probabilistic application of \(A\): applying \(U_A\) to \(\ket{0}^{\otimes a}\ket{\psi}\) and post-selecting on the first register being in the state \(\ket{0}^{\otimes a}\) gives an output state proportional to \(A\ket{\psi}\) in the second register.

Worked Example

To give an example of block encoding, let us consider a \(1 \times 1\) matrix \(A=\alpha\), where \(0\lt\alpha\lt1\). In this extremely simple case, a block encoding of \(A\) can be constructed as

\[ U_A=\begin{bmatrix} \alpha & \sqrt{1-\alpha^2} \\ \sqrt{1-\alpha^2} & -\alpha \end{bmatrix} \]

or

\[ U_A =\begin{bmatrix} \alpha & -\sqrt{1-\alpha^2} \\ \sqrt{1-\alpha^2} & \alpha \end{bmatrix} \]

Although this type of block encoding can be extended to a properly scaled matrix \(A\) of larger dimension to yield

\[ U_A =\begin{bmatrix} A & (I-A^{\dagger}A)^{1/2} \\ (I-A^{\dagger}A)^{1/2} & -A \end{bmatrix} \]

or

\[ \begin{bmatrix} A & -(I-A^{\dagger}A)^{1/2} \\ (I-A^{\dagger}A)^{1/2} & A \end{bmatrix} \]

this approach is not practical because it requires computing the square root of \(A^{\dagger}A\), which requires computing and diagonalizing \(A^{\dagger}A\). In general, there is no efficient algorithm to perform these operations on a quantum computer using \(\mathcal{O}(\mathrm{poly}(n))\) quantum gates.

Worked Example

Let \(H\) be a Hamiltonian made up of \(m\) Pauli terms, meaning that

\[ H=\sum_{a=1}^m \lambda_a E_a \quad \text{where } E_a \text{ is a tensor product of Pauli matrices} \]

Find an algorithm implementing a unitary close to \(e^{-\iota Ht}\), so that \(\|U-e^{\iota Ht}\|\leq \epsilon\).

Show solution

Original solutions proceeded by using Trotter approximations: for \(r\) large enough,

\[ e^{-\iota Ht}\approx (e^{-\iota E_1t/r} e^{-\iota E_2t/r } \ldots e^{-\iota E_mt/r })^r \]

However, this solution is far from optimal, notably because implementing this approximation requires \(\mathrm{poly}(1/\epsilon)\) gate complexity. Improved algorithms eventually developed into the framework presented below. This framework proceeds by:

  1. Defining a type of quantum circuit called a "block-encoding".
  2. Showing that, given \(\lambda_a\) and \(E_a\), we can construct an efficient block-encoding of \(H\).
  3. Showing that we can get a block-encoding of (an approximation of) \(e^{-\iota Ht}\) with few uses of the block-encoding of \(H\).
  4. Using this block-encoding to apply our approximation to a state.

A more general input model, as will be discussed in this chapter, is called "block encoding". Of course, if \(A\) is a dense matrix without obvious structure, any input model will be very expensive (e.g. exponential in \(n\)) to implement. Therefore a commonly assumed input model is \(s\)-sparse: there are at most \(s\) nonzero entries in each row/column of the matrix. Furthermore, we have an efficient procedure to get access to the location, as well as the value, of the nonzero entries. This in general can again be a difficult task given that the number of nonzero entries can still be exponential in \(n\) for a sparse matrix. Some dense matrices may also be efficiently block encoded on quantum computers. This chapter will illustrate the block encoding procedure via a number of detailed examples.

Worked Example

A more practical scheme that does not require computing the square root of \(A\) can be illustrated by the following real symmetric \(2 \times 2\) example. Let

\[ A=\begin{bmatrix} \alpha_1 & \alpha_2 \\ \alpha_2 & \alpha_1 \end{bmatrix} \]

where \(|\alpha_1|,|\alpha_2|\leq 1\). It can be verified that the matrix

\[ U_A =\frac{1}{2}\begin{bmatrix} U_{\alpha} & -U_{\beta} \\ U_{\beta} & U_{\alpha} \end{bmatrix} \]

is a block encoding of \(A/2\), where

\[ U_{\alpha} = \begin{bmatrix} \alpha_1 & \alpha_2 & \alpha_1 & -\alpha_2 \\ \alpha_2 & \alpha_1 & -\alpha_2 & \alpha_1 \\ \alpha_1 & -\alpha_2 & \alpha_1 & \alpha_2 \\ -\alpha_2 & \alpha_1 & \alpha_2 & \alpha_2 \end{bmatrix} \]

and

\[ U_{\beta} = \begin{bmatrix} \beta_1 & \beta_2 & \beta_1 & -\beta_2 \\ \beta_2 & \beta_1 & -\beta_2 & \beta_1 \\ \beta_1 & -\beta_2 & \beta_1 & \beta_2 \\ -\beta_2 & \beta_1 & \beta_2 & \beta_1 \end{bmatrix} \]

with \(\beta_1 =\sqrt{1-\alpha_1^2}\) and \(\beta_2 =\sqrt{1-\alpha_2^2}\). To implement this unitary on a quantum computer, we must further decompose \(U_A\) as a product of simpler unitaries and construct a quantum circuit with a limited number of quantum gates. This method of block encoding cannot be easily generalized to matrices of larger dimensions. However, for special matrices with special structures, e.g. sparse matrices, it is possible to develop some general block encoding strategies which we will discuss in the next section.

Finally, it can be difficult to find \(U_A\) to encode \(A\) exactly. This is not a problem, since it is sufficient if we can find \(U_A\) to block encode \(A\) up to some error \(\epsilon\). We are now ready to give the definition of block encoding.

The Definition

We introduce a definition of block encoding which we are going to work with. The main idea is to represent a subnormalized matrix as the upper-left block of a unitary.

\[ U=\begin{bmatrix} A/\alpha & * \\ * & * \end{bmatrix} \implies A=\alpha(\bra{0}\otimes I)U(\ket{0}\otimes I) \]
Definition — Block encoding

Given an \(n\)-qubit matrix \(A\) (\(N=2^n\)), if we can find \(\alpha,\epsilon \in \mathbb{R}_+\), and an \((m+n)\)-qubit unitary matrix \(U_A\) so that

\[ \|A-\alpha(\bra{0^m}\otimes I_n)U_A(\ket{0^m}\otimes I_n)\|\leq \epsilon \]

then \(U_A\) is called an \((\alpha,m,\epsilon)\)-block encoding of \(A\). When the block encoding is exact with \(\epsilon=0\), \(U_A\) is called an \((\alpha,m)\)-block encoding of \(A\). The set of all \((\alpha,m,\epsilon)\)-block-encodings of \(A\) is denoted by \(BE_{\alpha,m}(A,\epsilon)\), and we define \(BE_{\alpha,m}(A)=BE(A,0)\).

Here, \(m\) is the number of ancilla bits used to block encode \(A\).

Important

In addition to the definition of block-encoding, one can also define an asymmetric version as follows:

\[ \|A-\alpha(\bra{0}^{\otimes a}\otimes I)U_A(\ket{0}^{\otimes b}\otimes I)\|\leq \epsilon \]

where \(a\) may not equal \(b\). In this case, \(U_A\) can be considered to be an \((\alpha,(a,b),\epsilon)\)- or an \((\alpha,\max(a,b),\epsilon)\)-block-encoding of \(A\). This can be useful for block-encoding a non-square matrix.

Assume we know each matrix element of the \(n\)-qubit matrix \(A_{ij}\), and we are given an \((n+m)\)-qubit unitary \(U_A\). In order to verify that \(U_A \in BE_{1,m}(A)\) we only need to verify that

\[ \bra{0^m}\bra{i}U_A\ket{0^m}\ket{j}=A_{ij} \]

Here, \(\ket{0^m}\ket{j}\) will be a column vector of size \(2^m \times 1 \otimes 2^n \times 1= 2^{m+n} \times 1\) which is \(1\) in the \(j\)th row and \(0\) everywhere else. Similar arguments can be used for establishing \(\bra{0^m}\bra{i}\), which will be a row vector with \(1\) in the \(i\)th column entry and \(0\) everywhere else. Thus, upon multiplying the matrices, the \(\ket{0^m}\ket{j}\) will pick the \(j\)th column of the matrix \(U_A\), which corresponds to the \(j\)th column of the matrix \(A\), and \(\bra{0^m}\bra{i}\) will pick the \(i\)th row of \(U_A\), which corresponds to the \(i\)th row of \(A\); thus it will pick the \((i,j)\)th entry of the matrix \(U_A\), which will be \(A_{ij}\). \(U_A\) applied to the vector \(\ket{0^m,b}\) can be obtained via the superposition principle.

Therefore we may first evaluate the state \(U_A\ket{0^m,j}\), and perform the inner product with \(\ket{0^m,i}\), and verify the resulting inner product is \(A_{ij}\). We will also use the following technique frequently. Assume \(U_A=U_BU_C\); then

\[ \braket{0^m,i|U_A|0^m,j}=\braket{0^m,i|U_BU_C|0^m,j}=(U^{\dagger}_B\ket{0^m,i})^{\dagger}(U_C\ket{0^m,j}) \]

So we can evaluate the states \(U^{\dagger}_B\ket{0^m,i}\), \(U_C\ket{0^m,j}\) independently, and then verify the inner product is \(A_{ij}\). Such a calculation amounts to running the circuit shown below, and if the ancilla qubits are measured to be \(0^m\), the system qubits return the normalized state \(\sum_iA_{ij}\ket{i}/\|\sum_iA_{ij}\ket{i}\|\).

|0ᵐ⟩ ─────────╭──────╮────── M
              │      │
              │  U_A │
 |b⟩ ─────────╰──────╯──────  A|b⟩ / ‖A|b⟩‖   (upon measuring 0ᵐ)
Figure — Circuit for the general block encoding of \(A\) with \(m\) ancilla qubits.
Worked Example

((1,1)-block-encoding in general). For any \(n\)-qubit matrix \(A\) with \(\|A\|_2\leq 1\), the singular value decomposition (SVD) of \(A\) is denoted by \(W\Sigma V^{\dagger}\), where all singular values in the diagonal matrix \(\Sigma\) belong to \([0,1]\). Then we may construct an \((n+1)\)-qubit unitary matrix

\[\begin{aligned} U_A&=\begin{bmatrix} W & 0 \\ 0 & I_n\end{bmatrix} \begin{bmatrix}\Sigma & \sqrt{I_n-\Sigma^2} \\ \sqrt{I_n-\Sigma^2} & -\Sigma \end{bmatrix} \begin{bmatrix} V^{\dagger} & 0 \\ 0 & I_n\end{bmatrix}\\ &=\begin{bmatrix} A & W\sqrt{I_n-\Sigma^2} \\ \sqrt{I_n-\Sigma^2}V^{\dagger} & -\Sigma \end{bmatrix} \end{aligned}\]

which is a \((1,1)\)-block-encoding of \(A\).

Worked Example

(Random circuit block encoded matrix). In some scenarios, we may want to construct a pseudo-random non-unitary matrix on quantum computers. Note that it would be highly inefficient if we first generated a dense pseudo-random matrix \(A\) classically and then fed it into the quantum computer using e.g. quantum-random-access memory (QRAM). Instead we would like to work with matrices that are inherently easy to generate on quantum computers. This inspires the random circuit based block encoding matrix (RACBEM) model. Instead of first identifying \(A\) and then finding its block encoding \(U_A\), we reverse this thought process: we first identify a unitary \(U_A\) that is easy to implement on a quantum computer, and then ask which matrix can be block encoded by \(U_A\).

This example shows that in principle, any matrix \(A\) with \(\|A\|_2\leq 1\) can be accessed via a \((1,1,0)\)-block-encoding. In other words, \(A\) can be block encoded by an \((n+1)\)-qubit random unitary \(U_A\), and \(U_A\) can be constructed using only one-qubit unitaries and CNOT gates. The layout of the two-qubit operations can be designed to be compatible with the coupling map of the hardware.

Worked Example

(Block encoding of a diagonal matrix). As a special case, let us consider the block encoding of a diagonal matrix. Since the row and column indices are the same, we may simplify the oracle into

\[ O_A\ket{0}\ket{i}=\left(A_{ii}\ket{0}+\sqrt{1-|A_{ii}|^2} \ket{1}\right)\ket{i} \]

In the case when the oracle \(\tilde{O}_A\) is used, we may assume accordingly

\[ \tilde{O}_A\ket{0^{d'}}\ket{i}=\ket{\tilde{A}_{ii}}\ket{i} \]

Let \(U_A=O_A\). Direct calculation shows that for any \(i,j\in[N]\),

\[ \bra{0}\braket{i|U_A|0}\ket{j}=A_{ii}\delta_{ij} \]

This proves that \(U_A\in BE_{1,1}(A)\), i.e., \(U_A\) is a \((1,1)\)-block-encoding of the diagonal matrix \(A\).

There are several ways of implementing block-encodings based on the choice of matrix. In particular, we will now describe how to construct block-encodings of unitary matrices, density operators, POVM operators, sparse-access matrices, and matrices stored in a QROM (by QROM we mean quantum read-only memory, which stores classical data that can be accessed in superposition). Quantum matrix arithmetic carries out all calculations in an operational way, meaning that the matrices are represented by block-encodings, in principle enabling exponential speedups in terms of the dimension of the matrices.

Note that in all these cases, since \(\|U\|=1\), we necessarily have \(\|A\|\leq \alpha+\epsilon\). Also note that using the above definition it seems that we can only represent square matrices of size \(2^n \times 2^n\). However, this is not really a restriction. Suppose that \(A\in\mathbb{C}^{n\times m}\), where \(n,m\leq 2^s\). Then we can define an embedding matrix denoted by \(A_e\in\mathbb{C}^{2^s\times 2^s}\) such that the top-left block of \(A_e\) is \(A\) and all other elements are zero. This embedding is a faithful representation of the matrices. Suppose that \(A,B\in\mathbb{C}^{n\times m}\) are matrices; then \(A_e+B_e=(A+B)_e\). Moreover, suppose \(X\in\mathbb{C}^{m\times k}\) for some \(k\leq 2^s\); then \(A_e\cdot C_e=(A\cdot C)_e\).

1.5 Unitary Matrices — Trivial Block Encoding

Unitary matrices are \((1,0,0)\)-block-encodings of themselves. Controlled unitaries (e.g. CNOT) are essentially \((1,1,0)\)-block encodings of the controlled operation.

Definition — Trivial block-encoding

A unitary matrix is a \((1,0,0)\)-block encoding of itself.

If we \(\epsilon\)-approximately implement a unitary \(U\) using \(a\) ancilla qubits via a unitary \(\tilde{U}\) acting jointly on the system and the ancilla qubits, then \(\tilde{U}\) is a \((1,a,\epsilon)\)-block encoding of \(U\). This is also a rather trivial encoding. Note that we make a slight distinction between ancilla qubits that are exactly returned to their original state after the computation and the ones that might pick up some error. The latter qubits we will treat as part of the encoding, and the former qubits we usually treat as purely ancillary qubits.

Now we present some non-trivial ways of constructing block-encodings, which will serve as a toolbox for efficiently inputting and representing matrices for arithmetic computations on a quantum computer. We will denote by \(I_w\) a \(w\)-qubit identity operator, and let \(SWAP_w\) denote the swap operation of two \(w\)-qubit registers. We denote by CNOT the controlled-not gate that targets the first qubit. When clear from the context we simply use the notation \(\ket{0}\) to denote \(\ket{0}^{\otimes w}\).

1.6 Block encoding of density operators

Given an \(s\)-qubit density matrix \(\rho\) and an \((a+s)\)-qubit unitary \(G\) that prepares a purification of \(\rho\) as \(G\ket{0}^{\otimes a}\ket{0}^{\otimes s}=\ket{\rho}\) (such that \(\mathrm{tr}_a\ket{\rho}\bra{\rho}=\rho\), where \(\mathrm{tr}_a\) denotes the trace over the first register), then the operator

\[ (G^{\dagger}\otimes I_s)(I_s\otimes SWAP_s)(G\otimes I_s) \]

is a \((1,a+s,0)\)-block encoding of the density matrix \(\rho\), where \(I_x\) denotes the identity operator on a register with \(x\) qubits, and \(SWAP_s\) denotes the operation that swaps two \(s\)-qubit registers.

Lemma — Block-encoding of density operators

Suppose that \(\rho\) is an \(s\)-qubit density operator and \(G\) is an \((a+s)\)-qubit unitary that on the \(\ket{0}\ket{0}\) input state prepares a purification \(\ket{0}\ket{0}\rightarrow \ket{\rho}\), such that \(\mathrm{Tr}_a \ket{\rho}\bra{\rho}=\rho\). Then \((G^{\dagger}\otimes I_s)(I_a\otimes SWAP_s)(G\otimes I_s)\) is a \((1,a+s,0)\)-block encoding of \(\rho\).

Proof

Let \(r\) be the Schmidt rank of \(\rho\), let \(\{\ket{\psi_k}:k\in[2^s]\}\) be an orthonormal basis, let \(\{\ket{\phi_k}:k\in[r]\}\) be an orthonormal system, and let \(p \in [0,1]^{2^s}\) be such that \(\ket{\rho}=\sum_{k=1}^r \sqrt{p_k}\ket{\phi_k}\ket{\psi_k}\) and \(p_l=0\) for all \(l\in[2^s] \notin [r]\). Then for all \(i,j \in [2^s]\) we have that

\[ \bra{0}^{\otimes a+s}\bra{\psi_i}(G^{\dagger}\otimes I_s)(I_a\otimes SWAP_s)(G\otimes I_s)\ket{0}^{\otimes a+s}\ket{\psi_j}= \] \[\begin{aligned} &=\bra{\rho}\bra{\psi_i}(I_a\otimes SWAP_s)\ket{\rho}\ket{\psi_j}\\ &=\left(\sum_{k=1}^r \sqrt{p_k} \bra{\phi_k}\bra{\psi_k}\right)\bra{\psi_i}(I_a\otimes SWAP_s)\left(\sum_{l=1}^r\sqrt{p_l}\ket{\phi_l}\ket{\psi_l}\right) \ket{\psi_j}\\ &=\left(\sum_{k=1}^r \sqrt{p_k}\bra{\phi_k}\bra{\psi_k}\bra{\psi_i}\right) \left(\sum_{l=1}^r \sqrt{p_l}\ket{\phi_l}\ket{\psi_j}\ket{\psi_l}\right)\\ &=\sqrt{p_jp_i}\delta_{ij}\\ &=\bra{\psi_i}\rho\ket{\psi_j} \end{aligned}\]

Gilyén recently also showed that an implementation scheme for a POVM operator can also be easily transformed to a block-encoding of the POVM operators. By an implementation scheme we mean a quantum circuit \(u\) that, given input \(\rho\) and \(a\) ancilla qubits, sets a flag qubit to \(0\) with probability \(\mathrm{Tr}[\rho M]\). ∎

A density matrix \(\rho\) isn't unitary either, but if you know how to build its purification \(\ket{\rho}\) (a pure state on a bigger space whose partial trace gives \(\rho\)), then a sandwich of that state-prep unitary around a SWAP block-encodes \(\rho\) exactly, with no scaling factor. This is the reason quantum states themselves can serve as matrix inputs.

1.7 Block encoding of POVM operators

One can construct block-encodings of POVM operators, given access to a unitary that implements the POVM. Specifically, if \(U\) is a unitary that implements the POVM \(M\) to precision \(\epsilon\) such that, for all \(s\)-qubit density operators \(\rho\), we have

\[ |\mathrm{Tr}(\rho M)-\mathrm{Tr}[U(\ket{0}\bra{0}^{\otimes a}\otimes \rho)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})]|\leq \epsilon \]

then \((I_a\otimes U^{\dagger})(CNOT\otimes I_{a+s-1})(I_a\otimes U)\) is a \((1,1+a,\epsilon)\)-block encoding of \(M\).

Lemma — Block-encoding of POVM operators

Suppose that \(U\) is an \((a+s)\)-qubit unitary which implements a POVM operator \(M\) with \(\epsilon\)-precision such that for all \(s\)-qubit density operators \(\rho\),

\[ |\mathrm{Tr}[\rho M]-\mathrm{Tr}[U(\ket{0}\bra{0}^{\otimes a}\otimes \rho)U^{\dagger}(\ket{0}\bra{0}^{\otimes 1}\otimes I_{a+s-1})]|\leq \epsilon \]

Then \((I_1\otimes U^{\dagger})(CNOT\otimes I_{a+s-1})(I_a\otimes U)\) is a \((1,1+a,\epsilon)\)-block encoding of the matrix \(M\).

Proof

First observe that by the cyclicity of trace we have that

\[\begin{aligned} \mathrm{Tr}[U(\ket{0}\bra{0}^{\otimes a}\otimes \rho)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})] &=\mathrm{Tr}[U(\ket{0}^{\otimes a}\otimes I)\rho(\bra{0}^{\otimes a}\otimes I)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})]\\ &=\mathrm{Tr}[\rho(\bra{0}^{\otimes a}\otimes I)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})U(\ket{0}^{\otimes a}\otimes I)] \end{aligned}\]

Together, this implies that for all density operators \(\rho\),

\[ |\mathrm{Tr}[\rho(M-(\bra{0}^{\otimes a}\otimes I)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})U(\ket{0}^{\otimes a}\otimes I))]|\leq \epsilon \]

which is equivalent to saying that \(\|M-(\bra{0}^{\otimes a}\otimes I)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})(I_a\otimes U)(\ket{0}^{\otimes 1+a}\otimes I)\|\leq \epsilon\). We can conclude by observing that

\[\begin{aligned} (\bra{0}^{\otimes a}\otimes I)U^{\dagger}(\ket{0}\bra{0}\otimes I_{a+s-1})U(\ket{0}^{\otimes a}\otimes I)= \end{aligned}\] \[ =(\bra{0}^{\otimes 1+a}\otimes I)(I_a\otimes U^{\dagger})(CNOT\otimes I_{a+s-1})(I_1\otimes U)(\ket{0}^{\otimes 1+a}\otimes I) \]

∎

Now we turn to a more traditional way of constructing block-encodings via state preparation. This is a common technique, for example, to implement quantum walks. Note that we introduce the notation \([n]-1\) to denote the set \(\{0,1,\ldots,n-1\}\).

1.8 Block-encoding of Gram matrices

One can implement a block-encoding of a Gram matrix using a pair of state preparation unitaries \(U_L\) and \(U_R\). In particular, the product

\[ U_A=U_L^{\dagger}U_R \]

is a \((1,a,0)\)-block-encoding of the Gram matrix \(A\) whose entries are \(A_{ij}=\braket{\psi_i|\phi_j}\), where

\[ U_L\ket{0}^{\otimes a}\ket{i}=\ket{\psi_i}, \quad U_R\ket{0}^{\otimes a}\ket{j}=\ket{\phi_j} \]
Lemma — Block encoding of Gram matrices by state preparation unitaries

Let \(U_L\) and \(U_R\) be "state preparation" unitaries acting on \(a+s\) qubits, preparing the vectors \(\{\ket{\psi_i}:i\in [2^s]-1\}\), \(\{\ket{\phi_j}:j\in[2^s]-1\}\) such that

\[ U_L:\ket{0}\ket{i}\rightarrow \ket{\psi_i} \] \[ U_R:\ket{0}\ket{j}\rightarrow \ket{\phi_j} \]

Then \(U=U_L^{\dagger}U_R\) is a \((1,a,0)\)-block encoding of the Gram matrix \(A\) such that \(A_{ij}=\braket{\psi_i|\phi_j}\).

One can generalize the above strategy from Gram matrices to arbitrary matrices to produce \((\alpha,a,\epsilon)\)-block encodings of general matrices \(A\), where again \(\alpha\geq \|A\|\). We now give a few examples of block encodings of more general structured sparse matrices. See block-encoding of classical data for details.

1.9 Block Encoding of an s-sparse matrix

Sparse-access matrices: given a matrix \(A\in\mathbb{C}^{2^w\times2^w}\) that is \(s_r\)-row sparse and \(s_c\)-column sparse (meaning each row/column has at most \(s_r\) or \(s_c\) nonzero entries), then, defining \(\|A\|_{max}=\max_{i,j} |A_{ij}|\), one can create a \((\sqrt{s_rs_c}\|A\|_{max},w+3,\epsilon)\)-block-encoding of \(A\) using oracles \(O_r,O_c\), and \(O_A\), defined below:

\[ O_r:\ket{i}\ket{k}\rightarrow \ket{i}\ket{r_{ik}}\quad \forall i \in [2^w]-1,\ k\in[s_r] \] \[ O_c:\ket{l}\ket{j}\rightarrow \ket{c_{lj}}\ket{j}, \quad \forall j \in [2^w]-1 \] \[ O_A:\ket{i}\ket{j}\ket{0}^{\otimes b}\rightarrow \ket{i}\ket{j}\ket{A_{ij}}\quad \forall i,j \in [2^w]-1 \]

In the above, \(r_{ij}\) is the index of the \(j\)th nonzero entry in the \(i\)th row of \(A\) (or \(j+2^w\) if there are fewer than \(i\) nonzero entries), and \(c_{ij}\) is the index of the \(i\)th nonzero entry in the \(j\)th column of \(A\) (or \(i+2^w\) if there are fewer than \(j\) nonzero entries), and \(\ket{A_{ij}}\) is a \(b\)-bit binary encoding of the matrix element \(A_{ij}\). To build the block-encoding, one needs one query to each of \(O_r\) and \(O_c\), and two queries of \(O_A\).

Lemma — Block-encoding of sparse-access matrices

Let \(A\in \mathbb{C}^{2^w\times 2^w}\) be a matrix that is \(s_r\)-row sparse and \(s_c\)-column sparse, and each element of \(A\) has absolute value at most \(1\). Suppose that we have access to the following sparse-access oracles acting on two \((w+1)\)-qubit registers:

\[ O_r:\ket{i}\ket{k}\rightarrow \ket{i}\ket{r_{ik}}\quad \forall i\in[2^w]-1,\ k\in[s_r] \] \[ O_c:\ket{l}\ket{j}\rightarrow \ket{c_{lj}}\ket{j}\quad \forall l \in [s_c],\ j\in[2^w]-1 \]

where \(r_{ij}\) is the index for the \(j\)th non-zero entry of the \(i\)th row of \(A\), or if there are fewer than \(i\) nonzero entries then it is \(j+2^w\), and similarly \(c_{ij}\) is the index for the \(i\)th non-zero entry of the \(j\)th column of \(A\), or if there are fewer than \(j\) non-zero entries then it is \(i+2^w\). Additionally assume that we have access to an oracle \(O_A\) that returns the entries of \(A\) in a binary description

\[ O_A:\ket{i}\ket{j}\ket{0}^{\otimes b}\rightarrow \ket{i}\ket{j}\ket{a_{ij}}\quad \forall i,j\in[2^w]-1 \]

where \(a_{ij}\) is a \(b\)-bit binary description (for simplicity we assume here that the binary representation is exact) of the \((i,j)\) matrix element of \(A\). Then we can implement a \((\sqrt{s_rs_c},w+3,\epsilon)\)-block-encoding of \(A\) with a single use of \(O_r\), \(O_c\), two uses of \(O_A\), and additionally using \(O(w+\log^{2.5}(s_rs_c/\epsilon))\) one- and two-qubit gates while using \(\mathcal{O}(b,\log^{2.5}(s_rs_c/\epsilon))\) ancilla qubits.

Proof

We proceed by constructing state preparation unitaries. We will work with \(3\) registers, the first of which is a single-qubit register, and the other two registers have a \((w+1)\)-qubit unitary that implements the map \(\ket{0}\rightarrow \sum_{k=1}^s \frac{\ket{k}}{\sqrt{s}}\); it is known that this operator \(D_s\) can be implemented with \(\mathcal{O}(2)\) quantum gates using \(\mathcal{O}(1)\) ancilla qubits. Then we define the \(2(w+1)\)-qubit unitary \(V_L=O_r(I_{w+2}\otimes D_{s_r})SWAP_{w+1}\) such that

\[ V_L:\ket{0}^{w+2}\ket{i}\rightarrow \sum_{k=1}^{s_r} \frac{\ket{i}\ket{r_{ik}}}{\sqrt{s_r}}\quad \forall i\in[2^w]-1 \]

We implement the operator \(V_R=O_c(D_c\otimes I_{w+1})\) in a similar way, acting as

\[ V_R:\ket{0}^{w+2}\ket{j}\rightarrow \sum_{l=1}^{s_c}\frac{\ket{c_{lj}}\ket{j}}{\sqrt{s_c}}\quad \forall j \in [2^s]-1 \]

It is easy to see that the above unitaries are such that

\[ \bra{0}^{w+2}\bra{i}V_L^{\dagger}V_R\ket{0}^{w+2}\ket{j}=\frac{1}{\sqrt{s_rs_c}}\quad \text{if } a_{ij}\neq 0 \text{ and } 0 \text{ otherwise} \]

Now we define \(U_L=I_1\otimes V_L\) and define \(U_R\) as performing the unitary \(I_a\otimes V_R\) followed by some extra computation. After performing \(V_R\) we get a superposition of index pairs \(\ket{i}\ket{j}\). Given an index pair \(\ket{i}\ket{j}\) we query the matrix element \(\ket{a_{ij}}\) using the oracle \(O_A\). Then we do some elementary computations in order to implement a single-qubit gate \(\ket{0} \rightarrow a_{ij}\ket{0}+\sqrt{1-|a_{ij}|^2}\ket{1}\) on the first qubit, with precision \(\mathcal{O}(\mathrm{poly}(\frac{\epsilon}{s_rs_c}))\). This can be executed with the stated complexity. Finally we also need to uncompute everything, which requires one more use of \(O_A\). This way we get a good approximation of

\[ U_R:\ket{0}^{w+3}\ket{j}\rightarrow \sum_{l=1}^{s_c}\frac{(a_{c_{lj}j}\ket{0}+\sqrt{1-|a_{c_{lj}j}|^2}\ket{1})\ket{c_{lj}}\ket{j}}{\sqrt{s_c}}\quad \forall j\in[2^w]-1 \]

Note that in the above method the matrix gets subnormalized by a factor of \(\frac{1}{\sqrt{s_rs_c}}\). If we knew, for example, that \(\|A\|\leq \frac{1}{2}\), then we could amplify the block-encoding in order to remove this unwanted subnormalization using singular value amplification, using the block encoding roughly \(\sqrt{s_rs_c}\) times. However, under some circumstances one can defeat the subnormalization more efficiently by doing an amplification at the level of state preparation unitaries using a technique called "uniform spectral gap amplification". ∎

Lemma — Preamplified block-encoding of sparse-access matrices

Let \(A\in\mathbb{C}^{2^w\times 2^w}\) be a matrix that is \(s_r\)-row sparse and \(s_c\)-column sparse, and is given using the input oracles as defined before. Let \(a_{i\cdot}\) denote the \(i\)th row of \(A\) and similarly \(a_{\cdot j}\) the \(j\)th column. Let \(q\in[0,2]\) and suppose that \(n_r\in[1,s_r]\) is an upper bound on \(\|a_{i\cdot}\|_q^q\) and \(n_c\in[1,s_c]\) is an upper bound on \(\|a_{\cdot j}\|_{2-q}^{2-q}\).

Let \(m=\max[\frac{s_r}{n_r},\frac{s_c}{n_c}]\). Then we can implement a \((\sqrt{\frac{1}{2n_rn_c}},w+6,\epsilon)\)-block encoding of \(A\) with \(\mathcal{O}(\sqrt{\frac{s_r}{n_r}}\log(\frac{s_rs_c}{\epsilon}))\) uses of \(O_r\), \(\mathcal{O}(\sqrt{\frac{s_c}{n_c}}\log (\frac{s_rs_c}{\epsilon}))\) uses of \(O_c\), \(\mathcal{O}(\sqrt{m}\log(\frac{s_rs_c}{\epsilon}))\) uses of \(O_A\), and additionally using \(\mathcal{O}(\sqrt{m}\log(\frac{s_rs_c}{\epsilon})+\log^{3.5}(\frac{s_rs_c}{\epsilon}))\) one- and two-qubit gates while using \(\mathcal{O}(b,\log^{2.5}(\frac{s_rs_c}{\epsilon}))\) ancilla qubits.

Proof

The idea is very similar to the proof of the previous lemma: we implement the unitaries \(V_L,V_R\) the same way. However, we define \(U_R,U_L\) slightly differently. Using a similar method to the previous lemma we implement \(\mathcal{O}(\mathrm{poly}(\frac{\epsilon}{s_rs_c}))\) approximations of the maps

\[ U_L:\ket{0}^{w+4}\ket{i}\rightarrow \sum_{k=1}^{s_r} \frac{(|a_{ir_{ik}}|^{\frac{q}{2}}\ket{0}+\sqrt{1-|a_{ir_{ik}}|^q}\ket{1})\ket{0}\ket{i}\ket{r_{ik}}}{\sqrt{s_r}}\quad \forall i\in[2^w]-1 \] \[ U_R:\ket{0}^{w+4}\ket{j}\rightarrow \sum_{l=1}^{s_c}\frac{\frac{a_{c_{lj}j}}{|a_{c_{lj}j}|}(|a_{c_{lj}j}|^{1-\frac{q}{2}}\ket{0}+\sqrt{1-|a_{c_{lj}j}|^{2-q}}\ket{1})\ket{c_{lj}}\ket{j}}{\sqrt{s_c}}\quad \forall j \in [2^w]-1 \]

It is easy to see that the above unitaries are such that

\[ \bra{0}^{w+4}\bra{i}U_L^{\dagger}U_R\ket{0}^{w+4}\ket{j}=\frac{a_{ij}}{\sqrt{s_rs_c}}\quad \forall i,j \in [2^w]-1 \]

We can see that for all \(i\in[2^w]-1\) the modified row vector \(\sum_{k=1}^{s_r}\frac{|a_{ir_{ik}}|^{\frac{q}{2}}\ket{0}\ket{0}\ket{i}\ket{r_{ik}}}{\sqrt{s_r}}\) has squared norm at most \(\frac{n_r}{s_r}\), and a similar \(\frac{n_c}{s_c}\) upper bound holds for the squared norm of the modified column vector. Also observe that

\[ (\ket{0}\bra{0}\otimes I_{2w+3})U_L(\ket{0}\bra{0}^{w+4} \otimes I_2)=\sum_{j=0}^{2^w-1}\left(\sum_{k=1}^{s_r}\frac{|a_{ir_{ik}}|^{\frac{q}{2}}\ket{0}\ket{0}\ket{i}\ket{r_{ik}}}{\sqrt{s_r}}\right)\bra{0}^{w+4}\bra{j} \]

which is a singular value decomposition with the singular values being the modified row norms. Therefore we can apply singular value amplification with amplification \(\gamma_r=\sqrt{\frac{s_r}{\sqrt{2}n_r}}\) and precision \(\mathcal{O}(\mathrm{poly}(\frac{\epsilon}{s_rs_c}))\) to get an approximation of \(\tilde{U}_L\) such that

\[ (\bra{+}\otimes \ket{0}\bra{0}\otimes I_{2w+3})\tilde{U}_L (\ket{+}\otimes \ket{0}\bra{0}^{w+4}\otimes I_w)=\gamma_r \sum_{j=0}^{2^w-1}\left(\sum_{k=1}^{s_r}\frac{|a_{ir_{ik}}|^{\frac{q}{2}}\ket{0}\ket{0}\ket{i}\ket{r_{ik}}}{\sqrt{s_r}}\right)\bra{0}^{w+4}\bra{j} \]

Similarly we apply singular value amplification with amplification \(\gamma_c=\sqrt{\frac{s_c}{\sqrt{2}n_c}}\) and precision \(\mathcal{O}(\mathrm{poly}(\frac{\epsilon}{s_rs_c}))\), resulting in a \(\mathcal{O}(\mathrm{poly}(\frac{\epsilon}{s_rs_c}))\) approximation of \(\tilde{U}_R\) such that

\[ \bra{++}\bra{0}^{w+4}\bra{i}\tilde{U}_L^{\dagger}\tilde{U}_R\ket{++}\ket{0}^{w+4}\ket{j}=\gamma_r\gamma_c \frac{a_{ij}}{\sqrt{s_rs_c}}=\frac{a_{ij}}{\sqrt{2n_rn_c}}\quad \forall i,j\in[2^w]-1 \]

Finally, adding \(4\) Hadamard gates we can change the \(\ket{+}\) states above to \(\ket{0}\) states, resulting in the \(\left(\frac{1}{\sqrt{2n_rn_c}},w+6,\epsilon\right)\)-block-encoding of \(A\). The complexity statement follows similarly as in the previous proof, with the extra observation that the singular value amplifications of \(U_L\) and \(U_R\) can be performed using degree \(\mathcal{O}(\gamma_r \log(\frac{s_rs_c}{\epsilon}))\) and \(\mathcal{O}(\gamma_c\log(\frac{s_rs_c}{\epsilon}))\) singular value transformations respectively. ∎

For \(q\in[0,2]\) let us define \(\mu_q(A)=\sqrt{n_q(A)n_{(2-q)}(A^T)}\), where \(n_q(A)=\max_i\|a_{i\cdot}\|_q^q\) is the \(q\)th power of the maximum \(q\)-norm of the rows of \(A\). Let \(A^{(q)}\) denote the matrix of the same dimensions as \(A\), with (for complex values we define these non-integer powers using the principal value of the complex logarithm function) \(A_{ij}^{(q)}=\sqrt{a_{ij}^q}\).

Lemma — Block-encodings of matrices stored in quantum data structures

(Here we assume that the data structure stores the matrices with sufficient precision.) Let \(A\in\mathbb{C}^{2^w\times 2^w}\).

  1. Fix \(q\in[0,2]\). If \(A^{(q)}\) and \((A^{(2-q)})^{\dagger}\) are both stored in quantum-accessible data structures, then there exist unitaries \(U_R\) and \(U_L\) that can be implemented in time \(\mathcal{O}(\mathrm{poly}(w\log(1/\epsilon)))\) such that \(U_R^{\dagger}U_L\) is a \((\mu_q(A),w+2,\epsilon)\)-block-encoding of \(A\).
  2. On the other hand, if \(A\) is stored in a quantum-accessible data structure, then there exist unitaries \(U_R\) and \(U_L\) that can be implemented in time \(\mathcal{O}(\mathrm{poly}(w\log(e/\epsilon)))\) such that \(U_R^{\dagger}U_L\) is an \((\|A\|_F,w+2,\epsilon)\)-block-encoding of \(A\).

If, in addition to being sparse, the matrix also enjoys some additional structure — e.g. there are only a few distinct values that the matrix elements take — the complexity can be further improved. Finally, note that the sparsity dependence can be essentially quadratically improved to \((\max(s_r,s_c))^{\frac{1}{2}+o(1)}\) using advanced Hamiltonian simulation techniques combined with taking the logarithm of unitaries; however the resulting subroutine may be impractical and comes with a worse precision dependence.

The recurring theme across these lemmas: whenever a matrix comes with a way to look up "where are the nonzeros" (\(O_r,O_c\)) and "what is the value here" (\(O_A\)), you can turn it into a block encoding, but you pay a subnormalization of roughly \(\sqrt{s_rs_c}\). Preamplification and quantum data structures are refinements that shrink that penalty at the cost of extra circuitry.
Worked Example

Recall the real symmetric \(2\times 2\) matrix example. If we define \(\phi_1=\cos^{-1}(\alpha_1)+\cos^{-1}(\alpha_2)\) and \(\phi_2=\cos^{-1}(\alpha_1)-\cos^{-1}(\alpha_2)\), then we can verify that the block encoding for the \(2 \times 2\) matrix can be factored as a product of simple unitaries, i.e.

\[ U_A=U_6U_5U_4U_3U_2U_1U_0 \]

where \(U_0=U_6=I_2 \otimes H \otimes I_2\), \(U_1=R_1 \otimes I_2 \otimes I_2\), \(U_2=U_4=(I_2 \otimes E_0 + X \otimes E_1) \otimes I_2\), \(U_3 =R_2 \otimes I_2 \otimes I_2\), and \(U_5=I_2 \otimes (E_0 \otimes I_2 + E_1 \otimes X)\). Here, \(H, X\) are the Hadamard and Pauli-X gates, \(R_1=R_y(\phi_1)\), \(R_2 =R_y(\phi_2)\) are the rotation matrices about the \(y\) axis, and \(E_0,E_1\) are the projectors. The quantum circuit associated with the factorization is given below.

|0⟩ ─────── R₁ ──⊕── R₂ ──⊕──────────────── M
                 │        │
|0⟩ ─── H ───────●────────●─────●───── H ─── M
                                │
|j⟩ ────────────────────────────⊕───────────
Figure — A quantum circuit for the block encoding of a \(2 \times 2\) symmetric matrix \(A\). Two ancilla qubits (top two wires) plus one system qubit \(\ket{j}\); the rotations \(R_1,R_2\) and CNOTs implement \(O_A\) and \(O_c\).

Note that in this case, the quantum circuit requires 2 ancilla qubits in addition to the \(n=1\) system qubit required to match the dimension of \(A\), which is \(N=2^n\). As a result the unitary that block encodes the \(2 \times 2\) matrix \(A\) is of dimension \(2^3\).

It is possible to develop a general scheme to construct a block encoding and the corresponding quantum circuit for well-structured matrices. In particular, when \(A\) is sparse with a structured sparsity pattern and the nonzero matrix elements can also be well characterized, an efficient block encoding circuit for \(A\) can be constructed.

We start from a 1-sparse matrix, i.e., there is only one nonzero entry in each row or column of the matrix. This means that for each \(j\in[N]\), there is a unique \(c(j)\in[N]\) such that \(A_{c(j),j}\neq 0\), and the mapping \(c\) is a permutation. Then there exists a unitary \(O_c\) such that

\[ O_c\ket{j}=\ket{c(j)} \]

The implementation of \(O_c\) may require the usage of some work registers that are omitted here. We also have

\[ O^{\dagger}_c\ket{c(j)}=\ket{j} \]

We assume the matrix entry \(A_{c(j),j}\) can be queried via

\[ O_A\ket{0}\ket{j}=\left(A_{c(j),j}\ket{0}+\sqrt{1-|A_{c(j),j}|^2}\ket{1}\right)\ket{j} \]

Now we construct \(U_A=(I\otimes O_c)O_A\) (the tensor product of two unitary matrices is unitary), and compute

\[ \bra{i}\bra{0}U_A\ket{0}\ket{j}=\bra{0}\bra{i}\left(A_{c(j),j}\ket{0}+\sqrt{1-|A_{c(j),j}|^2}\ket{1}\right)\ket{c(j)}=A_{c(j),j}\delta_{i,c(j)} \]

This proves that \(U_A\in BE_{1,1}(A)\).

Theorem

Let \(c(j,l)\) be a function that gives the row index of the \(l\)th (among a list of \(s\)) non-zero matrix element in the \(j\)th column of an \(s\)-sparse matrix \(A \in\mathbb{C}^{N\times N}\) with \(N=2^n\), where \(s=2^m\). If there exists a unitary \(O_c\) such that

\[ O_c\ket{l}\ket{j}=\ket{l}\ket{c(j,l)} \]

and a unitary \(O_A\) such that

\[ O_A\ket{0}\ket{l}\ket{j}=(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1})\ket{l}\ket{j} \]

then

\[ U_A =(I_2 \otimes D_s \otimes I_N)(I_s \otimes O_c)(I_2 \otimes D_s \otimes I_N) \]

block encodes \(A/s\). Here \(D_s\) is called a diffusion operator and is defined as

\[ D=H \otimes H \otimes \ldots \otimes H=H^{\otimes m} \]
Proof

Note that applying \(D_s\) to \(\ket{0^m}\) yields

\[ D_s\ket{0^m}=\frac{1}{\sqrt{s}}\sum_{l=0}^{s-1} \ket{l} \]

where \(\{\ket{l}\}\) forms the computational basis in the Hilbert space defined by the \(m\) qubits. Our goal is to show that \(\bra{0}\bra{0^m}\bra{i}U_A\ket{0}\ket{0^m}\ket{j}=A_{ij}/s\). In order to compute the inner product, we apply \(D_s,O_A,O_c\) to \(\ket{0}\ket{0^m}\ket{j}\) successively as illustrated below:

\[\begin{aligned} \ket{0}\ket{0^m}\ket{j} &\xrightarrow{I_2 \otimes D_s \otimes I_N} \frac{1}{\sqrt{s}} \sum_{l\in[s]}\ket{0}\ket{l}\ket{j}\\ &\xrightarrow{O_A} \frac{1}{\sqrt{s}}\sum_{l\in [s]}(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1})\ket{l}\ket{j}\\ &\xrightarrow{I_2 \otimes O_c} \frac{1}{\sqrt{s}}\sum_{l\in[s]}(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1})\ket{l}\ket{c(j,l)} \end{aligned}\]

where \([s]\) denotes the set of integers \(\{0,1,\ldots,s-1\}\). Instead of multiplying the leftmost factor \(I_2 \otimes D_s \otimes I_N\) (note that \(D_s\) is Hermitian) into the last line, we apply it to \(\ket{0}\ket{0^m}\ket{i}\) to obtain

\[ \ket{0}\ket{0^m}\ket{i}\xrightarrow{I_2 \otimes D_s \otimes I_N} \frac{1}{\sqrt{s}}\sum_{l' \in [s]} \ket{0}\ket{l'}\ket{i} \]

Finally, taking the inner product between the two results in

\[ \bra{0}\bra{0^m}\bra{i}U_A \ket{0}\ket{0^m}\ket{j}=\frac{1}{s}\sum_l A_{c(j,l),j}\delta_{i,c(j,l)} =\frac{1}{s}A_{ij} \]

∎

The quantum circuit associated with the block encoding is shown below. Note that the implementation of this block encoding requires \(m+1\) ancilla qubits in addition to \(n\) system qubits. In order to turn this into an efficient quantum circuit, we need to further decompose the \(O_c\) and \(O_A\) unitaries into a sequence of quantum gates, which may not be straightforward. In the circuit shown for the real symmetric case, \(O_A\) is decomposed as \(O_A=U_4U_3U_2U_1\) and \(O_C\) is simply \(U_5\). We will now show how these decompositions are constructed systematically.

Although it may be possible to construct a set of controlled quantum gates to achieve the \(O_c\) and \(O_A\) oracles for a specific pair of \(j\) and \(l\), this approach will not yield an efficient quantum circuit because the total number of quantum gates in the circuit will be of the order of \(\mathcal{O}(N)\), which is exponential with respect to \(n\). Our goal is to construct a circuit that has a gate complexity of \(\mathrm{poly}(n)\), i.e. a polynomial in \(n\), at least for certain sparse and/or structured matrices with well-defined sparsity patterns.

Note that \(O_c\) is unitary, and thus we must have \(O_C^{\dagger}\ket{l}\ket{c(j,l)}=\ket{l}\ket{j}\). This means that for each index \(i=c(j,l)\) we can recover the column index \(j\) given the value of \(l\). This assumption is of course somewhat restrictive, but it covers important cases such as banded matrices. We remark that it can generally be more difficult to explicitly construct quantum circuits for \(O_C\) in these more general query models.

Worked Example

Real Symmetric \(2 \times 2\) matrix. We revisit the matrix considered previously once more, and view it as an \(s\)-sparse matrix with \(s=2\) even though it is dense. Therefore we can still use the recipe given in the theorem to construct a block encoding of \(A/2\). We will show how explicit circuits for \(O_c\) and \(O_A\) can be constructed.

  1. The \(O_C\) circuit: Since the second column is a down- or up-shift of the first one, the function \(c(j,l)\), which defines the 0-based row index of the \(l\)th nonzero element in the \(j\)th column, can be defined by \[ c(j,l)=j+l \bmod 2 \] for \(j,l\in\{0,1\}\). After enumerating all possible combinations of \((l,j)\) input pairs and their corresponding \((l,c(j,l))\) output pairs as shown in the table below, we see that \(O_c\) can simply be implemented as a CNOT gate, as shown in the figure below.
    |l⟩ ──●──          |l⟩ ──●──
          │      =           │
    |j⟩ ──O_c─          |j⟩ ──⊕──
    
    Figure — The \(O_c\) circuit is a single CNOT with control \(\ket{l}\) and target \(\ket{j}\).
    \(l\)\(j\)\(l\)\(c(j,l)\)
    0000
    1011
    0101
    1110

    Table — All possible output pairs \((l,c(j,l))\) for all possible combinations of \((l,j)\).

  2. The \(O_A\) circuit: The basic strategy to construct a circuit for \(O_A\) is to use controlled rotations to place numerical values at the proper locations in \(U_A\). Because the matrix \(A\) has at most two unique matrix elements, we need two controlled rotations. In general, we need to condition the application of these rotations on the values of \(j\) and \(l\). However, since the values of \(\alpha_1\) and \(\alpha_2\) depend solely on \(l\), control is only required on the qubit that takes \(\ket{l}\) as input. We apply the rotation \(R_y(\theta_1)\) with \(\theta_1=2\cos^{-1}(\alpha_1)\) when \(l=0\), and \(R_y(\theta_2)\) with \(\theta_2=\cos^{-1}(\alpha_2)\) when \(l=1\). These controlled rotations are combined to yield the following \(O_A\) circuit.
    |0⟩ ── R_y(θ₁) ── R_y(θ₂) ──
              │          │
    |l⟩ ──────○──────────●──────       (○ = control on l=0,  ● = control on l=1)
    |j⟩ ────────────────────────
    
    Figure — Implementation of the \(O_A\) circuit using controlled \(y\)-rotations. The last qubit is not used.

    Note that the last qubit is not used in this \(O_A\) circuit.

    On some quantum hardware it is preferable to use single-qubit rotations and CNOT gates in place of controlled rotation gates. These are sometimes referred to as uniformly controlled rotations. In the figure below, we show how the controlled rotations used in the \(O_A\) circuit can be replaced by an equivalent set of uniformly controlled gates.

    |0⟩ ─ R_y(θ₁) ─ R_y(θ₂) ─        |0⟩ ─ R_y(φ₁) ─⊕─ R_y(φ₂) ─⊕─
             │         │        =                   │            │
    |l⟩ ─────○─────────●─────        |l⟩ ────────────●────────────●─
    
    Figure — The \(O_A\) circuit rewritten with uniformly controlled rotations (single-qubit rotations interleaved with CNOTs).

    To see that the right-hand side is identical to the left, we observe first that, if the second qubit is in the \(\ket{0}\) state, the circuit on the left applies \(R_y(\theta_1)\) to the first qubit. In the circuit on the right, \(R_y(\phi_2)R_y(\phi_1)\) is applied to the first qubit in this case. These two operations are identical when \(\theta_1=\phi_1+\phi_2\). Secondly, if the second qubit is in the \(\ket{1}\) state, the left circuit applies \(R_y(\theta_2)\) to the first qubit, while the right circuit applies the gate sequence \(XR_y(\phi_2)XR_y(\phi_1)\). It follows from the identity \(XR_y(\theta)X=R_y(-\theta)\) that these operations are equivalent if \(\theta_2=\phi_1-\phi_2\).

  3. The complete circuit: Finally, we substitute the circuits, together with \(D_s=H\), into the general \(s\)-sparse block encoding circuit and obtain the complete block encoding quantum circuit for the matrix. Note that this circuit is identical to the one we have already introduced for the \(2\times 2\) symmetric matrix.

Banded Circulant Matrix

For a more general \(s\)-sparse matrix, WLOG we assume each row and column has exactly \(s\) nonzero entries (otherwise we can always treat some zero entries as nonzeros). For each column \(j\), the row index for the \(l\)th nonzero entry is denoted by \(c(j,l)=c_{j,l}\). For simplicity, we assume that there exists a unitary \(O_c\) such that

\[ O_c\ket{l}\ket{j}=\ket{l}\ket{c(j,l)} \]

Here we assume \(s=2^{p}\) and the first register is a \(p\)-qubit register. A necessary condition for this model is that \(O_C\) is reversible, i.e., we can have \(O_c^{\dagger}\ket{l}\ket{c(j,l)}=\ket{l}\ket{j}\). This means that for each row index \(i=c(j,l)\), we can recover the column index \(j\) given the value of \(l\). This can be satisfied e.g. by

\[ c(j,l)=j+l-l_0 \pmod N \]

where \(l_0\) is a fixed number. This corresponds to a banded matrix. This assumption is of course somewhat restrictive. We shall discuss more general query models.

Corresponding to the equation, the matrix entries can be queried via

\[ O_A\ket{0}\ket{l}\ket{j}=\left(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1}\right) \ket{l}\ket{j} \]

In order to construct a unitary that encodes all row indices at the same time, we define \(D=H^{\otimes p}\) (sometimes called a diffusion operator, a term originating from Grover's search) satisfying

\[ D\ket{0^p}=\frac{1}{\sqrt{p}}\sum_{l\in[p]}\ket{l} \]

Consider \(U_A\) given by the circuit below. The measurement means that to obtain \(A\ket{b}\), the ancilla register should return the value \(0\).

   |0⟩   ──────────╭──────╮──────────────────── M
                   │      │
|0⟩^⊗m ─── D ──────┤ O_A  ├──╭──────╮─── D ───── M
                   │      │  │ O_c  │
   |ψ⟩   ──────────╰──────╯──╰──────╯───────────
Figure — Quantum circuit for block encoding an \(s\)-sparse matrix. The diffusion \(D\) prepares a uniform superposition over nonzero positions; \(O_A\) writes the values; \(O_c\) routes them to the correct rows.
Proposition

The circuit given above defines \(U_A \in BE_{s,s+1}(A)\).

Proof

We call \(\ket{0}\ket{0^p}\ket{j}\) the source state, and \(\ket{0}\ket{0^p}\ket{i}\) the target state. In order to compute the inner product \(\bra{0}\bra{0^p}\bra{i}U_A\ket{0}\ket{0^p}\ket{j}\), we apply \(D,O_A,O_C\) to the source state accordingly as

\[\begin{aligned} \ket{0}\ket{0^p}\ket{j}&\xrightarrow{D}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\ket{0}\ket{l}\ket{j}\\ &\xrightarrow{O_A}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\left(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1}\right)\ket{l}\ket{j}\\ &\xrightarrow{O_C}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\left(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1}\right)\ket{l}\ket{c(j,l)} \end{aligned}\]

Since we are only interested in the final state when all ancilla qubits are in the \(0\) state, we may apply \(D\) to the target state \(\ket{0}\ket{0^p}\ket{i}\) as (note that \(D\) is Hermitian)

\[ \ket{0}\ket{0^p}\ket{i}\xrightarrow{D}\frac{1}{\sqrt{s}}\sum_{l'\in[s]}\ket{0}\ket{l'}\ket{i} \]

Hence the inner product

\[ \bra{0}\bra{0^p}\bra{i}U_A\ket{0}\ket{0^p}\ket{j}=\frac{1}{s}\sum_l A_{c(j,l),j}\delta_{i,c(j,l)}=\frac{1}{s}A_{ij} \]

∎

1.10 Hermitian Block Encoding

So far we have considered general \(s\)-sparse matrices. Note that if \(A\) is a Hermitian matrix, its \((\alpha,m,\epsilon)\)-block-encoding \(U_A\) does not need to be Hermitian. Even if \(\epsilon=0\), we only have that the upper-left \(n\)-qubit block of \(U_A\) is Hermitian. For instance, even the block encoding of a Hermitian diagonal matrix may not be Hermitian. On the other hand, there are cases when \(U^{\dagger}_A=U_A\) is indeed a Hermitian matrix, and hence the definition:

Definition — Hermitian Block Encoding

Let \(U_A\) be an \((\alpha,m,\epsilon)\)-block-encoding of \(A\). If \(U_A\) is also Hermitian, then it is called an \((\alpha,m,\epsilon)\)-Hermitian-block-encoding of \(A\). When \(\epsilon=0\), it is called an \((\alpha,m)\)-Hermitian-block-encoding. The set of all \((\alpha,m,\epsilon)\)-Hermitian-block-encodings of \(A\) is denoted by \(HBE_{\alpha,m}(A,\epsilon)\), and we define \(HBE_{\alpha,m}(A)=HBE(A,0)\).

The Hermitian block encoding provides the simplest scenario of the qubitization process.

1.11 Query models for general sparse matrices

If we query the oracle, the assumption that for each \(l\) the value of \(c(j,l)\) is unique for all \(j\) seems unnatural for constructing general sparse matrices. So we consider an alternative method for constructing the block encoding of a general sparse matrix as below.

Again without loss of generality we assume that each row/column has at most \(p=2^s\) non-zero entries, and that we have access to the following two \(2n\)-qubit oracles:

\[ O_r\ket{l}\ket{i}=\ket{r(i,l)}\ket{i} \] \[ O_c\ket{l}\ket{j}=\ket{c(j,l)}\ket{j} \]

Here \(r(i,l)\), \(c(j,l)\) give the \(l\)th nonzero entry in the \(i\)th row and \(j\)th column, respectively. It should be noted that although the index \(l\in[p]\), we should expand it into an \(n\)-qubit state (e.g. let \(l\) take the last \(s\) qubits of the \(n\)-qubit register following the binary representation of integers). The reason for such an expansion, and why we need two oracles \(O_c,O_r\), will be seen shortly.

Similar to the discussion before, we need a diffusion operator satisfying

\[ D\ket{0^n}=\frac{1}{\sqrt{s}}\sum_{l\in[p]}\ket{l} \]

This can be implemented using Hadamard gates as

\[ D=I_{n-s}\otimes H^{\otimes s} \]

We assume that the matrix entries are queried using the following oracle using controlled rotations:

\[ O_A\ket{i}\ket{j}=\left(A_{ij}\ket{0}+\sqrt{1-|A_{ij}|^2}\ket{1}\right)\ket{i}\ket{j} \]

where the rotation is controlled by both row and column indices. However, if \(A_{ij}=0\) for some \(i,j\), the rotation can be arbitrary, as there will be no contribution due to the usage of \(O_r,O_c\).

Proposition

The circuit shown below defines \(U_A\in BE_{s,n+1}(A)\).

   |0⟩   ──────────────╭──────╮────────────────────────── M
                       │      │
|0⟩^⊗m ─ D ─╭──────╮───┤ O_A  ├──╭──────╮─╭───────╮── D ── M
            │ O_c  │   │      │  │ SWAP │ │ O_r†  │
   |ψ⟩   ───╰──────╯───╰──────╯──╰──────╯─╰───────╯───────
Figure — Quantum circuit for block encoding of general sparse matrices, using separate row oracle \(O_r\) and column oracle \(O_c\) plus a SWAP.
Proof

We apply the first four gate sets to the source state:

\[\begin{aligned} \ket{0}\ket{0^n}\ket{j}&\xrightarrow{D}\xrightarrow{O_c}\xrightarrow{O_A}\frac{1}{\sqrt{p}}\sum_{l\in[p]}\left(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1}\right)\ket{c(j,l)}\ket{j}\\ &\xrightarrow{SWAP}\frac{1}{\sqrt{p}}\sum_{l\in[p]}\left(A_{c(j,l),j}\ket{0}+\sqrt{1-|A_{c(j,l),j}|^2}\ket{1}\right)\ket{j}\ket{c(j,l)} \end{aligned}\]

We then apply \(D\) and \(O_r\) to the target state:

\[ \ket{0}\ket{0^n}\ket{i}\xrightarrow{D}\xrightarrow{O_r}\frac{1}{\sqrt{p}}\sum_{l'\in[p]}\ket{0}\ket{r(i,l')}\ket{i} \]

Then the inner product gives

\[\begin{aligned} \bra{0}\bra{0^n}\braket{i|U_A|0}\ket{0^n}\ket{j}&=\frac{1}{p}\sum_{l,l'}A_{c(j,l),j}\delta_{i,c(j,l)}\delta_{r(i,l'),j}\\ &=\frac{1}{p}\sum_lA_{c(j,l),j}\delta_{i,c(j,l)}=\frac{1}{s}A_{ij} \end{aligned}\]

Here we have used that there exists a unique \(l\) such that \(i=c(j,l)\), and a unique \(l'\) such that \(j=r(i,l')\). ∎

We remark that the quantum circuit above is essentially the standard construction, which gives an \((s,n+3)\)-block-encoding. The construction above slightly simplifies the procedure and saves two extra qubits (used to mark whether \(l\geq s\)).

Next we consider the Hermitian block encoding of an \(s\)-sparse Hermitian matrix. Since \(A\) is Hermitian, we only need one oracle to query the location of the nonzero entries:

\[ O_c\ket{l}\ket{j}=\ket{c(j,l)}\ket{j} \]

Here \(c(j,l)\) gives the \(l\)th nonzero entry in the \(j\)th column. It can also be interpreted as the \(l\)th nonzero entry in the \(i\)th column. Again the first register needs to be interpreted as an \(n\)-qubit register. The diffusion operator is the same as before.

Unlike all discussions before, we introduce two signal qubits, and a quantum state in the computational basis takes the form \(\ket{a}\ket{i}\ket{b}\ket{j}\), where \(a,b\in\{0,1\}\), \(i,j\in[N]\). In other words, we may view \(\ket{a}\ket{i}\) as the first register, and \(\ket{b}\ket{j}\) as the second register. The \((n+1)\)-qubit SWAP gate is defined as

\[ SWAP\ket{a}\ket{i}\ket{b}\ket{j}=\ket{b}\ket{j}\ket{a}\ket{i} \]

To query matrix entries, we need access to the square root of \(A_{ij}\) as (note that these act on the second single-qubit register)

\[ O_A\ket{i}\ket{0}\ket{j}=\ket{i}\left(\sqrt{A_{ij}}\ket{0}+\sqrt{1-|A_{ij}|}\ket{1}\right)\ket{j} \]

The square root operation is well defined if \(A_{ij}\geq0\) for all entries. If \(A\) has negative (or complex) entries, we first write \(A_{ij}=|A_{ij}|e^{\iota \theta_{ij}}\), \(\theta_{ij}\in[0,2\pi)\), and the square root is uniquely defined as \(\sqrt{A_{ij}}=\sqrt{|A_{ij}|}e^{\iota\theta_{ij}/2}\).

Proposition

The figure below defines \(U_A\in HBE_{s,n+2}(A)\).

   |0⟩   ──────────────────╭───────╮──────────────────────── M
                           │       │
|0⟩^⊗n ─ D ─ O_c ─╭──────╮─┤       ├─╭───────╮─ O_c† ─ D ──── M
                  │ O_A  │ │ SWAP  │ │ O_A†  │
   |0⟩   ────┬────┤      ├─┤       ├─┤       ├──┬─────────────  M
             │    ╰──────╯ │       │ ╰───────╯  │
   |b⟩   ── O_c ───────────╰───────╯────────── O_c† ─────────
Figure — Quantum circuit for the Hermitian block encoding of a general Hermitian matrix, using a single position oracle \(O_c\), the value oracle \(O_A\) and its inverse, and an \((n+1)\)-qubit SWAP.
Proof

Applying the first four gate sets to the source state gives

\[\begin{aligned} \ket{0}\ket{0^n}\ket{0}\ket{j}&\xrightarrow{D}\xrightarrow{O_c}\xrightarrow{O_A}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\ket{0}\ket{c(j,l)}\left(\sqrt{A_{c(j,l),j}}\ket{0}+\sqrt{1-|A_{c(j,l),j}|}\ket{1}\right)\ket{j}\\ &\xrightarrow{SWAP}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\left(\sqrt{A_{c(i,l'),i}}\ket{0}+\sqrt{1-|A_{c(i,l'),i}|}\ket{1}\right)\ket{i} \end{aligned}\]

Apply the last three gate sets to the target state:

\[ \ket{0}\ket{0^n}\ket{0}\ket{i}\xrightarrow{D}\xrightarrow{O_c}\xrightarrow{O_A}\frac{1}{\sqrt{s}}\sum_{l\in[s]}\ket{0}\ket{c(i,l')}\left(\sqrt{A_{c(i,l'),i}}\ket{0}+\sqrt{1-|A_{c(i,l')}|}\ket{1}\right)\ket{i} \]

Finally, take the inner product as

\[\begin{aligned} \bra{0}\bra{0^n}\bra{0}\bra{i}U_A\ket{0}\ket{0^n}\ket{0}\ket{j}&\\ &=\frac{1}{s}\sum_{l,l'}\sqrt{A_{c(j,l),j}}\sqrt{A^*_{c(i,l'),i}}\delta_{i,c(j,l)}\delta_{c(i,l'),j}\\ &=\frac{1}{s}\sqrt{A_{ij}A^*_{ji}}\sum_{l,l'}\delta_{i,c(j,l)}\delta_{c(i,l'),j}=\frac{1}{s}A_{ij} \end{aligned}\]

In this equality, we have used that \(A\) is Hermitian: \(A_{ij}=A^*_{ji}\), and there exists a unique \(l\) such that \(i=c(j,l)\), as well as a unique \(l'\) such that \(j=c(i,l')\).

The quantum circuit above is essentially the standard construction. The relation to quantum walks will be discussed further. ∎

1.12 Examples

The cost of data input can dominate the run-time of quantum algorithms. Here, we consider data input of arithmetically structured matrices via block encoding circuits — the input model for the quantum singular value transform and related algorithms. We demonstrate how to construct block encoding circuits based on an arithmetic description of the sparsity and pattern of repeated values of a matrix. We present schemes yielding different subnormalizations of the block encoding; a comparison shows that the best choice depends on the specific matrix. The resulting circuits reduce flag qubit number according to sparsity, and data loading cost according to repeated values, leading to an exponential improvement for certain matrices. We give examples of our block encoding schemes for a few families of matrices, including Toeplitz and tridiagonal matrices.

Currently, the number of quantum algorithms and application use cases known to provide an exponential advantage is rather limited. The inception of the quantum singular value transformation (QSVT) has led to a new perspective on quantum algorithms. In what has been termed the "grand unification of quantum algorithms", many previously known quantum algorithms have been reformulated within the framework of QSVT, including matrix inversion, phase estimation, Hamiltonian simulation, and amplitude amplification. The core of the QSVT is a polynomial transformation of an input matrix's singular values. Different choices of polynomials and input matrices give rise to these various applications. In order to run a quantum algorithm in a real-world setting, data input (into the quantum computer) and data output (readout) are important steps and can severely limit any speedup provided by the quantum algorithm itself. Here, we will study how to input structured data efficiently and provide a scheme that facilitates the construction of explicit quantum circuits for structured data matrices.

In QSVT-based algorithms, the input model for matrices of data is block encoding, where an input matrix of data \(A\) could be non-unitary and there is no quantum circuit that could implement the operator \(A\) directly. The existence of an embedding is not sufficient to input the data matrix \(A\). Rather, \(U\) must be implemented as a quantum circuit and expressed in an elementary quantum gate set in order to run it on a quantum computer. Finding such a quantum circuit will typically further increase the subnormalization \(\alpha\) and the dimension of the junk blocks.

1.13 Resource cost — gates and qubits

The complexity of block-encoding an operator depends on the type of data or operator being encoded and any underlying assumptions. For instance, unitaries are naturally block-encodings of themselves, and hence their resource requirements depend entirely on their circuit-level implementation without any additional overhead for being a "block-encoding". By contrast, approaches that make use of state-preparation and QRAM to implement the block-encoding tend to have larger complexities, as those two subroutines typically dominate the resource requirements. For example, the best-known circuit that implements block-encoding matrices of classical data for general, dense \(N\times N\) matrices uses \(\mathcal{O}(N\log (1/\epsilon))\) qubits to achieve minimum \(T\)-gate count (which also scales as \(\mathcal{O}(N\log(1/\epsilon))\)), or a larger \(\mathcal{O}(N^2)\) number of qubits to achieve minimum \(T\)-gate depth (which scales as \(\mathcal{O}(\log N +\log (1/\epsilon))\)). In the sparse-access model, one can use \(\mathcal{O}(w+\log^{2.5}(s_rs_c/\epsilon))\) one- and two-qubit gates, and \(\mathcal{O}(b+\log^{2.5}(s_rs_c/\epsilon))\) ancilla qubits, in addition to the calls to the matrix entry oracle \(O_A\) and sparse access oracles \(O_r\) and \(O_c\), which must be implemented either by computing matrix entries "on the fly" or by using a QRAM primitive. Assuming appropriate binary representations of the numbers \(A_{ij}\), the exponents of the above logarithms can be reduced to \(1\) using some techniques.

The value of block-encodings is not that it is always cheap to implement them (as it depends on the relevant cost metric and the data access model); rather, the concept of block-encodings is powerful because it allows a practitioner of quantum algorithms to study and optimize the block-encoding construction independently of how it is used within the larger algorithm.

Important

A block-encoded matrix \(A\) must have norm \(\|A\|\leq 1\), or otherwise the matrix must first be normalized, and one must take care to keep track of normalization throughout the computation. In the definition of block-encodings shown above, the parameter \(\alpha\) plays the role of normalizing \(A\). Note that often the above constructions are suboptimal in the sense that \(\alpha\gg\|A\|\), which can lead to increased complexity.

For a given desired block encoding, there can be several independent, yet equally valid, implementations, and one can sometimes optimize for various resources when building the block-encoding. For example, many block-encoding strategies require a step in which some classical data is loaded into QRAM, but there are several ways of performing this data-loading step.

When using a block-encoding as part of a larger quantum algorithm, it is important to ensure that the overhead introduced by implementing a block-encoding will not outweigh any potential quantum speedups, as block-encoding can be very resource intensive.

The use of \(\ket{0}^{\otimes a}\) as the "signal" state is just one convention — we can use any "signal" state, given a unitary to prepare it. One can also consider a more general definition as "projected unitary encodings", which allows using an arbitrary subspace, rather than just a state-indexed block.

1.14 Example Use Cases

Block-encodings are ubiquitous in quantum algorithms, and they prevail in quantum algorithms that need coherent access to some linear operator or a method of implementing a non-unitary transformation on quantum data. Some specific examples:

Key Takeaways