/
optimized_latt_ft.py
195 lines (158 loc) · 7.06 KB
/
optimized_latt_ft.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
from multiprocessing import Pool
from copy import deepcopy
import numpy
import numpy.fft
from functools import partial
import math, time, cmath
from math import cos, exp, sin, log, log10, pi, sqrt
from pytriqs.operators import *
from pytriqs.archive import *
from pytriqs.gf.local import *
from pytriqs.arrays import BlockMatrix, BlockMatrixComplex
import pytriqs.utility.mpi as mpi
from data_types import IBZ
##################### inverse temporal ########################
def invf(Qw, beta, ntau, n_iw, statistic, fit_tail):
g = GfImFreq(indices = [0], beta = beta, n_points = n_iw, statistic=statistic)
gtau = GfImTime(indices = [0], beta = beta, n_points = ntau, statistic=statistic)
g.data[:,0,0] = Qw[:]
if fit_tail:
assert statistic == 'Fermion', "no tail fiting for bosonic functions!"
fit_fermionic_gf_tail(g) ############# !!!!!!!!!! add the bosonic option
gtau << InverseFourier(g)
return gtau.data[:,0,0]
def invf_(tup):
return invf(*tup)
def temporal_inverse_FT_single_core(Qkw, beta, ntau, n_iw, nk, statistic='Fermion', use_IBZ_symmetry = True, fit_tail = False):
if mpi.is_master_node(): print "temporal_inverse_FT_single core"
Qktau = numpy.zeros((ntau,nk,nk), dtype=numpy.complex_)
if use_IBZ_symmetry: max_kxi = nk/2+1
else: max_kxi = nk
for kxi in range(max_kxi):
if use_IBZ_symmetry: max_kyi = nk/2+1
else: max_kyi = nk
numpy.transpose(Qktau[:,kxi,:])[0:max_kyi,:] = [ invf( Qkw[:,kxi,kyi], beta, ntau, n_iw, statistic, fit_tail )\
for kyi in range(max_kyi)]
if use_IBZ_symmetry:
for taui in range(ntau):
IBZ.copy_by_weak_symmetry(Qktau[taui,:,:], nk)
return Qktau
def temporal_inverse_FT(Qkw, beta, ntau, n_iw, nk, statistic='Fermion', use_IBZ_symmetry = True, fit_tail = False, N_cores=1):
if N_cores==1: return temporal_inverse_FT_single_core(Qkw, beta, ntau, n_iw, nk, statistic, use_IBZ_symmetry, fit_tail)
if mpi.is_master_node(): print "temporal_inverse_FT, N_cores: ",N_cores
Qktau = numpy.zeros((ntau,nk,nk), dtype=numpy.complex_)
if use_IBZ_symmetry: max_kxi = nk/2+1
else: max_kxi = nk
pool = Pool(processes=N_cores) # start worker processes
for kxi in range(max_kxi):
if use_IBZ_symmetry: max_kyi = nk/2+1
else: max_kyi = nk
numpy.transpose(Qktau[:,kxi,:])[0:max_kyi,:] = pool.map(invf_,
[( Qkw[:,kxi,kyi],
beta, ntau, n_iw, statistic, fit_tail
)\
for kyi in range(max_kyi)])
pool.close()
if use_IBZ_symmetry:
for taui in range(ntau):
IBZ.copy_by_weak_symmetry(Qktau[taui,:,:], nk)
return Qktau
##################### direct temporal ########################
def f(Qtau, beta, ntau, n_iw, statistic):
g = GfImFreq(indices = [0], beta = beta, n_points = n_iw, statistic=statistic)
gtau = GfImTime(indices = [0], beta = beta, n_points = ntau, statistic=statistic)
gtau.data[:,0,0] = Qtau[:]
g << Fourier(gtau)
return g.data[:,0,0]
def f_(tup):
return f(*tup)
def temporal_FT_single_core(Qktau, beta, ntau, n_iw, nk, statistic='Fermion', use_IBZ_symmetry = True):
if mpi.is_master_node(): print "temporal_FT_single core"
if statistic=='Fermion':
nw = 2*n_iw
elif statistic=='Boson':
nw = 2*n_iw-1
else:
if mpi.is_master_node():
print "statistic not implemented"
quit()
Qkw = numpy.zeros((nw,nk,nk), dtype=numpy.complex_)
if use_IBZ_symmetry: max_kxi = nk/2+1
else: max_kxi = nk
for kxi in range(max_kxi):
if use_IBZ_symmetry: max_kyi = nk/2+1
else: max_kyi = nk
numpy.transpose(Qkw[:,kxi,:])[0:max_kyi,:] = [f( deepcopy(Qktau[:,kxi,kyi]), beta, ntau, n_iw, statistic )\
for kyi in range(max_kyi)]
if use_IBZ_symmetry:
for wi in range(nw):
IBZ.copy_by_weak_symmetry(Qkw[wi,:,:], nk)
return Qkw
def temporal_FT(Qktau, beta, ntau, n_iw, nk, statistic='Fermion', use_IBZ_symmetry = True, N_cores=1):
if N_cores==1: return temporal_FT_single_core(Qktau, beta, ntau, n_iw, nk, statistic, use_IBZ_symmetry)
if mpi.is_master_node(): print "temporal_FT, N_cores: ",N_cores
if statistic=='Fermion':
nw = 2*n_iw
elif statistic=='Boson':
nw = 2*n_iw-1
else:
if mpi.is_master_node():
print "statistic not implemented"
quit()
Qkw = numpy.zeros((nw,nk,nk), dtype=numpy.complex_)
if use_IBZ_symmetry: max_kxi = nk/2+1
else: max_kxi = nk
pool = Pool(processes=N_cores) # start worker processes
for kxi in range(max_kxi):
if use_IBZ_symmetry: max_kyi = nk/2+1
else: max_kyi = nk
numpy.transpose(Qkw[:,kxi,:])[0:max_kyi,:] = pool.map(f_,
[( deepcopy(Qktau[:,kxi,kyi]),
beta, ntau, n_iw, statistic
)\
for kyi in range(max_kyi)])
pool.close()
if use_IBZ_symmetry:
for wi in range(nw):
IBZ.copy_by_weak_symmetry(Qkw[wi,:,:], nk)
return Qkw
###################### inverse spatial ########################
def spinvf(Q):
return numpy.fft.ifft2(Q)
def spatial_inverse_FT_single_core(Qk):
if mpi.is_master_node(): print "spatial_inverse_FT_single core"
n = len(Qk[:,0,0])
nk = len(Qk[0,:,0])
Qij = numpy.zeros((n,nk,nk), dtype=numpy.complex_)
Qij[:,:,:] = [ spinvf(Qk[l,:,:]) for l in range(n)]
return Qij
def spatial_inverse_FT(Qk, N_cores=1):
if N_cores == 1: return spatial_inverse_FT_single_core(Qk)
if mpi.is_master_node(): print "spatial_inverse_FT, N_cores: ",N_cores
n = len(Qk[:,0,0])
nk = len(Qk[0,:,0])
Qij = numpy.zeros((n,nk,nk), dtype=numpy.complex_)
pool = Pool(processes=N_cores) # start worker processes
Qij[:,:,:] = pool.map(spinvf, [ Qk[l,:,:] for l in range(n)])
pool.close()
return Qij
###################### inverse spatial ########################
def spf(Q):
return numpy.fft.fft2(Q)
def spatial_FT_single_core(Qij):
if mpi.is_master_node(): print "spatial_FT_single core"
n = len(Qij[:,0,0])
nk = len(Qij[0,:,0])
Qk = numpy.zeros((n,nk,nk), dtype=numpy.complex_)
Qk[:,:,:] = [ spf(Qij[l,:,:]) for l in range(n)]
return Qk
def spatial_FT(Qij, N_cores=1):
if N_cores == 1: return spatial_FT_single_core(Qij)
if mpi.is_master_node(): print "spatial_FT, N_cores: ",N_cores
n = len(Qij[:,0,0])
nk = len(Qij[0,:,0])
Qk = numpy.zeros((n,nk,nk), dtype=numpy.complex_)
pool = Pool(processes=N_cores) # start worker processes
Qk[:,:,:] = pool.map(spf, [ Qij[l,:,:] for l in range(n)])
pool.close()
return Qk