Bohrium
robot
新建

空间站广场

论文
Notebooks
比赛
课程
Apps
我的主页
我的Notebooks
我的论文库
我的足迹

我的工作空间

任务
节点
文件
数据集
镜像
项目
数据库
公开
Introduction to Quantum Simulation Algorithms
Quantum Computing
English
Quantum ComputingEnglish
zhoushuo@dp.tech
发布于 2023-07-19
推荐镜像 :Basic Image:bohrium-notebook:2023-04-07
推荐机型 :c2_m4_cpu
赞 6
1
11
Introduction to Quantum Simulation Algorithms
1. Hamiltonian Simulation
1.1 Quantum Circuit: why we need to break Hamiltonian into local terms
1.2 Product Formula
1.2.1 Lie-Trotter Formula
1.2.2 Trotter-Suzuki Formula
1.3 qDRIFT Algorithm
1.4 More About Efficient Simulation
2. Variational Quantum Eigensolver
2.1 Schematic of VQE
2.2 Quantum Circuit: trial state preparation
3. Reference

Introduction to Quantum Simulation Algorithms

代码
文本

©️ Copyright 2023
Author:Shuo Zhou(周烁) 📨
To execute this document directly, please click the Connect button at the top of Bohrium Notebook Interface.

代码
文本

Quantum Computing is a computing model that is different from classical computing. In the 1970s and 1980s, with the development of quantum mechanics, the need to observe and simulate quantum systems was raised, and the idea of building "quantum computers" that follow the principles of quantum mechanics rather than those of classical physics was born.

Quantum Algorithm refers to algorithm that runs on a realistic model of quantum computing. Quantum algorithms often take advantage of the quantum superposition and entanglement properties of quantum computing to achieve speedups over classical algorithms for specific tasks. The most famous examples include the quantum algorithm for prime factorisation of large numbers proposed by Shor in 1994 [1], the quantum algorithm for unordered list search proposed by Grover in 1996 [2], and the quantum simulation algorithm introduced in this issue of the Notebook.

Quantum Simulation Algorithm dates back to 1982 [3], when Feynman, in his talk "Simulating Physics with Computers", suggested that it was inherently difficult to simulate the evolution of quantum systems using classical computers, and that using "quantum computers" to do so might be a viable path. In 1996, Seth Lloyd proposed the first explicit algorithm based on the Product Formula [4]. Since then, more quantum simulation algorithms have emerged, with applications ranging from quantum field theory to quantum chemistry and condensed matter physics.

Intuitively, we could classify quantum simulation problems into two catogories:

50171F97-5B3B-4472-B9DB-38A5991B54CA.png

代码
文本

1. Hamiltonian Simulation

In quantum mechanics, time evolution of the wave function is governed by the Schrdinger equation, For independent of time, the solution is: Many natural Hamiltonians have the form of a sum of terms, common expamles include:

  • A particle in a potential:
  • A -local Heisenberg spin model:

For numerical example, we choose Heisenberg model on a lattice. Without loss of generality, we assume there is no external magnetic field (), and the interaction length equals unit ().

The Hamiltonian is , where , and are Pauli operators acting on the -th spin, where the summation is over all neighboring spin pairs. We decompose the Hamiltonian into tree interaction terms: , respectively represented by yellow, green, and red bonds.

5E1CCEB3-436E-4881-994C-96AF09699B6A.png

In the following code, "np.kron" means tensor product between Pauli Matrices under the basis of spins.

代码
文本
[2]
import numpy as np
from scipy.linalg import kron, expm, norm
import matplotlib.pyplot as plt

# Pauli Matrices
X = np.array([[0,1],[1,0]])
Y = np.array([[0,-1j],[1j,0]])
Z = np.array([[1,0],[0,-1]])
I = np.array([[1,0],[0,1]])

# System Size: two L-length Single Chains
L = 3
N = 2 * L

# Construct Local Hamiltonians: H1, H2, and H3
H1 = - sum(kron(kron(op, op), np.eye(2**(L+1))) + kron(kron(np.eye(2**L), kron(op, op)), np.eye(2)) for op in [X, Y, Z])
H2 = - sum(kron(kron(np.eye(2),kron(op, op)), np.eye(2**L)) + kron(np.eye(2**(L+1)), kron(op,op)) for op in [X, Y, Z])
H3 = - sum(kron(kron(kron(kron(np.eye(2**i), op), np.eye(2**(L-1))), op), np.eye(2**(L-1-i))) for i in range(0,L) for op in [X, Y, Z])

# Construct Total Hamiltonian
H = H1 + H2 + H3
代码
文本

1.1 Quantum Circuit: why we need to break Hamiltonian into local terms

代码
文本

In quantum computing, we generally utilize subsets consisting of few single or two-qubit gates to approximate any unitary operation.

You've probably heard some common gate elements such as Control-NOT, Rotation-Pauli, Hardamard and so on. On top of that, we can simulate tensor product of Pauli matrix. For instance, the following figure shows "unit" quantum circuit for implementing :

image.png

代码
文本

If we could analyse the relationship between original time-evolution operator and "unit" quantum circuit as the figure above, in principle we could simulate many natural Hamiltonians. In fact, there are following mathematical theorems in a nutshell:

代码
文本

1.2 Product Formula

1.2.1 Lie-Trotter Formula

In Lie algebra, for possibly noncommutative operator and , the product of their exponential does not behave that simply according to Baker–Campbell–Hausdorff formula: For Hamiltonian with local interactions, , only when for all j,k could we split the time-evolution operator as products: However, even in general cases where the term do not commute with each other, an enlightening idea is splitting time into segments, called Lie formula or Trotterization:

代码
文本
[3]
# System size: N, Local Hamlitonians: H_list
def Lie_Trotter(N, H_list, t_step, r):
U = np.eye(pow(2,N))
U_step = np.eye(pow(2,N))
for H_local in H_list:
U_step = U_step @ expm(-1j * H_local * t_step)
for i in range(r):
U = U @ U_step
return U
代码
文本

1.2.2 Trotter-Suzuki Formula

By Taylor's theorem we can calculate the error bounds by straightforward algebra: Generally, for Hamiltonian with terms, one could define recursively: Thus we have a very significant result called Trotter Suzuki formula [5], p-order expansion satisfies:

代码
文本
[4]
# 2-order Trotter-Suzuki Decomposition
def Trotter_Suzuki_2(N, H_list, t_step, r):
U = np.eye(pow(2,N))
U_step = np.eye(pow(2,N))
for H_local in H_list:
U_step = U_step @ expm(-1j * H_local * t_step / 2)
for H_local in reversed(H_list):
U_step = U_step @ expm(-1j * H_local * t_step / 2)
for i in range(r):
U = U @ U_step
return U
代码
文本
[5]
# Define p-order Trotter-Suzuki Decomposition by Recursion
def Trotter_Suzuki(N, H_list, t_step, r, p):
if p == 1:
return Lie_Trotter(N, H_list, t_step, r)
elif p == 2:
return Trotter_Suzuki_2(N, H_list, t_step, r)
else:
u = 1/(4-pow(4,1/(p-1)))
return Trotter_Suzuki(N, H_list, u * t_step, r, p-2) @ Trotter_Suzuki(N, H_list, u * t_step, r, p-2) @ Trotter_Suzuki(N, H_list, (1-4*u) * t_step, r, p-2) @ Trotter_Suzuki(N, H_list, u * t_step, r, p-2) @ Trotter_Suzuki(N, H_list, u * t_step, r, p-2)
代码
文本

If we measure the Trotter Error by spectral norm, let's change the timestep and Trotter number, plot the error using 2-order Trotter-Suzuki formula. We could see that the cubic function fits the error very well, as the theory predicted.

代码
文本
[6]
fig,ax = plt.subplots()

# Timestep and Trotter Number
timestep_list = [0.005, 0.008, 0.010, 0.012, 0.015, 0.017, 0.020]
pivot = np.linspace(min(timestep_list), max(timestep_list), 100)
trotter_number_list = [50, 100, 150, 200]

# Plot
for r in trotter_number_list:
trotter_error = []
for t_step in timestep_list:
trotter_error.append(norm(expm(-1j * H * t_step * r) - Trotter_Suzuki_2(2*L, [H1, H2, H3], t_step, r),2))
coefficients = np.polyfit(timestep_list, trotter_error, 3)
poly = np.poly1d(coefficients)
ax.scatter(timestep_list, trotter_error, marker = '*')
ax.plot(pivot, poly(pivot), label = "r = {r}".format(r = r))

ax.set_title("Trotter Error of Simulating Heisenberg Model")
ax.set_xlabel("Step Size ($s$)")
ax.set_ylabel("Trotter Error ($\epsilon$)")
ax.legend()
plt.show()
代码
文本

1.3 qDRIFT Algorithm

Since the permutation of local terms in Trotter-Suzuki Formula is chosen arbitrarily. Without loss of generality, In 2018, Campbell imported randomness to seek possible improvement [6].

代码
文本
[7]
# qDRIFT Algorithm
def U_qDRIFT(N, H_list, t, step_number):
norm_list = []
for H_l in H_list:
norm_list.append(norm(H_l, 2))

total_sum = sum(norm_list)
unitary_list = []
for index in range(len(H_list)):
unitary_list.append(expm(-1j * (total_sum / norm_list[index]) * H_list[index] * (t / step_number)))

probabilities = norm_list/total_sum

# Randomly Generate
U_qDrift = np.eye(2**(N))
for i in range(step_number):
selected_index = np.random.choice(len(probabilities), p = probabilities)
U_qDrift = U_qDrift @ unitary_list[selected_index]
return U_qDrift

代码
文本
[8]
fig,ax = plt.subplots()

# Evolution Time and Random Walk Step Number
step_number_list = [1000, 10000, 20000, 50000, 100000]
pivot = np.linspace(min(np.log(step_number_list)/np.log(10)), max(np.log(step_number_list)/np.log(10)), 100)
t_list = [1.0, 3.0, 5.0, 10.0]

for t in t_list:
qDRFIT_Error = []
for step_number in step_number_list:
qDRFIT_Error.append(norm(expm(-1j * H * t) - U_qDRIFT(2*L, [H1, H2, H3], t, step_number),2))
coefficients = np.polyfit(np.log(step_number_list)/np.log(10), np.log(qDRFIT_Error)/np.log(10), 1)
poly = np.poly1d(coefficients)
ax.scatter(np.log(step_number_list)/np.log(10), np.log(qDRFIT_Error)/np.log(10), marker = '*')
ax.plot(pivot, poly(pivot), label = "t = {t}".format(t = t))
ax.set_title("qDRIFT Error of Simulating Heisenberg Model")
ax.set_xlabel("Logarithmic Step Number ($\lg(r)$)")
ax.set_ylabel("Logarithmic qDRIFT Error ($\lg(\epsilon)$)")
ax.legend()
plt.show()
代码
文本

The slopes of the lines are all almost -1/2, which roughly verify the theory: qDRIFT_Error ~ .

What's worth mentioning, the qDRIFT algorithm is easy to be mistaken for randmom permutation Trotter-Suzuki algorithm [7], which simply averages the time-evolution quantum channel over all permutation of local Hamiltonians.

代码
文本

1.4 More About Efficient Simulation

We say can be effeciently simulated if for any , there is a quantum circuit consisting of poly gates such that .

Generally, the problem of simulating Hamiltonians is BQP-hard.

Up to now, mainstream algorithms for quantum simulation include:

  1. Product Formula [3]: the most straightforward approach first proposed.
  2. Randomized Product Formula [6, 7]: randomly permuting terms in product formula & the qDRIFT algorithm.
  3. Truncated Taylor Series [8]: an alternative approach that leverages LCU achieves complexity poly.
  4. Quantum Singnal Processing [9]: an approach based on qubitization and block-encoding with an optimal complexity tradeoff.
代码
文本

2. Variational Quantum Eigensolver

The variational quantum eigensolver (VQE) [10] is a method that uses a hybrid quantum-classical computational approach to find eigenvalues of a Hamiltonian.

2.1 Schematic of VQE

It starts with a reasonable assumption about the form of the target wave function. A trial wave function or ansatz is constructed with adjustable parameters, followed by the design of a quantum circuit capable of realizing this ansatz. The ansatz parameters are then variationally adjusted until the expectation value of the electronic Hamiltonian is minimized:

Here is a schematic of variational quantum eigensolver (VQE) that minimizes the energy of Fermionic Hamiltonian . It uses classical computing resources denoted by green color and quantum computing resources denoted by blue. A simulation starts by constructing wavefunction ansatz with a set of initial parameter. Then the quantum computer prepares the trial state by applying parameterized unitary on Hatree-Fock wavefunction, and at iteration , the energy of the Hamiltonian is computed by measuring every Hamiltonian term and adding them on a classical computer. Next, the clasical optimization algorithm updates the parameter and feedbacks to the quantum computer. Finally the quantum computer generates a new state and goes round.

A2107146-4F33-41DD-8BCD-ECF841A51E60.png

We use TenCirChem from Tencent to implement Quantum Chemistry Computation: https://github.com/tencent-quantum-lab/TenCirChem

In the following code, h4 represents chain consisting of 4 H atoms, the UCCSD is a wavefunction ansatz for optimization, which is chemistry-inspired and represents a unitary version of the classical non-unitary CCSD method.

代码
文本
[ ]
! pip install tencirchem
代码
文本
[12]
from tencirchem import UCCSD, M

d = 0.8
# Distance Unit is Angstrom
h4 = M(atom=[["H", 0, 0, d * i] for i in range(4)])

# Configuration
uccsd = UCCSD(h4)
# Calculate and Returns Energy
uccsd.kernel()
# Analyze Result
uccsd.print_summary(include_circuit=True)
################################ Ansatz ###############################
 #qubits  #params  #excitations initial condition
       8       11            18               RHF
############################### Circuit ###############################
 #qubits  #gates  #CNOT  #multicontrol  depth  #FLOP
       8     146     98             10     78 506688
############################### Energy ################################
       energy (Hartree)  error (mH) correlation energy (%)
HF            -2.121387   46.173788                 -0.000
MP2           -2.151794   15.766505                 65.854
CCSD          -2.167556    0.004979                 99.989
UCCSD         -2.167546    0.014384                 99.969
FCI           -2.167561    0.000000                100.000
############################# Excitations #############################
      excitation configuration     parameter  initial guess
0         (6, 4)      01100011 -6.291323e-03       0.000000
1         (2, 0)      00110110 -6.291323e-03       0.000000
2         (7, 4)      10100011  9.142024e-17       0.000000
3         (3, 0)      00111010  9.142024e-17       0.000000
4         (6, 5)      01010011  2.013444e-16       0.000000
5         (2, 1)      00110101  2.013444e-16       0.000000
6         (7, 5)      10010011  3.686593e-03       0.000000
7         (3, 1)      00111001  3.686593e-03       0.000000
8   (2, 6, 5, 1)      01010101 -1.399103e-01      -0.081208
9   (2, 6, 4, 0)      01100110 -5.239766e-02      -0.045444
10  (2, 7, 5, 0)      10010110 -5.250098e-02      -0.032406
11  (6, 3, 1, 4)      01101001 -5.250098e-02      -0.032406
12  (3, 7, 5, 1)      10011001 -2.991510e-02      -0.029495
13  (3, 7, 4, 0)      10101010 -3.308486e-02      -0.022896
14  (6, 7, 5, 4)      11000011 -2.457277e-02      -0.018145
15  (2, 3, 1, 0)      00111100 -2.457277e-02      -0.018145
16  (3, 6, 5, 0)      01011010 -2.856758e-02      -0.014261
17  (7, 2, 1, 4)      10100101 -2.856758e-02      -0.014261
######################### Optimization Result #########################
            e: -2.1675461600271344
          fun: array(-2.16754616)
     hess_inv: <11x11 LbfgsInvHessProduct with dtype=float64>
   init_guess: [0.0, 0.0, 0.0, 0.0, -0.018145135788852563, -0.04544411015309671, -0.022896105235218407, -0.03240648017333939, -0.01426134438448682, -0.08120787303242095, -0.02949460893918542]
          jac: array([-1.37001897e-08,  6.68513448e-21,  1.11607575e-19,  1.18183576e-09,
       -1.78964662e-09, -6.83009106e-09,  3.43035067e-09,  7.86964607e-09,
        1.11886073e-08,  4.56193371e-09,  1.70279067e-09])
      message: 'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
         nfev: 13
          nit: 11
         njev: 13
     opt_time: 0.02908802032470703
 staging_time: 8.106231689453125e-06
       status: 0
      success: True
            x: array([-6.29132329e-03,  9.14202447e-17,  2.01344373e-16,  3.68659333e-03,
       -2.45727657e-02, -5.23976611e-02, -3.30848564e-02, -5.25009838e-02,
       -2.85675846e-02, -1.39910303e-01, -2.99150954e-02])
代码
文本

2.2 Quantum Circuit: trial state preparation

代码
文本
[13]
# Display the Quantum Circuit of the Trial State Preparation
circuit = uccsd.get_circuit()
circuit.draw(output="mpl")
代码
文本

3. Reference

  1. Peter W. Shor, Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer, SIAM Journal on Computing 26 (1997), no. 5, 1484–1509, quant-ph/9508027, preliminary version in FOCS 1994.
  2. Lov K. Grover, Quantum mechanics helps in searching for a needle in a haystack, Physical Review Letters 79 (1997), no. 2, 325–328, quant-ph/9706033, preliminary version in STOC 1996.
  3. Richard P. Feynman, Simulating physics with computers, International Journal of Theoretical Physics 21 (1982), no. 6, 467-488.
  4. Seth Lloyd, Universal quantum simulators, Science 273 (1996), 1073-1078.
  5. Masuo Suzuki, Fractal decomposition of exponential operators with applications to many-body theories and Monte Carlo simulations, Physics Letter A (1990), 319-323.
  6. Earl Campbell, Random compiler for fast hamiltonian simulation, Physical Reivew Letters 123 (2019), no. 7, 070503, arXiv:1811.08017.
  7. Andrew M. Childs, Aaron Ostrander, and Yuan Su, Faster quantum simulation by randomization, Quantum 3 (2019), 182, arXiv:1805.08385.
  8. Dominic W. Berry, Andrew M. Childs, Richard Cleve, Robin Kothari, and Rolando D. Somma, Simulating hamiltonian dynamics with a truncated taylor series, Physical Review Letters 114 (2015), no. 9, 090502, arXiv:1412.4687.
  9. Guang Hao Low and Isaac L. Chuang, Optimal hamiltonian simulation by quantum signal processing, Physical Review Letters 118 (2017), no. 1, 010501, arXiv:1606.02685.
  10. Dmitry A. Fedorov, Bo Peng, Niranjan Govind, Yuri Alexeev, VQE method: a short survey and recent developments, Materials Theory 6 (2022), arXiv:2103.08505.
代码
文本
Quantum Computing
English
Quantum ComputingEnglish
已赞6
本文被以下合集收录
Quantum computing
bohrc6fa4a
更新于 2024-09-10
1 篇0 人关注
Read collection
kirk0830
更新于 2024-09-04
1 篇0 人关注
推荐阅读
公开
Delta Machine Learning在量化计算领域的应用(论文复现)
Deep Learning中文PyTorch
Deep Learning中文PyTorch
jinyucheng
发布于 2023-11-08
4 赞3 转存文件1 评论
公开
AI直接求解电子波函数的尝试——从FermiNet说起
Deep Learning中文notebookAI4S科学计算QMCVMC机器学习及其在化学中的应用NBHub量子化学
Deep Learning中文notebookAI4S科学计算QMCVMC机器学习及其在化学中的应用NBHub量子化学
JoeYoung
发布于 2023-10-20
4 赞4 转存文件