2D Quantum随机行走(Grover行走)不起作用

时间:2018-07-21 04:52:18

标签: python python-3.x

我正在研究量子步态,并尝试对应用于周期性边界条件的二维(8乘8)格罗夫步态进行编码。 enter image description here // 标记为红色的点是初始状态[1000],概率为1.0,然后沿4个方向扩展。 代码在下面。

import numpy as np
import matplotlib.pyplot as plt
import math
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.colors as colors
#import matplotlib.animation as animation

n=1 #time
m=4 #number


#Grover walk
P = [[-1/2, 1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0],[0,0,0,0]] #→
Q = [[0,0,0,0],[1/2, -1/2, 1/2, 1/2],[0,0,0,0],[0,0,0,0]] #←
R = [[0,0,0,0],[0,0,0,0],[1/2, 1/2, -1/2, 1/2],[0,0,0,0]] #↓
S = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[1/2, 1/2,-1/2, -1/2]] #↑
##########
t_list = []
x_list = []
y_list = []
p_list=[]
#phi_map is phi value each vertex.
phi_map = np.zeros((2*m+1, 2*m+1,4),dtype="complex") 
#initial phi
phi_map[0,0]= np.array([1,0,0,0])
#probability each vertex
p_map=np.zeros([2*m+1,2*m+1])
#initial probability each vertex
for i in range(0,2*m+1):
    p_map[i,i] = np.real(np.inner(phi_map[i,i], np.conj(phi_map[i,i])))
    #p_map[i,i]=p
    x_list.append(i)
    y_list.append(i)

#calculate phi for each vertex for time.
for t in range(0,n+1):
    t_list.append(t)
    if t == 0:
        print("foool")
    else: #next_phi_map is for new phi.
        next_phi_map = np.zeros((2*m+1,2*m+1, 4),dtype="complex")
        for x in range(0,2*m+1):
            if x == 0:  #periodic boundary coinditons
                for y in range(0,2*m+1):
                    if y == 0:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[2*m,y]) + np.dot(Q, phi_map[x+1,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,2*m])])
                    elif y == 2*m:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[2*m,y]) + np.dot(Q, phi_map[x+1,y]) + np.dot(R, phi_map[x,0]) + np.dot(S, phi_map[x,y-1])])
                    else:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[2*m,y]) + np.dot(Q, phi_map[x+1,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,y-1])])
            elif x == 2*m:
                for y in range(0,2*m+1):
                    if y == 0:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y]) + np.dot(Q, phi_map[0,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,2*m])])
                    elif y == 2*m:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y]) + np.dot(Q, phi_map[0,y]) + np.dot(R, phi_map[x,0]) + np.dot(S, phi_map[x,y-1])])
                    else:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y]) + np.dot(Q, phi_map[0,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,y-1])])
            elif x == 2 and y == 2:
                next_phi_map[2,2]=-np.array([np.dot(P, phi_map[x+1,y]) + np.dot(Q, phi_map[x-1,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,y-1])])
            else:
                for y in range(0,2*m+1):
                    if y == 0:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y]) + np.dot(Q, phi_map[x+1,y]) + np.dot(R, phi_map[x,y+1]) + np.dot(S, phi_map[x,2*m])])
                    elif y == 2*m:
                        next_phi_map[x,y] = np.array([np.dot(P, phi_map[x-1,y]) + np.dot(Q, phi_map[x+1,y]) + np.dot(R, phi_map[x,0]) + np.dot(S, phi_map[x,y-1])])
                    else:
                        next_phi_map[x,y] = np.array([np.inner(P, phi_map[x-1,y]) + np.inner(Q, phi_map[x+1,y]) + np.inner(R, phi_map[x,y+1]) + np.inner(S, phi_map[x,y-1])])
            #print(t,mean_0,mean_1,mean_2,mean_3)
                    p_map[x,y] = np.real(np.inner(next_phi_map[x,y], np.conj(next_phi_map[x,y])))
        phi_map = next_phi_map
    #print(t,phi_map[0])
    mean_0 = phi_map[0].sum()/(4*m**2) #= np.array([(2*mean - next_phi_map[x,y][0])])
    mean_1 = phi_map[1].sum()/(4*m**2) #= np.array([(2*mean - next_phi_map[x,y][1])])
    mean_2 = phi_map[2].sum()/(4*m**2) #= np.array([(2*mean - next_phi_map[x,y][2])])
    mean_3 = phi_map[3].sum()/(4*m**2) #= np.array([(2*mean - next_phi_map[x,y][3])])
    phi_map[0] = 2*mean_0 - phi_map[0]
    phi_map[1] = 2*mean_1 - phi_map[1]
    phi_map[2] = 2*mean_2 - phi_map[2]
    phi_map[3] = 2*mean_3 - phi_map[3]

    for i in range(0,2*m+1):
        for j in range(0,2*m+1):
            print("t = {}   ({}, {}):{}".format(t, i, j, phi_map[i, j]))

结果是

t = 0   (0, 0):[-0.96875+0.j  0.03125+0.j  0.03125+0.j  0.03125+0.j]
t = 0   (0, 1):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 2):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 3):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 4):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 5):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 6):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 7):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (0, 8):[0.03125+0.j 0.03125+0.j 0.03125+0.j 0.03125+0.j]
t = 0   (1, 0):[0.+0.j 0.+0.j 0.+0.j 0.+0.j]
t = 0   (1, 1):[0.+0.j 0.+0.j 0.+0.j 0.+0.j]
.
.
.

除了t = 0时的初始概率外,我不知道为什么该概率具有某些值。 我期待着您的指导和支持。

0 个答案:

没有答案