forked from jcosborn/qhmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaugeact.lua
269 lines (237 loc) · 5.41 KB
/
gaugeact.lua
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
require 'topo'
function clock()
--return os.clock()
--return os.time()
return qopqdp.dtime()
end
function globalRand()
local r = qopqdp.random()
return r
end
local oldprintf = printf
function printf(...)
if(qopqdp.master()) then
oldprintf(...)
end
end
function exit(n)
os.exit(n)
end
local actmt = {}
actmt.__index = actmt
local gaugemt = {}
gaugemt.__index = gaugemt
local forcemt = {}
forcemt.__index = forcemt
-- gauge action
local gaugecoeffs={}
function gaugecoeffs.plaquette(p)
return { plaq=1, rect=0, pgm=0, adjplaq=0 }
end
function gaugecoeffs.plaquette_adjoint(p)
return { plaq=1, rect=0, pgm=0, adjplaq=p.adjFac }
end
function gaugecoeffs.symanzik_tree(p)
local u0 = p.u0 or 1
local u2 = u0*u0
local c = { plaq=1, pgm=0, adjplaq=0 }
c.rect = -1/(20*u2)
return c
end
function gaugecoeffs.iwasaki(p)
local u0 = p.u0 or 1
local u2 = u0*u0
local c1 = -0.331
local c = { pgm=0, adjplaq=0 }
c.plaq = 1 - 8*c1
c.rect = c1/u2
return c
end
function gaugecoeffs.dbw2(p)
local u0 = p.u0 or 1
local u2 = u0*u0
local c1 = -1.4067
local c = { pgm=0, adjplaq=0 }
c.plaq = 1 - 8*c1
c.rect = c1/u2
return c
end
function gaugecoeffs.symanzik_1loop(p)
local u0 = p.u0 or 1
local u2 = u0*u0
local lu0 = math.log(u0)
local c = { plaq=1, adjplaq=0 }
c.rect = -(1 -0.6264*lu0 ) / (20*u2)
c.pgm = 0.04335*lu0 / u2
return c
end
function gaugecoeffs.symanzik_1loop_nf(p)
local u0 = p.u0 or 1
local nf = p.nf or 0
local u2 = u0*u0
local lu0 = math.log(u0)
local c = { plaq=1, adjplaq=0 }
c.rect = -(1 - (0.6264-0.4742*nf)*lu0 ) / (20*u2)
c.pgm = (0.0433-0.012*nf)*lu0 / u2
return c
end
function gaugecoeffs.symanzik_1loop_hisq(p)
local u0 = p.u0 or 1
local nf = p.nf or 0
local u2 = u0*u0
local lu0 = math.log(u0)
local c = { plaq=1, adjplaq=0 }
c.rect = -(1 - (0.6264-1.1746*nf)*lu0 ) / (20*u2)
c.pgm = (0.0433-0.0156*nf)*lu0 / u2
return c
end
function gaugeact(p)
local a = {}
a.latsize = p.latsize
a.vol = p.vol
a.beta = p.beta
a.xi0 = p.xi0 or 1
a.params = p.gaugeact or { type="plaquette" }
local gcfunc = gaugecoeffs[a.params.type]
if not gcfunc then
printf("unknown gauge action type %s\n", a.params.type)
exit(1)
end
a.coeffs = gcfunc(a.params)
qopqdp.lattice(a.latsize)
qopqdp.profile(profile or 0)
qopqdp.verbosity(qopVerbose or 0)
qopqdp.seed(p.seed)
--printf("gauge coeffs: ")
--for k,v in pairs(a.coeffs) do printf(" %-5s = % g\n", k, v) end
myprint("gauge coeffs: ", a.coeffs, "\n")
a.act0 = a.vol*(6*a.coeffs.plaq + 12*a.coeffs.rect + 16*a.coeffs.pgm + 6*a.coeffs.adjplaq)
a.act0 = a.act0*(1+a.xi0*a.xi0)/(2*a.xi0)
a.gf = actmt.forceNew(a)
a.g2 = actmt.gaugeNew(a)
actmt.clearStats(a)
return setmetatable(a, actmt)
end
function actmt.clearStats(a)
a.GFtime = 0
a.GFflops = 0
a.GFn = 0
a.GFnorm2 = 0
a.GFmax = 0
a.GUtime = 0
a.GUn = 0
end
function actmt.updateStats(a)
a.GFmflops = 1e-6 * a.GFflops / a.GFtime
a.GFrms = math.sqrt(a.GFnorm2/(4*a.GFn*a.vol))
end
function actmt.gaugeNew(a)
local g = {}
g.a = a
g.g = qopqdp.gauge()
g.nupdate = 0
return setmetatable(g, gaugemt)
end
function actmt.forceNew(a)
local f = {}
f.a = a
f.f = qopqdp.force()
return setmetatable(f, forcemt)
end
function actmt.action(a, g)
local ss,st,sm = g.g:action(a.coeffs, a.xi0)
return a.beta*(a.act0-ss-st) + sm
end
function actmt.force(a, f, g)
local t0 = clock()
g.g:force(f.f, a.coeffs, a.beta, a.xi0)
a.GFtime = a.GFtime + clock() - t0
--a.GFtime = a.GFtime + f.f:time()
a.GFflops = a.GFflops + f.f:flops()
a.GFn = a.GFn + 1
end
function actmt.updateMomentum(a, f, g, eps, fgeps)
local gf = a.gf
a:force(gf, g)
fgeps = fgeps or 0
if fgeps ~= 0 then
local g2 = a.g2
g2.g:set(g.g)
g2.g:update(gf.f, fgeps)
a:force(gf, g2)
end
local s = eps
f.f:fupdate(gf.f, s)
local gf2 = s*s*gf.f:norm2()
local gfi = s*gf.f:infnorm()
if a.printforce then
printf("gauge force: norm %g inf %g\n", gf2, gfi)
end
a.GFnorm2 = a.GFnorm2 + gf2
if a.GFmax < gfi then a.GFmax = gfi end
end
-- gauge methods
function gaugemt.nupdates(g)
return g.nupdate
end
function gaugemt.unit(g)
g.g:unit()
g.nupdate = g.nupdate + 1
end
function gaugemt.warm(g, w)
weakfield(g.g, w)
g.nupdate = g.nupdate + 1
end
function gaugemt.set(g, g2)
g.g:set(g2.g)
g.nupdate = g.nupdate + 1
end
function gaugemt.load(g, fn)
g.g:load(fn)
g.nupdate = g.nupdate + 1
end
function gaugemt.save(g, fn, md, ...)
md = md or "<?xml version=\"1.0\"?>\n<note>generated by qhmc</note>\n"
g.g:save(fn, md, md, ...)
end
function gaugemt.checkSU(g)
return g.g:checkSU()
end
function gaugemt.makeSU(g)
g.g:makeSU()
g.nupdate = g.nupdate + 1
end
function gaugemt.plaq(g)
local ss,st = g.g:action({plaq=1})
local nd = #qopqdp.lattice()
local s = 0.25*nd*(nd-1)*g.a.vol
return ss/s, st/s
end
function gaugemt.ploop(g)
local nd = #qopqdp.lattice()
local pl = {}
for i=1,nd do
--local plpath = rep(-i,g.a.latsize[i]) -- changed convention
local plpath = rep(i,g.a.latsize[i])
pl[i] = g.g:loop(plpath)
end
return pl
end
function gaugemt.update(g, f, eps)
local t0 = clock()
g.g:update(f.f, eps)
g.a.GUtime = g.a.GUtime + clock() - t0
g.a.GUn = g.a.GUn + 1
g.nupdate = g.nupdate + 1
end
-- force methods
function forcemt.random(f, var)
--f.f:random()
f.f:randomTAH()
if var then
f.f:scale(var)
end
end
function forcemt.norm2(f)
return f.f:norm2()
end