forked from jcosborn/qhmc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
puregauge.lua
151 lines (134 loc) · 3.51 KB
/
puregauge.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
require 'common'
require 'gaugeact'
require 'hmc'
nx = nx or 4
nt = nt or 8
beta = beta or 6
--seed = seed or 54321
seed = seed or os.time()
tau = tau or 1
nsteps = nsteps or 40
ntraj = ntraj or 1
first = first or -1
latsize = { nx, nx, nx, nt }
--latsize = { nx, nt }
vol = 1; for k,v in ipairs(latsize) do vol=vol*v end
p = {}
p.latsize = latsize
p.vol = vol
p.beta = beta
p.seed = seed
if gact then
--p.gaugeact = { type = gact }
p.gaugeact = gact
end
act = {}
act.g = gaugeact(p)
myprint("latsize = ", latsize, "\n")
printf("volume = %i\n", vol)
printf("seed = %i\n", seed)
printf("beta = %g\n", beta)
printf("tau = %g\n", tau)
printf("nsteps = %g\n", nsteps)
printf("ntraj = %g\n", ntraj)
basefn = string.format("l4x%i%ib%03.0f.", nx, nt, 100*beta)
last = ntraj * tau
if first >= 0 then
infn = basefn .. tostring(first)
U = loadGauge(infn)
last = last + first
else
G = act.g:gaugeNew()
G:unit()
end
outfn = basefn .. tostring(last)
local fields = {}
function fields.save(f)
f.GSave:set(f.G)
f.F:random()
end
function fields.action(f)
local Sgq = act.g:action(f.G)
local Sgp = 0.5 * f.F:norm2()
local S = Sgq + Sgp
printf("Sgq: %-8.6g Sgp: %-8.6g\n", Sgq, Sgp)
return S
end
function fields.accept(f)
local devavg,devmax = f.G:checkSU()
printf("unitarity deviation avg: %g max: %g\n", devavg, devmax)
f.G:makeSU()
devavg,devmax = f.G:checkSU()
printf("new unitarity deviation avg: %g max: %g\n", devavg, devmax)
end
function fields.reject(f)
f.G:set(f.GSave)
end
function fields.nfields(f)
return 1
end
function fields.nforces(f)
return { 1 }
end
function fields.updateField(f, i, eps)
--printf("F1: fnorm: %g\tact: %g\n", 0.5*f.F:norm2(), act.g:action(f.G))
f.G:update(f.F, eps)
--printf("F2: fnorm: %g\tact: %g\n", 0.5*f.F:norm2(), act.g:action(f.G))
end
function fields.updateMomentum(f, i, j, eps)
--printf("P1: fnorm: %g\tact: %g\n", 0.5*f.F:norm2(), act.g:action(f.G))
act.g:updateMomentum(f.F, f.G, eps[1])
--printf("P2: fnorm: %g\tact: %g\n", 0.5*f.F:norm2(), act.g:action(f.G))
end
--act.g.printforce = true
fields.G = G
fields.GSave = act.g:gaugeNew()
fields.F = act.g:forceNew()
local fp = {}
fp.nsteps = nsteps
fp.intalg = intalg or { type = "leapfrog" }
--fp.intalg = { type = "omelyan", lambda = 0.21 }
--hmcparams.traceS = true
--qcd.defaults{qdpProfcontrol=1}
hmcparams = {}
hmcparams.tau = tau
hmcparams.forceparams = {{ fp }}
function measure(G)
local t0 = clock()
local ps,pt = G:plaq()
printf("plaq ss: %g st: %g tot: %g\n", ps, pt, 0.5*(ps+pt))
local nd = #G.a.latsize
for i=1,nd do
for j=i+1,nd do
--local l = G.g:loop({i,j,-i,-j}) -- changed convention
local l = G.g:loop({-i,-j,i,j})
printf("plaq%i%i: %g\t%g\n", i, j, l.r, l.i)
end
end
--local plpath = rep(-nd, G.a.latsize[nd]) -- changed convention
local plpath = rep(nd, G.a.latsize[nd])
local plp = G.g:loop(plpath)
printf("ploop: %g\t%g\n", plp.r, plp.i)
t0 = clock() - t0
printf("meas time: %g\n", t0)
io.stdout:flush()
end
totaltime = clock()
measure(G)
for traj=1,ntraj do
t0 = clock()
hmcstep(fields, hmcparams)
--act.g:checkSU(fields.G)
t0 = clock() - t0
printf("traj %i secs: %g\n", traj, t0)
act.g:updateStats()
printf("GF secs: %8.3f mflops: %5.0f\n", act.g.GFtime, act.g.GFmflops)
printf("GU secs: %8.3f\n", act.g.GUtime)
ot = t0 - act.g.GFtime - act.g.GUtime
printf("?? secs: %8.3f\n", ot)
act.g:clearStats()
measure(fields.G)
end
--if outfn then saveGauge(G, outfn) end
totaltime = clock() - totaltime
printf("total time: %g seconds\n", totaltime)