A Quantum Algorithm for the Kalman Filter Using

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

A QUANTUM ALGORITHM FOR THE K ALMAN FILTER USING

BLOCK ENCODING

Hao Shi Guofeng Zhang


College of Intelligence Science Department of Applied Mathematics
arXiv:2404.04554v1 [math.QA] 6 Apr 2024

National University of Defense Technology Hong Kong Polytechnic University


Changsha, China Hong Kong, China
shihao_hill@163.com guofeng.zhang@polyu.edu.hk

Ming Zhang*
College of Intelligence Science
National University of Defense Technology
Changsha, China
zhangming@nudt.edu.cn

A BSTRACT
Quantum algorithms offer significant speed-ups over their classical counterparts in various applica-
tions. In this paper, we develop quantum algorithms for the Kalman filter widely used in classical
control engineering using the block encoding method. The entire calculation process is achieved by
performing matrix operations on Hamiltonians based on the block encoding framework, including
addition, multiplication, and inversion, which can be completed in a unified framework compared
to previous quantum algorithms for solving control problems. We demonstrate that the quantum
algorithm exponentially accelerates the computation of the Kalman filter compared to traditional
methods. The time complexity can be reduced from O(n3 ) to O(κpoly log(n/ϵ) log(1/ϵ′ )), where
n represents the matrix dimension, κ denotes the condition number for the matrix to be inverted, ϵ
indicates desired precision in block encoding, ϵ′ signifies desired precision in matrix inversion. This
paper provides a comprehensive quantum solution for implementing the Kalman filter and serves as an
attempt to broaden the scope of quantum computation applications. Finally, we present an illustrative
example implemented in Qiskit (a Python-based open-source toolkit) as a proof-of-concept.

Keywords quantum computation · Kalman filter · state estimation · block encoding · QSVT

1 Introduction

Quantum computing is an emerging and rapidly growing paradigm that has the potential to offer significant computa-
tional advantages over classical computing, by leveraging quantum-mechanical principles such as quantum superposition
and entanglement[1, 2]. This computational advantage of quantum computing will facilitate the resolution of complex
computational problems in various application domains. As is well known, classical computers store information in bits
(‘0’ or ‘1’), whereas their equivalent in quantum computers are qubits, represented as |0⟩ or |1⟩ or any superposition
of |0⟩ and |1⟩. By utilizing Hilbert space as a quantum computing space, where n qubits can result in a superposition
state of 2n possible outcomes, quantum computers possess an inherent advantage over classical computers when it
comes to solving large-scale problems. Over the past few decades, numerous quantum algorithms have been proposed,
two well-known algorithms are Shor’s algorithm for factoring[3] and Grover’s algorithm for database searching[4],
which are often employed to illustrate the advantages of quantum computing. The core steps of both algorithms use the
subroutines of quantum phase estimation [1] and amplitude amplification [5]. In 2009, the Harrow-Hassidim-Lloyd
(HHL) algorithm was proposed for linear systems[6], which has the potential of solving a large number of mathematical
problems, such as linear differential equations[7], least-square curve fitting[8] and matrix inversions[9]. Many subse-
√ implemented using these methods as subroutines achieve exponential speedup O(log(n)) or
quent quantum algorithms
quadratic speedup O( n), relative to their classical counterparts [10].
As linear system problems arise ubiquitously across all scientific and engineering disciplines, one may expect to
explore more quantum algorithms. Notably, Wossnig et al.[11] proposed a quantum algorithm for dense matrices based
on HHL without considering matrix sparsity. Gilyén et al. introduced a technique called “block encoding", which
involves embedding a general matrix into a larger unitary operator implemented by the quantum system using blocks of
unitaries. They also established rules for addition, subtraction and multiplication of block-encoded matrices, thereby
leading to exponential speed-ups with respect to matrix dimension[12]. Subsequently, a hybrid quantum-classical
algorithm called variational quantum linear solver (VQLS) is presented by Bravo-Prieto et al.[13], which used fewer
qubits compared with HHL. Shao[14] explored three approaches for solving matrix multiplication operations and
discussed the calculation problem from the perspective of input/output data types (quantum/classical). Li et al.[15]
proposed a quantum matrix multiplier that can serve as an intermediate module for more complex quantum algorithms.
Qi et al.[16] developed quantum algorithms for matrix operations using the Sender-Receiver model. Zhao et al.[17]
provided Trotter-based subroutines for elementary matrix operations through the matrix embedding formula. These
aforementioned quantum algorithms hold promise in terms of offering speed-ups over their classical counterparts when
applied to specific problems.
Matrix operations play a crucial role in machine learning and data processing, and quantum computing holds immense
potential for enhancing matrix arithmetic, as mentioned above. In the field of control theory and engineering, researchers
have explored the application of quantum computing to solve linear system problems encountered in classical control
systems. Sun et al.[18] proposed a quantum algorithm based on HHL for solving Lyapunov equations, demonstrating
exponential acceleration of optimal control protocols using quantum algorithms[19]. Li et al.[20] proposed a quantum
algorithm that enhances the efficiency of solving state estimation problems. Furthermore, Li et al.[21] devised a
quantum linear system algorithm for general matrices in system identification. All these aforementioned quantum
algorithms exhibit accelerated performance compared to their classical counterparts. In this paper, we intent to develop
a block-encoding-based quantum version of the classical Kalman filter, showcasing its exponential improvement.
Being the best Bayesian estimator of optimal state estimation for linear systems with Gaussian uncertainty[22], the
Kalman filter is widely employed in various fields such as in UAV, robotics, communication, navigation[23]. It is a
recursive estimator that combines mathematical models and output measurements from a physical system to accurately
estimate its state. Solving state estimation involves solving a series of linear equations, which can be efficiently
addressed by quantum algorithms. Therefore, the proposed quantum algorithm for the Kalman filter exponentially
reduce time complexity from O(n3 ) to O(κpoly log(n/ϵ) log(κ/ϵ′ )).
This paper is organized as follows: Section 2 presents the proposed block encoding schemes and matrix operations
based on block encoding. Subsequently, in Section 3, our quantum algorithm and the corresponding quantum circuits
for the Kalman filter are introduced. In Section 4, a numerical example is provided to demonstrate the feasibility of our
approach using Qiskit[24]. Finally, Section 5 concludes the paper.

2 Block encoding
Block encoding is a general way of transforming a matrix to a unitary operator. An illustrative example of block
encoding is as follows: if an s-qubit matrix A is embedded in an (s + a)-qubit unitary matrix UA ,
A/α ∗ · · · ∗
 
 ∗ ∗ · · · ∗
UA =   ... .. , (1)
. 
∗ ∗ ··· ∗
it represents a submatrix with the normalization factor α as the upper-left block of UA , where ∗ denotes irrelevant
s-qubit matrices and UA consists of 2a block rows(columns). Now suppose that |ψ⟩ is any quantum state consisting of
s qubits, and |0a ⟩ represents a ancilla qubits. By measuring the ancilla qubits, we can obtain outcome A if it returns 0.
The circuit is presented in Figure 1. The equation for solving the matrix A is given by:
A = α(⟨0a | ⊗ Is )UA (|0a ⟩ ⊗ Is ) (2)

Theorem 1: Block encoding[12, 25]. Given an s-qubit matrix A ∈ Cn×n , if there exist real positive values α,ϵ ∈ R+ ,
a natural number a ∈ N, and a unitary matrix UA of (s + a) qubits, such that
∥A − α(⟨0a | ⊗ Is )UA (|0a ⟩ ⊗ Is )∥ ≤ ϵ, (3)

2
Figure 1: Circuit for block encoding of A using a ancilla qubits.

then UA is called an (α, a, ϵ)-block-encoding of A. In the case where the block encoding is exact with ϵ = 0, UA is
termed an (α, a)-block-encoding of A. The set of all (α, a, ϵ)-block-encoding of A is denoted by BEα,a (A, ϵ), and we
define BEα,a (A) = BE(A, 0).
s
×2s
If A ∈ Cm×n , where m, n ≤ 2s , we can define Ae ∈ C2 such that A occupies the upper-left of matrix Ae while
all other elements are set to zero [12].

2.1 The construction of block encoding

There exist many specific methods to find UA to block encode A[25, 26, 27, 28, 29]. In this paper, building upon
the theory in the references[12, 25], we derive a method for constructing UA in quantum-accessible data structure
introduced in [30] to efficiently generate quantum states.
Theorem 2: Block encoding of matrix in quantum data structure. Let A ∈ Cm×n be an s-qubit matrix with Aij ∈ C
being the entry on the i-row and the j-column, let m, n ≤ 2s . When A is stored in a quantum data structure, then we
always can implement unitaries UR and UL in time O(polylog(mn/ϵ)) in Theorem 1 according to [31].

m
s 1 X
UL : |0 ⟩|j⟩ → ∥Ai,· ∥|i⟩|j⟩ (4)
∥A∥F i=1
n
1 X
UR : |i⟩|0s ⟩ → |i⟩ Ai,j |j⟩ (5)
∥Ai,· ∥ j=1

where ∥Ai,· ∥ is theql2 norm of the i-th row of A. So we can verify that UL† UR is a (∥A∥F , s, ϵ)-block-encoding of
s
P 2
A, where ∥A∥F = i,j |Ai,j | is the Frobenius norm of A. The construction circuit can be seen in Figure 2. |0 ⟩
denotes the ancilla qubits used to construct UA .

Figure 2: Circuit construction for block encoding of A using s ancilla qubits.

Proof.

m n
1 X 1 X
⟨i|⟨0s |UL† UR |0s ⟩|j⟩ = (UL |i⟩|0s ⟩)† UR |0s ⟩|j⟩ = ( ∥Ai,· ∥⟨i|⟨j|)(|i⟩ Ai,j |j⟩)
∥A∥F i=1 ∥Ai,· ∥ j=1
Ai,j
= (6)
∥A∥F

So we consider that a BE∥A∥F ,s (A, ϵ) can be implemented in time O(polylog(mn/ϵ)) described above.

3
2.2 Addition and multiplication of block-encoded matrices

If the block encoding of a matrix has been efficiently completed, we can perform matrix addition and multiplication
operations using the following rules. The theorems referenced in [12, 25] have been modified and expanded to adjust
the specific problems addressed in our study.
Theorem 3: Addition of two block-encoded matrices. If UA represents an (α, a, δ)-block-encoding of an s-qubit
operator A and UB represents a (β, b, ϵ)-block-encoding of an s-qubit operator B, α, β > 0. Let T = αUA + βUB
be the linear combination of unitaries (LCU), note that the dimensions of UA , UB may not be equal and the sum
is simply the addition of the corresponding elements. Define W = (V † ⊗ Is )U (V ⊗ Is ), we can get that W ∈
BE∥γ∥1 ,max(a,b)+1 (A + B, δ + ϵ), where ∥γ∥1 = α + β.
proof. Firstly
 ′  ′
A /α ∗ ··· ∗ B /α ∗ ··· ∗
 
 ∗ ∗ ··· ∗  ∗ ∗ ··· ∗
UA = 
 ... ..  , UB =  .
 .. ..  (7)
.  . 
∗ ∗ ··· ∗ ∗ ∗ ··· ∗
and
∥A − A′ ∥ ≤ δ, ∥B − B ′ ∥ ≤ ϵ. (8)
 ′
A + B′ ∗ ··· ∗

 ∗ ∗ ··· ∗
T = αUA + βUB =  .. .. . (9)
 . . 
∗ ∗ ··· ∗
max(a,b)
×2max(a,b)
even if the dimensions of UA and UB are not equal, where T ∈ C2 . So
∥A + B − (⟨0 max(a,b) max(a,b)
| ⊗ Is )T (|0 ⟩ ⊗ Is )∥ = ∥A + B − (A′ + B ′ )∥
≤ ∥A − A′ ∥ + ∥B − B ′ ∥ (10)
≤ δ + ϵ.
Secondly, let
U = |0⟩⟨0| ⊗ UA + |1⟩⟨1| ⊗ UB , (11)
and
√  √ √ 
1
√α ∗ † 1 α β
V =p ,V = p . (12)
∥γ∥1 β ∗ ∥γ∥1 ∗ ∗

According to Lemma 7.9 in [25], we can verify that W ∈ BE∥γ∥1 ,1 (T ), where ∥γ∥1 = α + β.
Thirdly,
T
 
∥γ∥1 ∗
W = (13)
∗ ∗
max(a,b)+1
×2max(a,b)+1
where W ∈ C2 .
Lastly,
∥A + B − ∥γ∥1 (⟨0|⟨0max(a,b) | ⊗ Is )W (|0⟩|0max(a,b) ⟩ ⊗ Is )∥
=∥A + B − (⟨0max(a,b) | ⊗ Is )T (|0max(a,b) ⟩ ⊗ Is )∥ (14)
≤δ + ϵ.

Therefore, W serves as a (∥γ∥1 , max{a, b} + 1, δ + ϵ)-block-encoding of A + B. The quantum circuit is illustrated in


Figure 3.
Theorem 4: Multiplication of two block-encoded matrices. If UA is an (α, a, δ)-block-encoding of an s-qubit operator
A, and UB is a (β, b, ϵ)-block-encoding of an s-qubit operator B, then (Ib ⊗ UA )(Ia ⊗ UB ) is an (αβ, a + b, αϵ + βδ)-
block-encoding of AB in Lamma 53 in reference [25].

4
Figure 3: Circuit for addition of two block encoded matrices (a ≤ b).

Figure 4: Circuit for product of two block encoded matrices.

The quantum circuit for block encoding of AB can be constructed in Figure 4.


It should be noted that a marker is placed on the left side of the gate inspired by Qiskit to specify which ancilla qubits
are affected by the quantum gate. For instance, we utilize 0a as a marker to indicate that UA operates on |0a ⟩ while no
operation is performed on other qubits |0b ⟩, and vice versa. Of course, both quantum operators act on state |ψ⟩. This
notation will be employed consistently throughout the rest of this article.

2.3 Matrix Inversion by QSVT

The HHL algorithm[6] is widely recognized as the most prominent quantum algorithm for matrix inversion. In the case
of a sparse Hermitian matrix A, it enables us to efficiently solve the linear equation Ax = b :
2
n
−1
X 1
|x⟩ = A |b⟩ = βi |ui ⟩, (15)
i=1
λi

where λi is the eigenvalue of the


 matrix A, ui is the corresponding eigenvector. However, we need to dilate the matrix
0 A
into a Hermitian matrix à = if A is a general square matrix. Additionally, obtaining the explicit form of
A† 0
−1
A poses significant challenges and hinders further calculation. In this paper, we consider addressing the problem of
matrix inversion through the quantum singular value transformation (QSVT)[25, 32].
Given an s-qubit square matirx A ∈ Cn×n with the singular value decomposition A = W ΣV † , where Σ is a
diagonal matrix of the singular values. Referring to the setup of HHL, we assume that the singular values of A
satisfy σi ∈ [κ−1 , 1], where κ is condition number of A. As all the singular values are nonzero, we can obtain the
inversion of A as A−1 = V Σ−1 W † , where Σ−1 contains reciprocals of the singular values along the diagonal. Because
A† = V ΣW † , then
A−1 = V f (Σ)W † = f (A† ) (16)
−1
where f (x) = x is an odd function. According to the QSVT with real polynomials, we can construct the circuit
of Up(A) ∈ BE1,a+1 (p(A)) when f (x) is an odd function, as depicted in Figure 5. Here, p(x) represents an odd
polynomial that approximates f (x). Further details can be found in references [12, 25, 32].
Hence, it is imperative to identify an odd polynomial p(x) that serves as an ϵ′ -approximation to the function f (x)
within the interval [ κ1 , 1]. Notably, based on [25], we can obtain an odd polynomial p(x) of degree O(κ log(1/ϵ′ ))
1 1
which effectively approximates κβ x . That is

1 1 1 1
|p(x) − | ≤ ϵ′ , ∀x ∈ [−1, − ] ∪ [ , 1]. (17)
κβ x κ κ
where p(x) has odd parity and |p(x)| ≤ 1 for x ∈ [−1, − κ1 ] ∪ [ κ1 , 1], β is chosen arbitrarily.

5
Figure 5: Circuit of UP (A) ∈ BE1,a+1 (P (A)) when d is odd.

The matrix inversion algorithm by QSVT is designed as follows[25, 32]:


Given an n × n matrix A, where ∥A∥ ≤ 1(if not, A can be rescaled to meet this condition), and a precision parameter
ϵ′ .
(1) Prepare the unitary block encoding of A and A† , denoted by UA ∈ BE1,a (A), UA† ∈ BE1,a (A† ) respectively.
(2) Construct the circuit shown in Figure 5 to get Up(A) ∈ BE1,a+1 (p(A)), where p(x) represents the matrix inversion
polynomial of degree O(κ log(1/ϵ′ )). Note that the phase factor Φe = (ϕ f1 , · · · , ϕ
f0 , ϕ fd ) can be determined from the
polynomial p(x).
1 −1
(3) Finally, we have that p(A) is an ϵ-approximation to κβ A .

3 A quantum algorithm of the Kalman filter


3.1 The classical Kalman filter

The Kalman filter is employed for state estimation in linear dynamical systems represented in the state space format[22].
The process model specifies the transition of the state from time k − 1 to time k as follows:
xk = Axk−1 + Buk−1 + wk−1 , k ≥ 1. (18)
where A is the state transition matrix applied to the previous state vector xk−1 , B is the control-input matrix applied to
the control vector uk−1 , and wk−1 is the process noise vector which is zero-mean Gaussian with the covariance Q, i.e.,
it can be represented as wk−1 ∼ N (0, Q).
The process model is paired with the observation model which characterizes the correlation between the state and the
observation at time step k as:
zk = Hxk + vk . (19)
where zk is the observation vector, H denotes the observation matrix, and vk represents the observation noise vector
which is zero-mean Gaussian with the covariance R, i.e., vk ∼ N (0, R). Let’s assume that both wk−1 and vk are
statistically independent.
The Kalman filter algorithm for state estimation comprises two stages: prediction and update. Essentially, it employs
the Kalman gain to refine the predicted state value towards its true value counterpart. The Kalman filter algorithm is
summarized as follows.
1. The prior state estimation is calculated:
x̂−
k = Ax̂k−1 + Buk−1 . (20)

2. The prior error covariance is computed:


Pk− = APk−1 AT + Q. (21)

3. The Kalman gain is determined:


Kk = Pk− H T [HPk− H T + R]−1 . (22)

4. The state estimation is updated:


x̂k = x̂− −
k + Kk (zk − H x̂k ). (23)

6
5. The error covariance is computed:

Pk = (I − Kk H)Pk− . (24)

Equations (20)∼(21) represent the discrete Kalman filter prediction equations, while equations (22)∼(24) correspond to
the discrete Kalman filter update equations. This procedure ensures accurate estimation of the state variables x̂k . The
whole process involves computation of these five formulas through matrix operations. Considering that block encoding
of arbitrary matrices used in matrix operations can lead to exponential speed-ups[12], we propose a corresponding
quantum algorithm for constructing the Kalman filter based on block encoding.

3.2 The quantum algorithm

The implementation procedure of the quantum algorithm for the Kalman filter involves evolving the encoded quantum
state to the final required state through a series of unitary transformations, followed by obtaining the final result via
quantum measurement. The process begins with block encoding and ends with measurement.
Before we proceed, let me make two brief statements:
(1)The matrices A ∈ Rn×n , B ∈ Rn×c , H ∈ Rm×n , Q ∈ Rn×n , R ∈ Rm×m in equations (18)∼(19) are known
and constant, where 1 ≤ m, c, n. At the initial time, the vectors x̂0 ∈ Rn , u0 ∈ Rc and the matrix P0 ∈ Rn×n are
given. Moreover, we assume that u0 = u1 = · · · = uK . It is considered that we can get zk ∈ Rm from the sensor
measurements at time k.
(2) To analyze the complexity of this quantum algorithm, we adopt certain criteria for block encoding: if an arbitrary
s-qubit matrix A ∈ Cn×n is stored in a quantum-accessible data structure, then we can always contruct a (∥A∥F , s, ϵ)-
block-encoding of A that can be implemented in time O(polylog(n/ϵ)) refer to Theorem 2. For simplicity, let’s assume
that all these matrices have an error-free block encoding.
We present the complete procedure for implementing the Kalman filter using a quantum approach in Figure 6. This
includes addition, multiplication and inversion operations on the block-encoded matrices. The detailed process is given
below.

Figure 6: The Kalman filter (left: the classical algorithm, right: the quantum algorithm)

7
Table 1: The block encoding of the known data

Original matrix Dimension Block encoding

A n×n eA ∈ BE∥A∥ ,s (A)


U F

B n×c eB ∈ BE∥B∥ ,s (B)


U F

X̂0 n×n e ∈ BE
UX̂0 ∥X̂0 ∥F ,s (X̂0 )

U0 n×n eU0 ∈ BE∥U ∥ ,s (U0 )


U k−1 F

P0 n×n eP0 ∈ BE∥P ∥ ,s (P0 )


U k−1 F

Q n×n eQ ∈ BE∥Q∥ ,s (Q)


U F

R n×n eR ∈ BE∥R∥ ,s (R)


U F

H m×n eH ∈ BE∥H∥ ,s (H)


U F

Z1 n×n eZ1 ∈ BE∥Z ∥ ,s (Z1 )


U 1 F

3.2.1 Block encoding of the known data


Since x̂0 ,u0 ,z1 are vectors of dimensions n, c and m respectively, for simplicity of calculation, they need to be converted
into n × n square matrices for block encoding. This can be achieved by filling in zeros in the remaining positions of
matrices as follows:
 (0)   (0)   (0) 
x̂0 0 ··· ··· 0 u0 0 ··· ··· 0 z0 0 ··· ··· 0
 . .. . . .. .  . .. . . .  . .. . . .
 .. . ..   .. .. ..
 . .  . . . ..   .. . . . .. 
X̂0 =  .. .. . . .. 
   
 .. U0 = u(c−1) 0 · · · · · · 0 Z 1 = z (m−1) 0 · · · · · · 0
 . . . . . 
 0.
 
 0 .
 
 (n−2) .. .
.. . .. . .
. . ..

.. .
.. . .. . . 
. . .. 
0 · · · · · · 0

x̂0   
(n−1)
x̂0 0 · · · · · · 0 n×n 0 0 · · · · · · 0 n×n 0 0 · · · · · · 0 n×n
(25)

The block encoding of a matrix is denoted by U


e in order to differentiate it from the control matrix Uk−1 .
Since B, H are not necessarily square matrices and R is not an n-order square matrix, it is necessary to convert them
into n × n matrices for block encoding by padding the remaining positions with zeros.
We can perform block encoding for all known matrices using Theorem 2 as shown in Table 1.

3.2.2 The computational process of the quantum algorithm of the Kalman filter
We summarize the procedure of computing the Kalman filter based on the block encoding framework in Algorithm 1.
The results of each procedure are shown in Table 2. According to Theorems 3 and 4, we can successfully perform the
addition and multiplication operations on unitary matrices. More importantly, it is necessary to solve for the inverse of
matrix UeA
temp , which can be achieved through the QSVT in procedure 5. To obtain Atemp , we first need to measure

UAtemp to obtain Atemp as it provides essential a priori knowledge such as the condition number κ and singular values
e
σ. This information enables us to calculate suitable phase factors for approximating 1/x. Immediately according to
equation (17), the ϵ′ polynomial approximating f (x) = κβ 1 1
x can be expressed as p(x). Then unitary operator UA
e −1
temp

can be constructed. In the end, if the loop continues, we need to reconstruct the block encoding of X̂k , Pk and Zk for
the next calculation. Using the U e ,U
X̂k
eP directly leads to more qubits being used later. Moreover, the more ancilla
k
qubits there are in construction of UA , the larger normalization factor α is, it’s more difficult to obtain the exact matrix
A by measurement.
The quantum circuit for a loop is illustrated in Figures 7 and 8. Let’s provide a brief explanation of the symbols depicted
in these figures. As shown in Figure 7, U e represents the block encoding of the matrix, with its subscript denoting the

8
given matrix. According to Theorem 3, operator V is determined by the coefficients of two adder numbers. For instance,
during the implementation process of U e , both matrices U e − and U eK (U eZ − U eH Ue − ) that need to be summed are
X̂k X̂k k k X̂k
multiplied by their respective coefficients, which serve as scaling factors for the matrix. Operator VX̂k can be computed
using these two coefficients. Similarly, the operator Vtemp , VP − , VX̂ − can be obtained following a similar procedure
k k

where we assign temp = Zk − H X̂k− .


Here, it is particularly noted that Ue −1 is obtained by QSVT. Please refer to Figures 9 and 10 for the circuits of
Atemp
calculating U −1 and UA
e
Atemp
e , respectively.
temp

Algorithm 1 The process of solving Kalman filter based on the block encoding framework.
Input: Access to all the given matrices A, B, X̂0 , U0 , P0 , Z1 , Q, R, H.
Output: X̂K , PK .
Runtime: O(poly log(n/ϵ)κ log(1/ϵ′ )), the time complexity is analyzed in detail in Section 4.2.

Procedure:
1 Prepare the unitary block encoding of A, B, X̂0 , U0 , P0 , Z1 , Q, R, H.
2 for k = 1 to K do:

3 e − =U
Calculate the block encoding of the prior state U X̂k
eA U
e
X̂k−1 + UB UUk−1 .
e e
4 Compute the block encoding of the prior error covariance Ue − =U eA U
eP U eT + U
eQ .
Pk k−1 A
5 Calculate the block encoding of the Kalman gain U e −U
eK = U e T [U
eH Ue −U eR ]−1 , where
eT + U
k Pk H Pk H
U
eA =U e −U
eH U eT + U eR . Measure UeA to get Atemp , which is subsequently subjected to
temp Pk H temp

block encoding again after knowing the condition number and the singular values.
6 e =U
Update the block encoding of the posterior state estimation U e − +U eK (UeZ − U e − ).
eH U
X̂k X̂k k k X̂k
7 Update the block encoding of the error covariance U
eP = (U eI − U
eK UeH )U
e −.
k k Pk
8 Conducting measurements on U e ,U eP to obtain X̂k , Pk .
X̂k k

9 Block encode X̂k , Pk , Zk

10 If the loop ends, the final results are X̂K , PK .

Figure 7: The quantum circuit of calculating X̂K

4 Algorithm complexity analysis

In this section, we conduct an analysis of the time and space complexities involved.

9
Table 2: The result of the intermediate variables

Procedure Result Normalization factor

U X̂k−1 ∈ BEα31 ,2s (AX̂k−1 ) α31 = ∥A∥F ∥X̂k−1 ∥F


eA U
e

3 eB U
U eU
k−1 ∈ BEα32 ,2s (BUk−1 ) α32 = ∥B∥F ∥X̂k−1 ∥F
e − ∈ BEα
UX̂ − ,2s+1 (X̂k− ) αX̂ − = α31 + α32
k X̂ k
k

eA U
U eP
k−1 UAT ∈ BEα41 ,3s (APk−1 A )
e T
α21 = ∥A∥2F ∥Pk−1 ∥F
4
e − ∈ BEα
UP − ,3s+1 (Pk− ) αP − = α41 + ∥Q∥F
k P k
k

U eH T ∈ BEα51 ,4s+1 (P − H T )
e −U α51 = αP − ∥H∥F
P k
k k

U eH T ∈ BEα52 ,5s+1 (HP − H T )


e −U
eH U α52 = α51 ∥H∥F
P k
k
blockencoding ′
5 eAtemp ∈ BEα53 ,5s+2 (Atemp ) −−−−−−−−−→ BEα′ ,s (Atemp )
U α53 = α52 + ∥R∥F , α53 = γα53
53

U
e −1
A
∈ BEα54 ,s+1 (A−1 ′
temp , ϵ )

α54 = κβ/α53
temp

eK ∈ BEα ,5s+2 (Kk ) ′


U k Kk αKk = κβα51 /α53

−U e − ∈ BEα61 ,3s+1 (−H X̂ − )


eH U α61 = αX̂ − ∥H∥F
X̂ k
k k

eZ − U
U e − ∈ BEα62 ,3s+2 (Zk − H X̂ − )
eH U α62 = α61 + ∥Zk ∥F
k X̂ k
6 k

U eZ − U
eK (U e − ) ∈ BEα63 ,8s+4 (Kk (Zk − H X̂ − ))
eH U α63 = α62 αKk
k k X̂ k
k

e ∈ BEα
U ,8s+5 (X̂k ) αX̂k = αX̂ − + α63
X̂k X̂ k k


U k H UP − ∈ BEα71 ,9s+3 (Kk HPk ) α71 = αKk αP − ∥H∥F
eK U
e e
7 k k

eP ∈ BEα ,9s+4 (Pk )


U αPk = α71 + αP −
k Pk
k

8s+5 e (|08s+5 ⟩ ⊗ Is )
X̂k = αX̂k (⟨0 | ⊗ Is )UX̂k αX̂k = αX̂ − + α63
8 k

9s+4 eP (|09s+4 ⟩ ⊗ Is )
Pk = αPk (⟨0 | ⊗ Is )U k αPk = α71 + αP −
k

Figure 8: The quantum circuit of updating PK

4.1 Time complexity theory

Now, let’s analyse the time complexity of this algorithm, which comprises four parts: block encoding, addition of
unitary matrices, multiplication of unitary matrices, and matrix inversion.

10
Figure 9: The quantum circuit of calculating U
e −1
A temp

Figure 10: The quantum circuit of calculating U


eA
temp

(1) The time complexity of block encoding.


According to Theorem 1, if A is an s-qubit square matrix, where A ∈ Cn×n , s = ⌈log n⌉, the quantum-accessible data
structure stores the matrix A in times O(log2 n)[31], Then A can be efficiently block encoded to an ϵ-approximate
unitary UA , an (∥A∥F , s, ϵ)-block encoding of A, with a time complexity of O(polylog(n/ϵ)) in the quantum-accessible
data structure. So the quantum-accessible data structure enables the transformation of A to UA in a time complexity of
O(polylog(n/ϵ)), denoted as TUA .
(2) The time complexity of matrix addition.
If UA is an (α, a, ϵa )-block-encoding of an s-qubit operator A that can be implemented in time TUA , and if UB is a
(β, b, ϵb )-block-encoding of an s-qubit operator B that can be implemented in time TUB , then according to Theorem 3,
we can perform the (α + β, max{a, b} + 1, ϵa + ϵb )-block-encoding of the sum of operators A and B in time complexity
O(TUA + TUB ).
(3) The time complexity of matrix multiplication.
With UA and UB give above, according to Theorem 4, we can perform the (α+β, max{a, b}+1, ϵa +ϵb )-block-encoding
of AB in time complexity O(TUA + TUB ).
(4) The time complexity of matrix inversion.
To solve A−1 , we introduce the matrix polynomial p(A) of degree O(κ log(1/ϵ′ )), which serves as an ϵ′ -approximation
) A . Here, κ represents the condition number and ϵ′ denotes the desired precision. The degree d = O(κ log(1/ϵ′ ))
1 1
to ( κβ
implies that QSVT requires implementing O(d) instances of UA , UA† and (d + 1) interleaved rotations, as depicted in
Figure 5. Consequently, the matrix inversion process for obtaining A−1 through QSVT can be accomplished within a
time complexity of O(TUA d).

4.2 Algorithm complexity analysis

4.2.1 Time complexity analysis


We analyze the time complexity of each procedure and compare it with the classical algorithm.
(1) Block encoding. Before performing block encoding, all the matrices need to have been stored in quantum-accessible
data structure, then the block encoding of A, B, Xk−1 ,

11
Table 3: The time complexity of classical algorithm and quantum algorithm

Procedure Classical algorithm Quantum algorithm

Block encoding 0 O(polylog(n/ϵ))

x̂−
k = Ax̂k−1 + Buk−1 O(n2 ) O(polylog(n/ϵ))

Pk− = APk−1 AT + Q O(n3 ) O(polylog(n/ϵ))

Kk = Pk− H T [HPk− H T + R]−1 O(mn2 ) O(poly log(n/ϵ)κ log(1/ϵ′ ))

x̂k = x̂− −
k + Kk (zk − H x̂k ) O(mn) O(poly log(n/ϵ)κ log(1/ϵ′ ))

Pk = (I − Kk H)Pk− O(n3 ) O(poly log(n/ϵ)κ log(1/ϵ′ ))

Sum O(n3 ) O(poly log(n/ϵ)κ log(1/ϵ′ ))

Uk−1 , Pk−1 , Q, R, Zk in quantum-accessible data structure can be implemented, the time cost of each matrix are all the
same which can be denoted TU , so the block encoding process is finished in time O(TU ), where TU = poly log(n/ϵ).
(2) For U
e − , the total computation time is 4TU , thus enabling the implementation of U
X̂k
e − in O(TU ) time. Similarly,
X̂k
we can also accomplish U − within O(TU ) time.
e
Pk

(3) Calculating U
eK involves addition, multiplication and invertion operations. The total time required for matrix
k
e −1 is 7TU d, where d = O(κ log(1/ϵ′ )), with ϵ′ representing the desired precision of the solution and
inversion UAtemp
κ denoting the condition number (κ > 1). Consequently, the time complexity of this process can be expressed as
O(TU d) = O(poly log(n/ϵ)κ log(1/ϵ′ )).
(4) The calculation step for U
e − involves the operation of U
X̂k
eK , enabling the simulation of U
k
e − in a time complexity
X̂k

of O(poly log(n/ϵ)κ log(1/ϵ )), as well as UeP .
k

In conclusion, the overall time complexity of the algorithm is O(poly log(n/ϵ)κ log(1/ϵ′ )).
Next, we present a complexity comparison between this algorithm and its classical counterpart. In the process of
solving the Kalman filter problem, various matrix operations need to be handled. With brute force computation,
the holistic time complexity of the classical algorithm is O(n3 ). Specifically, naive matrix multiplication for square
matrices with dimensions n × n has a complexity O(n3 ), while Strassen’s algorithm achieves a lower complexity of
O(n2.807 )[33]. Additionally, there are several approaches reducing the computational complexity of the Kalman filter.
Parallel computing can effectively decrease computation time by parallelizing matrix operations within the linear algebra
library that handles these operations[34]. This leads to a reduction in time complexity from O(n) to O(log n), in terms
of the number of time steps taken, rather than reducing it per single step alone. A method known as Fast Algorithm
for Kalman Filtering[35] can further reduce the computational complexity of Pk from O(n3 ) to O(n2 α). From Table
3, we observe that the quantum algorithm exhibits a time complexity of approximately O(poly log(n/ϵ)κ log(1/ϵ′ )),
which still demonstrates exponential acceleration compared with its classical counterpart.

4.2.2 Space complexity analysis

As is depicted in Figure 7 and Figure 8, in addition to the qubits required for constructing |ψ⟩, denoted by s, the
number of the ancilla qubits required for block encoding as well as for implementing matrix addition and multiplication
operations are 8s + 5 and 9s + 4. Additionally, 2-qubit or 3-qubit controlled-U (CU) gates can be found, where U
comprises a combination of CNOT or Toffoli gates. The CU gate may involve up to 5-qubit control gates, which could
require an additional set of 4 ancilla qubits for decomposition into elementary gates at least. It can be seen that the total
number of qubits required is linearly dependent on s.
For instance, when considering an 8-dimensional column vector x0 which can be represented by 3 qubits, the corre-
sponding ancilla qubits required for block encoding and matrix operations amount to 29 and 31 resepctively (s=3),

12
excluding the ancilla qubits needed for some multi-qubit control gates decomposition. We propose two approaches to
reduce the number of ancilla qubits used.
The first approach begins with the construction of block encoding. As is well-known, for any s-qubit matrix A satisfying
∥A∥F ≤ 1, its singular value decomposition can be denoted as W ΣV † , where all the singular values in the diagonal
matrix Σ belong to the interval [0, 1]. Subsequently, an (s + 1)-qubit unitary matrix can be constructed.

  √    √ 
W 0 √ Σ I s − Σ2 V† 0 A W Is − Σ2
UA = = √ . (26)
0 Is Is − Σ2 −Σ 0 Is Is − Σ2 V † −Σ
The matrix A can be block encoded by a single ancilla qubit, denoted as UA , which is a (1, 1)-block-encoding[36].
However, it should be noted that achieving this in practice remains challenging. If such encoding is feasible, the number
of required ancilla qubits would be reduced. Nevertheless, currently there is no known general method to construct an
arbitrary metrix using only one ancilla qubit. Further research and development are still necessary in this area.
The second approach involves measuring each precedure of the algorithm once and subsequently re-block-encoding the
resulting matrix. As an example, consider U
e − which requires (2s + 1) ancilla qubits. If we measure U

e − to obtain

k k

X̂k− and perform block encoding again, only s ancilla qubits are needed. This choice proves advantageous, however,
finding the block encoding for an arbitrary matrix is challenging without a general construction method available in
practice. Moreover, errors can occur during quantum computing measurements, with continuous measurement leading
to error accumulation. Hence, it is crucial to minimize intermediate measurement steps.

5 An illustrative example
The proposed quantum algorithm is demonstrated through a simple illustrative example. We have implemented the
entire algorithm using Qiskit, an open-source software development kit designed for quantum computing[24]. To ensure
simplicity, we consider a state space representation as depicted below:
   
1 −1 1
xk = xk−1 + u + wk−1 (27)
1 1 1 k−1
 
2 0
zk = x + vk (28)
0 1 k
   
2 1 0
Initialize the initial state estimation as x̂0 = , the initial prior covariance matrix as P0 = . The process noise
1 0 1
 
1 0
is modeled as w ∼ N (0, ), while the observation noise is denoted by v ∼ N (0, 1). Therefore, we have matrices
0 1
         
1 −1 1 1 0 1 0 2 0
A= ,B = ,Q = ,R = ,H = . The initial condition is set as u0 = 1, and the
1 1 1 0 1 0 1 0 1
vector z1 is defined as [1, 1]T for the sake of simplicity.
The quantum algorithm of the Kalman filter is outlined as follows:
(1) Construct the block encoding of A, B, P0 , Q, R, H, x̂0 , u0 , z1 , where s=1. These variables are represented as
follows:
 1   1 
1
− 12 ∗ ∗
 √
2
0 ∗ ∗ √
2
0 ∗ ∗
2
1 1  1 √1
∗ ∗ eB =  √2 0 ∗ ∗

eR =  0
 ∗ ∗
U
eA =  2 2 U U
eP = UeQ = U 2 
∗ ∗ ∗ ∗ 0
  ∗ ∗ ∗ ∗ ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ 4×4 ∗ ∗ ∗ ∗ 4×4 ∗ ∗ ∗ ∗ 4×4
 2   2   1 

1 0 ∗ ∗
 √
5
0 0 ∗ √
5
0 ∗ ∗ √
2
0 ∗ ∗
0 0 ∗ ∗ √1 ∗ ∗  1  1
eH =  0 e =  √5 0 ∗ ∗ eZ =  √2 0 ∗ ∗
  
UeU = 
0 ∗ ∗ ∗ ∗ U ∗ 5  U X̂0 U 1
∗ ∗ ∗   ∗ ∗ ∗ ∗   ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗ 4×4 ∗ ∗ ∗ ∗ 4×4 ∗ ∗ ∗ ∗ 4×4 ∗ ∗ ∗ ∗ 4×4
(29)
We must ensure that all matrices are unitary matrices, thus requiring the multiplication of matrix elements by a
normalization factor. Additionally, we assume an exact block encoding with ϵ = 0. Therefore, the block encoding of A
is denoted as BE2,1 (A), and similar treatment is applied to other cases.

13
(2) Let’s compute Ue
AX̂0 and U
eBU separately, then add them together to get U − . The detailed calculation procedure
0 X̂ 1
is shown as follows:
 1  1
∗ ··· ∗ 0 ∗ ··· ∗
 

2 5
0 √
2
3 1
2 5 0
 √ ∗ ··· ∗ 
 √2
 0 ∗ ··· ∗ 
UAX̂0 =  ∗ ∗ ∗ ··· ∗  ∈ BE2√5,2 (AX̂0 ), U ∗
eBU =  ∗ ∗ ··· ∗  ∈ BE√2,2 (BU0 ). (30)
e 
0
 . .. .. . . .. 
  . .. .. . . .. 
 .. . . . .  .. . . . .
∗ ∗ ∗ ··· ∗ ∗ ∗ ∗ ··· ∗
√ √
Let T = 2 5U eBU to be LCU, so the block encoding of X̂ − is
AX̂0 + 2U
e
0 1
 2
0 ∗ ··· ∗

√ √
2 5+ 2
 √4√
 2 5+ 2 0 ∗ · · · ∗

e − = ∗
U ∗ ∗ · · · ∗  ∈ BE2√5+√2,3 (X̂1− ). (31)

X̂1 
 .
.. . .
.. .. . . 
. . .. 
∗ ∗ ∗ ··· ∗

eAP AT is done first, followed by obtaining the block encoding of P − . The


(3) In the similar way, the calculation of U 0 1
specific calculation process is shown as follows:
 1
∗ ··· ∗


2 2
0
1
 0
 √
2 2
∗ · · · ∗ 
eAP AT =  ∗
U ∗ ∗ · · · ∗  ∈ BE4√2,3 (AP0 AT ). (32)
 
0
 . . . .
.. . . . .. 

 .. ..
∗ ∗ ∗ ··· ∗
√ √
Let T = 4 2U eQ , the block encoding of P − is
eAP AT + 2U
0 1
 3 

5 2
0 ∗ ∗
3
e − = 0
 √ ∗ ∗  ∈ BE √ (P − ).
U P1  ∗ 5 2 5 2,4 1 (33)
∗ ∗ ∗
∗ ∗ ∗ ∗

(4) The calculation of the Kalman gain poses one of the primary challenges within the entire algorithm.
Firstly, we conduct matrix multiplication operations to obtain the block encodings of P1− H T and HP1− H T , respectively.
 6
∗ ··· ∗


5 10
0
 0 √3 ∗ · · · ∗
 5 10 
e − T = ∗
U ∗ ∗ · · · ∗  ∈ BE5√10,5 (P1− H T ).
 
P1 H  .
 .. .. .. . . .
. . . .. 
∗ ∗ ∗ ··· ∗
 12 (34)
∗ ··· ∗


25 2
0
3√
 0
 25 2
∗ · · · ∗ 
Ue − T = ∗ ∗ ∗ · · · ∗  ∈ BE25√2,6 (HP1− H T ).
 
HP1 H  .
 .. .. .. . . .
. . . .. 
∗ ∗ ∗ ··· ∗
√ √
Secondly, by setting U
eA
temp
= 25 2U e − T + 2U
HP1 H
eR , we can derive the block encoding for Atemp .
 1
∗ ··· ∗


2 2
0
2√
 0
 13 2
∗ · · · ∗ 
UeA
temp = 
 ∗ ∗ ∗ · · · ∗  ∈ BE26√2,7 (Atemp ). (35)
 . . . . . 
 .. .. .. . . .. 
∗ ∗ ∗ ··· ∗

14
The specific circuit for U
eA
temp is illustrated in Figure 11. At last, Atemp can be obtained by measuring the final state.
The sampling process is 10 iterations, and 8192 shots are executed in each iteration. Of course, each sampling result
has a small difference, and we take the average for the input of the subsequent process. The selected result of Atemp is:

 
13.0000 0
Atemp = (36)
0 4.0010

The value is obtained as


 
13 0
Atemp,c = (37)
0 4
by the classical algorithm. The solution closely aligns with the classical algorithm, showing only a 0.1% discrepancy
upon comparison. However, there are occasional fluctuations in the sampling that may result in an error of 0.01.

Figure 11: The quantum circuit of calculating U


eA
temp

The third step involves calculating the matrix inversion of Atemp using the QSVT method. It is worth noting that
the condition number of Atemp is κ ≈ 3.25. To accomplish this, we utilize pyqsp[37], a Python package specifically
designed for generating QSP (quantum signal processing) phase angles. In our case, we set κ = 3.5 and ϵ = 0.01.
Consequently, we obtain a comprehensive set of QSP phase angles using Chebyshev polynomials that effectively
approximate x1 as follows:
Φ = [−0.06009860, −0.22167921, −0.55045474, −0.77609938, −0.52660613, 0.21660955,
0.38314397, 0.56345849, 0.61656709, −0.40620100, −0.69935839, 0.87923605,
0.07902779, 0.05022705, 1.11206017, −2.71868915, 2.51891920, −0.62276767,
−0.52968031, −0.11403588, −0.72213012, −0.03486492, −0.37990064, 0.80318098,
0.49191184, 1.15950162, −0.60287972, −0.60286045, 1.15950755, −2.64969722,
0.80316442, −0.37990169, −0.03487192, 2.41946175, −0.11403621, −0.52967421,
−0.62277180, −0.62267939, 0.42290199, 1.11205726, 0.05023048, 0.07903506,
−2.26235974, 2.44222583, −0.40619834, −2.52502044, 0.56345461, 0.38314771,
0.21661194, −0.52660677, 2.36549409, −0.55045294, −0.22168027, 1.51069668].
denoted by Φ = [ϕ0 , ϕ1 , · · · , ϕ53 ].
1 1
The corresponding polynomial approximation is shown in Figure 12. The range of x is [−1, − 3.5 ] ∪ [ 3.5 , 1], the scaling
factor of f (x) is 5.40127692.
1 2√
Apparently, the singular values of Atemp are σ1 = √
2 2
, σ2 = 13
but σ2 is out of the range. We need to rescale
,
 2 
13 0
Atemp to obey this condition. The original matrix of Atemp is , we can reconstruct the block encoding of
0 4
Atemp , denoted by U
eA
temp .

√13
 
185
0 ∗ ∗
 0 √4 ∗ ∗
U =  ∈ BE√
185 185,2 (Atemp ). (38)
eA
temp  ∗ ∗ ∗ ∗
∗ ∗ ∗ ∗

15
Figure 12: The function for the polynomial approximation to the inverse function with κ = 3.5 and ϵ = 0.01

Obviously, the singular values of the new matrix Atemp are evidently within the specified range.
It’s easy to get UA† temp through UAtemp . Then we can get the block encoding of P (Atemp ) by constructing the circuit
shown in Figure 13. d = 53, we construct the parameterized circuit consisting of UAtemp , UA† temp are applied alternately
by 53 iterates and 54 rotations that are interleaved in alternating sequence.

0.19306 0 ∗ ··· ∗
 
 0 0.62846 ∗ · · · ∗
 ∗ ∗ ∗ · · · ∗
UP (Atemp ) = 
e   ∈ BE √ 1 ×5.40127692,2 (A−1
temp , 0.001). (39)
 .
.. .
.. .
.. . . 
. . ..  185

∗ ∗ ∗ ··· ∗

Figure 13: The quantum circuit of calculating U


e −1
A temp

Lastly, we calculate the block encoding of K1 = P1− H T A−1


temp .

0.07326 0 ∗ ··· ∗
 
 0 0.11924 ∗ · · · ∗
 ∗ ∗ ∗ ··· ∗
U
eK =  ∈ BE 5√74 (K1 , 0.001). (40)
37 ×5.40127692,7
1  .. .. .. . . .. 
 . . . . . 
∗ ∗ ∗ ··· ∗

(5) Calculate X̂1 = X̂1− + K1 (Z1 − H X̂1− ). Firstly, we can get the block encoding of H X̂1− ,
 4
0 ∗ ··· ∗


10+ 10
 4√
 10+ 10 0 ∗ · · · ∗

e − = ∗
U ∗ ∗ · · · ∗  ∈ BE10+√10,4 (H X̂1− ). (41)

H X̂1  .
 .. .
.. ... . . 
. . .. 
∗ ∗ ∗ ··· ∗

Secondly, we perform the block encoding of Z1 − H X̂1− ,

16
−0.2056 0 ∗ ··· ∗
 
−0.2071 0 ∗ ··· ∗
U

= ∗ ∗ ∗ ··· ∗  ∈ BE √ √ (Z1 − H X̂ − ). (42)
Z1 −H X̂ −
e
10+ 10+ 2,5 1
1  .. .. .. . . .. 
 . . . . .
∗ ∗ ∗ ··· ∗

And then we multiply Uek times U


1
e
Z1 −H X̂1− to get the block encoding of K1 (Z1 − H X̂1− ).

−0.01507 0 ∗ ··· ∗
 
−0.02454 0 ∗ · · · ∗
U
 ∗ ∗ ∗ · · · ∗  ∈ BE91.5237,12 (K1 (Z1 − H X̂ − ), 0.001).
K1 (Z1 −H X̂1− ) =  (43)
e 
1
.. .. .. . . .. 
 . . . . .
∗ ∗ ∗ ··· ∗
√ √
At last, perform matrix addition to get the block encoding of X̂1 . Let T = (2 5 + 2)U e − + 91.5237
X̂1
U
e − , the result is
K1 (Z1 −H X̂1 )

0.00636 0 ∗ ··· ∗
 
0.01801 0 ∗ ··· ∗
 ∗ ∗ ∗ ··· ∗
U
e =  ∈ BE97.41,13 (X̂1 , 0.001). (44)
X̂1  .. .. .. . . .. 
 . . . . .
∗ ∗ ∗ ··· ∗

(6) Calculate P1 = P1− − K1 HP1− . Referring to the previous process, firstly, we can construct the circuit to get the
block encoding of −K1 HP1− .
−0.0278 0 ∗ ··· ∗
 
 0 −0.02262 ∗ · · · ∗
e

U−K1 HP − = 
 ∗ ∗ ∗ · · · ∗  ∈ BE99.2774,12 (−K1 HP − , 0.001). (45)
1
1 .
.. .
.. .. . . .. 
 . . .
∗ ∗ ∗ ··· ∗

And then we add U


e
−K1 HP − to UP − to get the block encoding of P1 .
e
1 1

2.2567 × 10−3 0 ∗ ··· ∗


 
 0 7.0889 × 10−3 ∗ ··· ∗
U
eP

=
 ∗ ∗ ∗ ··· ∗  ∈ BE106.3485,13 (P1 , 0.001). (46)
1
.. .. .. . . .. 
 . . . . .
∗ ∗ ∗ ··· ∗

6 Experimental results and discussion

In order to obtain X̂1 and P1 , it is essential to perform measurements on U e and U


X̂1
eP . To compare the estimated
1
amplitudes with the exact ones, it is crucial to represent the final state in its full-amplitude form.

6.1 The form of the final state


e , we set the initial state to be |0⊗14 ⟩, after U
For U e acting on |0⊗14 ⟩ the final state |ψ ⟩ is:
X̂1 X̂1 X̂1

|ψX̂1 ⟩ = 6.36484546 × 10−3 |00 · · · 00⟩ + 1.80050738 × 10−2 |00 · · · 01⟩


− 8.95345618 × 10−16 |00 · · · 10⟩ + · · · + 3.17131363 × 10−19 |11 · · · 01⟩ (47)
−24 −23
+ 4.02491466 × 10 |11 · · · 10⟩ + 1.10222235 × 10 |11 · · · 11⟩.

17
Figure 14: The quantum circuit of calculating U
e
X̂1

Similarly, for UeP , the initial states are set to |0⊗14 ⟩, |0⊗13 ⟩|1⟩ respectively, after the operation of U
eP the two final
1 1
states are respectively:
|ψP11 ⟩ = 2.25672976 × 10−3 |00 · · · 00⟩ + 2.10564344 × 10−15 |00 · · · 01⟩
+ 1.50448651 × 10−3 |00 · · · 10⟩ + · · · − 6.73134796 × 10−19 |11 · · · 01⟩ (48)
−21 −19
− 1.38326258 × 10 |11 · · · 10⟩ − 8.18294411 × 10 |11 · · · 11⟩.
−16 −3
|ψP12 ⟩ = 3.14223305 × 10 |00 · · · 00⟩ + 7.08894955 × 10 |00 · · · 01⟩
−4
+ 7.52233295 × 10 |00 · · · 10⟩ + · · · + 1.61401008 × 10−20 |11 · · · 01⟩ (49)
−18 −20
+ 1.85712631 × 10 |11 · · · 10⟩ + 2.03004883 × 10 |11 · · · 11⟩.

6.2 Measurement

|ψX ⟩ consists of 214 = 16384 quantum superposition states, the experiment involves conducting 16384 shots in one
sampling iteration. We need 100 iterations for an acceptable result. The resulting probabilities of partial samples in
|ψX̂1 ⟩ are shown in Figure 16. The two values of X̂1 can be obtained by squaring P (|00 · · · 00⟩) and P (|00 · · · 01⟩)
and multiplying by the normalization factor 97.41:
 
0.6201
X̂1 = . (50)
1.7635

The probabilities of partial samples in |ψP11 ⟩ are illustrated in Figure 17. The first row of P1 can be obtained by
squaring the probabilities for |00 · · · 00⟩ and |00 · · · 01⟩ and multiplying the normalization factor 106.3485, respectively.

18
Figure 15: The quantum circuit of calculating U
eP
1

Figure 16: The probabilities of partial samples in |ψX̂1 ⟩

Additionally, Figure 18 displays the probabilities of partial samples in |ψP12 ⟩. Similarly, the second row of P1 can be
derived by the same way:
 
0.2213 0
P1 = . (51)
0 0.7619

19
Figure 17: The probabilities of partial samples in Figure 18: The probabilities of partial samples in
|ψP11 ⟩ |ψP12 ⟩

Figure 19: Comparation of X̂1 between quantum and Figure 20: Comparation of P1 between quantum and
classical approaches classical approaches

The results of X̂1 and P1 obtained through classical approach are:


   
0.6154 0.2308 0
X̂1,c = , P1,c = . (52)
1.75 0 0.75
Due to the random nature of sampling, errors are inevitable in the results obtained from 100 iterations. In our study, we
implemented 10 sets of experiments with each set consisting of 100 and 10,000 iterations respectively (shots=16384).
A comparative analysis between classical and quantum approaches was performed, and the results are illustrated in
Figure 19 and 20. Here x̂0 and x̂1 represent the two elements of vector X̂1 , while P11 and P22 denote two non-zero
entries in matrix P1 . The outcomes obtained from 10000 iterations closely resemble classical results with a negligible
error margin of only 0.01. Conversely, values derived from 100 iterations exhibit a larger error margin of 0.1.

6.3 Error analysis

The previous subsection presents an illustrative example showcasing a quantum verison of the Kalman filter algorithm
using block encoding. By comparing X̂1 , P1 obtained from quantum and classical algorithms, we observe that the
quantum algorithm achieves an error. This error comes from three aspects when the block encoding is completely
accurate:
(1)The algorithm itself. For X̂1 , we can directly calculate the two elements from the amplitude of |0⊗14 ⟩, |0⊗13 ⟩|1⟩,
which are 0.6199 and 1.7519 respectively. The error is 0.001 compared with the result obtained by the classical
approach. A similar conclusion holds for P1 . The error from the algorithm itself mainly coming from the results of
matrix inversion leading to an error in Kalman gain Kk . This is unavoidable because of the polynomial approximation,
and we can only increase the degrees of freedom d to find a Chebyshev polynomial that more closely approximates
f (x) = 1/x and reduce the error as much as possible. In many cases, the matrix inversion also exist errors in the
classical algorithm.
(2) Number of sampling. The errors of the results obtained with 100 and 10000 iterations are different. We can mitigate
the error of the second kind to increase the number of iterations or conduct multiple sets of experiments. However, the

20
number of samples does not increase without bound either. The accuracy is directly proportional to the square root
of the sample size, as it is well-established in scientific literature. The quantum state |ψX ⟩, |ψP1 ⟩, |ψP2 ⟩ consists of
14 qubits, with a total of 214 superposition states. Obtaining accurate probability values through sampling at such a
precision level of 10−4 is challenging and would require approximately 108 samples. But for solving general 2 × 2
matrices, this sampling scale is not necessary.
(3) Normalization factor. X̂0 is a 2-dimensional column vector, but the dimension of U e becomes 214 × 214 ,
X̂1
expanding by a factor of 13. This leads to a significantly large normalization factor for the block-encoded matrix U
e ,
X̂1
reaching around 100 in this instance. We know that the real matrix equals the block-encoded matrix multiplied by the
normalization factor. However, even with an error of only 0.0001 in the block-encoded matrix, it translates to an error
of 0.01 in the real matrix, which is unavoidable.

6.4 Discussion

Furthermore, it is important to consider certain caveats associated with this approach.


(1) The accuracy improvement achieved with 108 samples is only 0.01, indicating compromised precision for faster
computation in this methodology. When comparing the time complexity of quantum and classical algorithms, it’s
often overlooked that both the encoding and measurement processes are time-consuming. Some quantum algorithms
require significant time resources for encoding and measurement procedures. In this algorithm, we have considered
the temporal requirements for block encoding in QRAM while maintaining a lower time complexity compared to
classical algorithms. However, if we also consider the process of measurements, it may not necessarily surpass classical
algorithms as achieving more accurate results with this algorithm requires extensive measurements.
(2) The accumulation of errors. In the previous subsection, we compared the error in calculating X̂k−1 and Pk−1
between the classical and quantum algorithms, which yielded small differences. Furthermore, since X̂k−1 and Pk−1
serve as inputs for the subsequent loop, this implies that the outcomes of both algorithms will diverge. However, it is
difficult to assess the impact of the exact solutions from the classical algorithm and approximate solutions from the
quantum algorithm on the convergence of the Kalman filter. In practice, convergence is influenced by factors such as
system model accuracy, data quality, and parameter selection making it a complex system engineering. Comparing
results between these two algorithms holds limited value directly.
(3) When solving the Kalman filtering algorithm, a crucial task is constructing block encoding, which can be quite
challenging to implement. There is a significant amount of work involved in creating block encoding for matrices,
and typically specific encoding methods exist for certain types of matrices[28, 29]. While there are some generalized
encoding methods available for sparse matrices, block encoding remains a difficult task for more complex matrices.

7 Conclusions

In this paper, we proposed a quantum scheme to solve state estimation in the Kalman filter. By block encoding, we
encoded matrices stored in the quantum-accessible data structure into unitary matrices. Then the quantum circuit of
solving the state estimation of the Kalman filter can be constructed through addition and multiplication rules of block
encoding. Finally, the optimal state estimate is obtained by measuring the quantum state. And our scheme can reduce
the time complexity from O(n3 ) to O(κ log(κ/ϵ′ )poly log(n/ϵ)) without considering the measurement, where n is
matrix dimension, κ is condition number, ϵ is the desired precision in block encoding, ϵ′ is the desired precision in
matrix inversion. That means that an exponential speed-ups can be realized in the quantum algorithm in comparison to
the existing algorithm on classical computers. And of course, the time complexity of block encoding generally takes
O(polylog(n/ϵ)). If a matrix requires s qubits, the total number of needed qubits is linearly dependent on s in the
whole algorithm. So the space complexity of the whole algorithm is O(s).
The method presented in this paper can be applied to solve state estimation of the Kalman filter. Meanwhile, we show
the potential of quantum computing for large-scale control systems. However, there are several problems that need to
be solved in the future. Firstly, we have verified the feasibility of this algorithm theoretically, and the experiment was
performed in a quantum simulator. Due to the large number of qubits and the deep circuit, the verification cannot be
performed by existing quantum computers. Secondly, the construction of block encoding are still challenging, and it
takes a lot of resources to implement. If there is a fast block encoding mechanism, the power of the method based on
block encoding model will be greater. Furthermore, in quantum algorithms, block encoding is a good way to embed
a matrix into a unitary matrix that a quantum computer can perform. We can use this method to solve other control
problems, and thus expand the application field of quantum computing.

21
Acknowledgments
This work was supported by the National Natural Science Foundation of China (No.61673389).

References
[1] Michael A. Nielsen and Isaac L. Chuang. Quantum Computation and Quantum Information 10th Anniversary
Edition. Cambridge University Press, 2010. 10th Anniversary Edition.
[2] Sukhpal Singh Gill, Adarsh Kumar, Harvinder Singh, Manmeet Singh, Kamalpreet Kaur, Muhammad Usman, and
Rajkumar Buyya. Quantum computing: A taxonomy, systematic review and future directions. Software: Practice
and Experience, 2022.
[3] P. Shor. Algorithms for quantum computation: discrete logarithms and factoring. In Proceedings 35th Annual
Symposium on Foundations of Computer Science, pages 124–134, 1994.
[4] Lov K Grover. A fast quantum mechanical algorithm for database search. In Proceedings of the 28th ACM
Symposium on Theory of Computing, pages 212–219. ACM, 1996.
[5] Gilles Brassard, Peter Hoyer, Michele Mosca, and Alain Tapp. Quantum amplitude amplification and estimation.
ArXiv preprint quant-ph/0005055, 2000. https://arxiv.org/abs/quant-ph/0005055.
[6] Aram W. Harrow, Avinatan Hassidim, and Seth Lloyd. Quantum algorithm for linear systems of equations.
Physical Review Letters, 103(15):150502, 2009.
[7] Dominic W. Berry. High-order quantum algorithm for solving linear differential equations. Journal of Physics A:
Mathematical and Theoretical, 47(10):298–307, 2012.
[8] Nathan Wiebe, Daniel Braun, and Seth Lloyd. Quantum algorithm for data fitting. Physical Review Letters,
109(5):050505, 2012.
[9] Ta-Shma and Amnon. Inverting well conditioned matrices in quantum logspace. In Proceedings of the Forty-fifth
Annual ACM Symposium on Theory of Computing, pages 881–890, 2013.
[10] Jacob Biamonte, Peter Wittek, Nicola Pancotti, Patrick Rebentrost, Nathan Wiebe, and Seth Lloyd. Quantum
machine learning. Nature, 549:195–202, 2017.
[11] Leonard Wossnig, Zhikuan Zhao, and Anupam Prakash. Quantum linear system algorithm for dense matrices.
Physical Review Letters, 120:050502, 2017.
[12] András Gilyén, Yuan Su, Guang Hao Low, and Nathan Wiebe. Quantum singular value transformation and beyond:
exponential improvements for quantum matrix arithmetics. In Proceedings of the 51st Annual ACM SIGACT
Symposium on Theory of Computing, pages 193–204, 2019.
[13] Carlos Bravo-Prieto, Ryan LaRose, M. Cerezo, Yigit Subasi, Lukasz Cincio, and Patrick J. Coles. Variational
quantum linear solver: A hybrid algorithm for linear systems. Bulletin of the American Physical Society, 2019.
[14] Pengcheng Shao. Quantum algorithms to matrix multiplication. ArXiv preprint arXiv:1803.01601, 2018.
[15] Hong Li, Nan Jiang, Zichen Wang, Jian Wang, and Ri-gui Zhou. Quantum matrix multiplier. International Journal
of Theoretical Physics, 60:2037–2048, 2021.
[16] Wentao Qi, Alexandr I. Zenchuk, Asutosh Kumar, and Junde Wu. Quantum algorithms for matrix operations and
linear systems of equations. Communications in Theoretical Physics, 76(3):035103, 2022.
[17] Liming Zhao, Zhikuan Zhao, Patrick Rebentrost, and Joseph Fitzsimons. Compiling basic linear algebra subrou-
tines for quantum computers. Quantum Machine Intelligence, 3:21, 2021.
[18] He Sun and Jing Zhang. Solving lyapunov equation by quantum algorithm. Control Theory & Technology,
15:267–273, 2017.
[19] He Sun, Jing Zhang, Rebing Wu, et al. Optimal control protocols can be exponentially accelerated by quantum
algorithms. In Proceedings of Optimal control protocols can be exponentially accelerated by quantum algorithms,
pages 2777–2782, 2016.
[20] Kai Li, Hongyi Dai, and Ming Zhang. Quantum algorithms of state estimators in classical control systems. Science
China Information Sciences, 63:192501, 2020.
[21] Kai Li, Ming Zhang, Xiaowen Liu, et al. Quantum linear system algorithm for general matrices in system
identification. Entropy, 24:893, 2022.
[22] Youngjoo Kim and Hyochoong Bang. Introduction and Implementations of the Kalman Filter. IntechOpen, 2018.

22
[23] Greg Welch and Gary Bishop. An Introduction to Kalman Filter. University of North Carolina at Chapel Hill,
1995.
[24] Qiskit contributors. Qiskit: An open-source framework for quantum computing, 2023.
[25] Lin Lin. Lecture notes on quantum algorithms for scientific computation. ArXiv preprint arXiv:2201.08309, 2022.
[26] Daan Camps, Lin Lin, Roel Van Beeumen, and Chao Yang. Explicit quantum circuits for block encodings of
certain sparse matrices. SIAM Journal on Matrix Analysis and Applications, 45(1), 2024.
[27] Daan Camps and Roel Van Beeumen. Fable: Fast approximate quantum circuits for block-encodings. 2022 IEEE
International Conference on Quantum Computing and Engineering (QCE), pages 104–113, 2022.
[28] B. David Clader, Alexander M. Dalzell, Nikitas Stamatopoulos, et al. Quantum resources required to block-encode
a matrix of classical data. IEEE Transactions on Quantum Engineering, 3:1–23, 2022.
[29] Lin-chun Wan, Yu Chao-Hua, Shijie Pan, et al. Implementing block-encoding with a decomposition of linear
combination of unitaries. arXiv preprint arXiv:1912.12212v1, 2019.
[30] Iordanis Kerenidis and Anupam Prakash. Quantum recommendation systems. In 8th Innovations in Theoretical
Computer Science Conference (ITCS 2017), volume 67 of Leibniz International Proceedings in Informatics
(LIPIcs), pages 49:1–49:21. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2017.
[31] Shantanav Chakraborty, András Gilyén, and Stacey Jeffery. The power of block-encoded matrix powers: improved
regression techniques via faster hamiltonian simulation. In International Colloquium on Automata, Languages
and Programming, 2018.
[32] John M. Martyn, Zane M. Rossi, Andrew K. Tan, and Isaac L. Chuang. Grand unification of quantum algorithms.
PRX Quantum, 2:040203, 2021.
[33] G. H. Golub. Matrix computations. JHU Press, 2012.
[34] M. Raitoharju and R. Piché. On computational complexity reduction methods for kalman filter extensions. IEEE
Aerospace and Electronic Systems Magazine, 34:2–19, 2019.
[35] T. Kailath, A. H. Sayed, and B. Hassibi. Linear estimation. Prentice Hall, 2000.
[36] Yulong. Dong and Lin Lin. Random circuit block-encoded matrix and a proposal of quantum LINPACK benchmark.
Physical Review A, 103:062412, 2021.
[37] I. Chuang, J. Docter, J. M. Martyn, Z. Rossi, and A. Tan. pyqsp 0.1.6, 2022.

23

You might also like