-
Notifications
You must be signed in to change notification settings - Fork 1
/
numericalp2.py
382 lines (293 loc) · 8.56 KB
/
numericalp2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
import numpy as np
import matplotlib.pyplot as plt
from pathlib import Path
from scipy.linalg import expm
from datetime import datetime
from multiprocessing import Pool
import pandas as pd
#this script computes dynamical, Berry and AB phases for p=1
r=1e-4
tTot=10*1000
B=2
Q=int(1e6)
dt=tTot/Q
p=2
def phiSEN(t):
#counter clockwise path
return -1/2*np.pi+np.pi/tTot*t
def phiSWN(t):
#clockwise path
return -1/2*np.pi-np.pi/tTot*t
def k1(phi):
return r*np.cos(phi)
def k2(phi):
return r*np.sin(phi)
def beta(k1Val,k2Val):
return B*(-1+np.cos(k1Val)+np.cos(k2Val))
def gamma(k1Val,k2Val):
return B*(np.sin(k1Val)-1j*np.sin(k2Val))
def solution(gVal,betaVal,gammaVal):
#solve real values of x, sorted from small to large (with sign)
inList=[gVal**2,4*betaVal*gVal,4*betaVal**2-gVal**2+4*np.abs(gammaVal)**2,-4*betaVal*gVal,-4*betaVal**2]
roots=np.roots(inList)
realRoots=[]
for oneRoot in roots:
if np.abs(np.imag(oneRoot))<=1e-8 and np.abs(np.real(oneRoot))<=1:
realRoots.append(np.real(oneRoot))
rst=sorted(realRoots)
return rst
def x2E(x,gVal,betaVal):
"""
:param x:
:param gVal:
:param betaVal:
:return: transform x to E for p=2
"""
E=(1/4*gVal*x**3+betaVal)/x+3/4*gVal
return E
def E2x(gVal,betaVal,gammaVal):
#choose the value of x based on the value of E
xs=solution(gVal,betaVal,gammaVal)
EVals=[x2E(x,gVal,betaVal) for x in xs]
indsOfE=np.argsort(EVals)#ascending order
if gVal>0:
#choose the lowest band
indx=indsOfE[0]
else:
#choose the highest band
indx=indsOfE[-1]
x=xs[indx]
E=EVals[indx]
return [E,x]
def initVec(gVal,betaVal,gammaVal):
#computes the 2 components of initial vector, psi1 and psi2
E,x=E2x(gVal,betaVal,gammaVal)
psi1=np.sqrt(1/2+1/2*x)
psi2=(E-betaVal-gVal*np.abs(psi1)**(2*p))/gammaVal*psi1
return np.array([psi1,psi2])
def oneStepSEN(q,gVal,psiIn):
"""
:param q:
:param gVal:
:param psiIn:
:return: next step along SEN
"""
tq=q*dt
psi1q=psiIn[0]
psi2q=psiIn[1]
###step 1: nonlinear evolution for 1/2 dt
y1=psi1q*np.exp(-1j*gVal*np.abs(psi1q)**(2*p)*1/2*dt)
y2=psi2q*np.exp(-1j*gVal*np.abs(psi2q)**(2*p)*1/2*dt)
yVec=np.array([y1,y2])
###step 2: linear evolution for dt
phiVal=phiSEN(tq+1/2*dt)
k1Val=k1(phiVal)
k2Val=k2(phiVal)
betaVal=beta(k1Val,k2Val)
gammaVal=gamma(k1Val,k2Val)
h0=np.array([[betaVal,gammaVal],[np.conj(gammaVal),-betaVal]])
zVec=expm(-1j*dt*h0).dot(yVec)
###step 3: nonlinear evolution for 1/2 dt
z1,z2=zVec
psi1Next=z1*np.exp(-1j*gVal*np.abs(z1)**(2*p)*1/2*dt)
psi2Next=z2*np.exp(-1j*gVal*np.abs(z2)**(2*p)*1/2*dt)
return np.array([psi1Next,psi2Next])
def oneStepSWN(q, gVal, psiIn):
"""
:param q:
:param gVal:
:param psiIn:
:return: next step along SWN
"""
tq = q * dt
psi1q = psiIn[0]
psi2q = psiIn[1]
###step 1: nonlinear evolution for 1/2 dt
y1 = psi1q * np.exp(-1j * gVal * np.abs(psi1q) ** (2 * p) * 1 / 2 * dt)
y2 = psi2q * np.exp(-1j * gVal * np.abs(psi2q) ** (2 * p) * 1 / 2 * dt)
yVec = np.array([y1, y2])
###step 2: linear evolution for dt
phiVal = phiSWN(tq + 1 / 2 * dt)
k1Val = k1(phiVal)
k2Val = k2(phiVal)
betaVal = beta(k1Val, k2Val)
gammaVal = gamma(k1Val, k2Val)
h0 = np.array([[betaVal, gammaVal], [np.conj(gammaVal), -betaVal]])
zVec = expm(-1j * dt * h0).dot(yVec)
###step 3: nonlinear evolution for 1/2 dt
z1, z2 = zVec
psi1Next = z1 * np.exp(-1j * gVal * np.abs(z1) ** (2 * p) * 1 / 2 * dt)
psi2Next = z2 * np.exp(-1j * gVal * np.abs(z2) ** (2 * p) * 1 / 2 * dt)
return np.array([psi1Next, psi2Next])
def thetaDqSEN(q,gVal,psiIn):
"""
:param q:
:param psiIn:
:param gVal:
:return: one dynamical phase at time step q along SEN
"""
tq=dt*q
phiVal = phiSEN(tq)
k1Val = k1(phiVal)
k2Val = k2(phiVal)
betaVal = beta(k1Val, k2Val)
gammaVal = gamma(k1Val, k2Val)
h0 = np.array([[betaVal, gammaVal], [np.conj(gammaVal), -betaVal]])
psi1q=psiIn[0]
psi2q=psiIn[1]
thetaDq=-(np.conj(psiIn).dot(h0).dot(psiIn)*dt\
+gVal*(np.abs(psi1q)**(2*p+2)+np.abs(psi2q)**(2*p+2))*dt)
return thetaDq
def thetaDqSWN(q,gVal,psiIn):
"""
:param q:
:param gVal:
:param psiIn:
:return: one dynamical phase at time step q along SWN
"""
tq = dt * q
phiVal = phiSWN(tq)
k1Val = k1(phiVal)
k2Val = k2(phiVal)
betaVal = beta(k1Val, k2Val)
gammaVal = gamma(k1Val, k2Val)
h0 = np.array([[betaVal, gammaVal], [np.conj(gammaVal), -betaVal]])
psi1q = psiIn[0]
psi2q = psiIn[1]
thetaDq = -(np.conj(psiIn).dot(h0).dot(psiIn) * dt \
+ gVal * (np.abs(psi1q) ** (2 * p + 2) + np.abs(psi2q) ** (2 * p + 2)) * dt)
return thetaDq
def thetaDSEN(gVal,psiAll):
"""
:param gVal:
:param psiAll: wavefuction at q=0,1,...,Q
:return: total dynamical phase along SEN
"""
thetaD=0
for q in range(0,Q):
psiq=psiAll[q]
thetaD+=thetaDqSEN(q,gVal,psiq)
return thetaD
def thetaDSWN(gVal,psiAll):
"""
:param gVal:
:param psiAll: wavefuction at q=0,1,...,Q
:return: total dynamical phase along SWN
"""
thetaD=0
for q in range(0,Q):
psiq=psiAll[q]
thetaD+=thetaDqSWN(q,gVal,psiq)
return thetaD
def dtPsiq(psiAll):
"""
:param psiAll: wavefunction at q=0,1,...,Q
:return: time derivative of wavefunction at q=0,1,...,Q-1
"""
dtPsi=[]
#time derivative of psi at q=0
psi1=psiAll[1]
psi2=psiAll[2]
psi0=psiAll[0]
dtPsi.append((4*psi1-psi2-3*psi0)/(2*dt))
#time derivative of psi at q=1,...,Q-1
for q in range(1,Q):
dtPsi.append((psiAll[q+1]-psiAll[q-1])/(2*dt))
return dtPsi
def thetaB(psiAll):
"""
:param psiAll: wavefunction at q=0,1,...,Q
:return: total Berry phase
"""
timeDifferential=dtPsiq(psiAll)
thetaBTotal=0
for q in range(0,Q):
thetaBTotal+=np.vdot(psiAll[q],timeDifferential[q])
thetaBTotal*=dt*1j
return thetaBTotal
def evolutionSEN(gVal):
"""
:param gVal:
:return: wavefunctions along path SEN
"""
phi0=phiSEN(0)
k10=k1(phi0)
k20=k2(phi0)
gamma0=gamma(k10,k20)
beta0=beta(k10,k20)
psi0=initVec(gVal,beta0,gamma0)
# print([np.abs(psi0[0]),np.abs(psi0[1])])
psiAllSEN=[psi0]
for q in range(0,Q):
psiAllSEN.append(oneStepSEN(q,gVal,psiAllSEN[q]))
return psiAllSEN
def evolutionSWN(gVal):
"""
:param gVal:
:return: wavefunctions along path SWN
"""
phi0 = phiSWN(0)
k10 = k1(phi0)
k20 = k2(phi0)
gamma0 = gamma(k10, k20)
beta0 = beta(k10, k20)
psi0 = initVec(gVal, beta0, gamma0)
psiAllSWN = [psi0]
for q in range(0, Q):
psiAllSWN.append(oneStepSWN(q, gVal, psiAllSWN[q]))
return psiAllSWN
def circularPhase(gVal):
psiAllSEN=evolutionSEN(gVal)
psiLastSEN=psiAllSEN[-1]
# print([np.abs(psiLastSEN[0]),np.abs(psiLastSEN[1])])
psiAllSWN=evolutionSWN(gVal)
psiLastSWN=psiAllSWN[-1]
# print([np.abs(psiLastSWN[0]),np.abs(psiLastSWN[1])])
prod=np.vdot(psiLastSWN,psiLastSEN)
AB=np.angle(prod)
# print("AB/pi="+str(AB/np.pi))
thetaDSENVal=np.real(thetaDSEN(gVal,psiAllSEN))
thetaDSWNVal=np.real(thetaDSWN(gVal,psiAllSWN))
# print("thetaD SEN="+str(thetaDSENVal))
# print("thetaD SWN="+str(thetaDSWNVal))
diffthetaD=thetaDSENVal-thetaDSWNVal
# thetaBSENVal=thetaB(psiAllSEN)
# thetaBSWNVal=thetaB(psiAllSWN)
#
# diffThetaB=thetaBSENVal-thetaBSWNVal
return [diffthetaD,AB]
# #one value
# tStart=datetime.now()
# gVal=1.2*B
# td,AB=circularPhase(gVal)
#
# tEnd=datetime.now()
# print("one round time: ",tEnd-tStart)
#
# print((td/np.pi))
# print((td/np.pi)-4*B/gVal)
# multiprocessing
def wrapper(gVal):
return [gVal,circularPhase(gVal)]
gValsAll=np.linspace(-10*B,10*B,100)
procNum=24
pool0=Pool(procNum)
tBatchStart=datetime.now()
ret=pool0.map(wrapper,gValsAll)
tBatchEnd=datetime.now()
print("batch time: ",tBatchEnd-tBatchStart)
outDir="./p"+str(p)+"/"
Path(outDir).mkdir(parents=True,exist_ok=True)
dValsAll=[]
ABValsAll=[]
for elem in ret:
td=elem[1][0]
AB=elem[1][1]
dValsAll.append(td)
ABValsAll.append(AB)
plt.figure()
plt.scatter(gValsAll,dValsAll,color="black")
plt.savefig(outDir+"p"+str(p)+"dynamicalPhase.png")
pdData=np.array([gValsAll,dValsAll,ABValsAll]).T
outData=pd.DataFrame(data=pdData,columns=["g","td","AB"])
outData.to_csv(outDir+"p"+str(p)+".csv",index=False)