-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobs.jl
More file actions
365 lines (321 loc) · 10.8 KB
/
obs.jl
File metadata and controls
365 lines (321 loc) · 10.8 KB
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
using ADerrors
using JLD2
using JSON
using LinearAlgebra
using SpecialFunctions
using Statistics
using TOML
wpm = Dict{String,Vector{Float64}}()
chosen = [-1, 1.5, -1, -1]
###########################
### PARSE THE TOML FILE ###
###########################
### FUNCTION inParse ###
# Parse TOML file and return its data as variables
#
# Inputs:
# - filename: path to the TOML file
#
# Outputs:
# - id: id of this run
# - fls: array of data files
# - uis: unique id for each file
# - bts: array of beta values
# - flw: used flow
# - xi: weight of the plaquette action density
# - rgB: boolean whether to perform or nor renormalization
# group improvement (set xi correctly when doing so)
# - En: names of action density observables
# - Ev: flow time values of action density observables
# - dEn: names of derivative action density observables
# - dEv: flow time values of derivative action density observables
### --- ###
function inParse(filename)
params = TOML.parsefile(filename)
# Global field
id = params["id"]
fls = params["files"]
uis = params["uids"]
# Simulation info
bts = params["Simulation"]["betas"]
flw = params["Simulation"]["flow"]
# Analysis peculiarities
xi = params["Analysis"]["xi"]
rgB = params["Analysis"]["rg"]
# Action density
En = params["Action_density"]["names"]
Ev = params["Action_density"]["values"]
# Derivative of action density
dEn = params["Derivative_action_density"]["names"]
dEv = params["Derivative_action_density"]["values"]
return id, fls, uis, bts, flw, xi, rgB, En, Ev, dEn, dEv
end
#############################################
### FUNCTIONS TO INTERACT WITH JLD2 FILES ###
#############################################
### FUNCTION derivate ###
# Central differences of y w.r.t. x
#
# Inputs:
# - y: y vector
# - x: x vector, same size as y
#
# Outputs:
# - dy: derivative vector
### --- ###
function derivate(y, x)
dy = Array{Float64}(undef, size(y)[1], size(y)[2]-2)
for i in 2:(length(x)-1)
dy[:,i-1] = (y[:,i+1] .- y[:,i-1]) ./ (x[i+1] - x[i-1])
end
return dy
end
### FUNCTION loadXsl ###
# Reads JLD2 file and extract action density related quantities
# (TODO: topological charge)
#
# Inputs:
# - file: path to JLD2 file
# - discretization: either Ysl (clover) or Wsl (plaquette)
#
# Outputs:
# - tfw: flow time vector trimmed in the extremes
# - ttX: adimensional action density trimmed in the extremes
# - tdttX: log derivative of the adimensional action density
### --- ###
function loadXsl(file, discretization)
data = jldopen(file, "r")
nmeas = parse(Int64, keys(data[discretization])[end])
sfq = parse(Int64, keys(data[discretization])[1])
nfw = size(data["tfw"])[1]
tfw = data["tfw"][:]
Xsl = Array{Float64}(undef, nmeas, nfw)
for (i,key) in enumerate(keys(data[discretization]))
Xsl[(i-1)*sfq+1:i*sfq, :] = mean(data[discretization][key][:,:,:,:], dims=3)[:,:,1,1]
end
close(data)
ttX = tfw'.^2 .* Xsl
tdttX = tfw[2:end-1]' .* derivate(ttX, tfw)
ttX = ttX[:,2:end-1]
tfw = tfw[2:end-1]
return tfw, ttX, tdttX
end
###########################################
### FUNCTIONS FOR RENORMALIZATION GROUP ###
###########################################
### FUNCTION r0aPoly ###
# Calculate r_0/a from \beta using functional
# polynomial form.
# (TODO: right now based on my Master's Thesis,
# the method is improvable and polynomials should coincide in \beta = 6)
#
# Inputs:
# - beta: value of beta (6/g_0^2)
#
# Outputs:
# - ur0a: uwreal object of r_0/a
### --- ###
function r0aPoly(beta)
global wpm["r0a.$beta"] = chosen
if (beta < 5.7) || (beta > 6.9)
exit()
elseif beta < 6
r0a = exp(1.6805 + 1.7139*(beta - 6) - 0.8155*(beta - 6)^2 + 0.6667*(beta - 6)^3)
dr0a = (0.003/0.87 * (beta - 5.7) + 0.003) * r0a
ur0a = uwreal([r0a, dr0a], "r0a.$beta")
uwerr(ur0a)
return ur0a
else
r0a = 9.5130 + 12.965*(beta - 6.38) + 6.982*(beta - 6.38)^2 + 4.16*(beta - 6.38)^3
dr0a = (0.01 * (beta - 6) + 0.001) * r0a
ur0a = uwreal([r0a, dr0a], "r0a.$beta")
uwerr(ur0a)
return ur0a
end
end
### FUNCTION alphaMS ###
# Calculate \alpha_{MS} from \beta using
# r_0\Lambda_{MS} from Ramos, Dalla Brida.
# Function adapted from R function of Gregorio Herdoiza
#
# Inputs:
# - beta: value of \beta
# - mulr0: scalar to multiply r_0/a (default = 1)
# - powa: order of perturbation theory: 0, 1, 2, 3 (default = 3)
# - Nf: number of flavours (default = 0)
### --- ###
function alphaMS(beta, mulr0=1, powa=3, Nf=0)
r0 = r0aPoly(beta) * mulr0
lambdaMS = uwreal([0.660, 0.011], "refLamMS")
logmuLam = log(r0^2/lambdaMS^2)
llogmuLam = log(logmuLam)
zeta3 = zeta(3)
beta0 = (33.0 - 2.0*Nf)/(12.0*pi)
beta1 = (153.0 - 19.0*Nf)/(24.0*pi^2)
beta2 = (77139.0 - 15099.0*Nf + 325.0*Nf^2)/(3456.0*pi^3)
beta3 = (149753.0/6.0 + 3564.0*zeta3 - (1078361.0/162.0 + 6508.0/27.0*zeta3)*Nf + (50065.0/162.0 + 6472.0/81.0*zeta3)*Nf^2 + 1093.0/729.0*Nf^3)/(4.0*pi)^4
aN0LO = 1.0/(beta0*logmuLam)
aN1LO = -beta1*llogmuLam/(beta0^3*logmuLam^2)
aN2LO = 1.0/(beta0^3*logmuLam^3)*(beta1^2/beta0^2*(llogmuLam^2 - llogmuLam - 1.0) + beta2/beta0)
aN3LO = 1.0/(beta0^4*logmuLam^4)*(beta1^3/beta0^3*(-llogmuLam^3 + 5.0/2.0*llogmuLam^2 + 2.0*llogmuLam -1.0/2.0) - 3.0*beta1*beta2/beta0^2*llogmuLam + beta3/(2.0*beta0))
alphaMS = aN0LO*(powa >= 0) + aN1LO*(powa >= 1) + aN2LO*(powa >= 2) + aN3LO*(powa >= 3)
return alphaMS
end
### FUNCTION dxi ###
# Modification to \xi for RG (assuming well selected xi)
#
# Inputs:
# - beta: value of \beta
# - t: flow time
#
# Outputs:
# - \Delta \xi
### --- ###
function dxi(beta, t)
return 27/56 * ((alphaMS(beta)/alphaMS(beta, 1/sqrt(8*t)))^(7/11) - 1.0)
end
###############################################
### GET THE VALUES NEEDED FOR EXTRAPOLATION ###
###############################################
### FUNCTION fileIteration ###
# Get the needed values for extrapolation for one data file
#
# Inputs:
# - fl: file path
# - bt: \beta value
# - xi: weight of plaquette
# - rgB: boolen whether to perform RG or not
# - En: names of action density observables
# - Ev: flow time values of action density observables
# - dEn: names of derivative action density observables
# - dEv: flow time values of derivative action density observables
#
# Outputs:
# - rt: flow time values before and after extrapolation point of AD
# - drt: flow time values before and after extrapolation point of dAD
# - rE: AD values before and after extrapolation point of AD
# - drE: dAD values before and after extrapolation point of dAD
### --- ###
function fileIteration(fl, bt, xi, rgB, En, Ev, dEn, dEv)
nE, ndE = length(Ev), length(dEv)
# Load the JLD2 files
t, Y, dY = loadXsl(fl, "Ysl")
t, W, dW = loadXsl(fl, "Wsl")
nMs, nFw = size(Y)
# Preallocate arrays
rt = Array{Float64}(undef, 2*nE)
drt = Array{Float64}(undef, 2*ndE)
rE = Array{uwreal}(undef, 2*nE)
drE = Array{uwreal}(undef, 2*ndE)
# Fast iteration for the flow times
Et0, dEt0, Ec, dEc = 0.0, 0.0, 1, 1
for i in 1:nFw
tX = xi + rgB * dxi(bt, t[i]) # Adjusted xi for RG
otX = 1.0 - tX
Et1 = tX*mean(W[:,i]) + otX*mean(Y[:,i])
dEt1 = tX*mean(dW[:,i]) + otX*mean(dY[:,i])
if Ec != nE + 1
if (Et0 < Ev[Ec]) && (Et1 > Ev[Ec])
rE[2*Ec] = tX*uwreal(W[:,i], "pl.$fl") + otX*uwreal(Y[:,i], "cl.$fl")
rE[2*Ec-1] = tX*uwreal(W[:,i-1], "pl.$fl") + otX*uwreal(Y[:,i-1], "cl.$fl")
rt[2*Ec] = t[i]
rt[2*Ec-1] = t[i-1]
Ec += 1
end
end
if dEc != ndE + 1
if (dEt0 < dEv[dEc]) && (dEt1 > dEv[dEc])
drE[2*dEc] = tX*uwreal(dW[:,i], "pl.$fl") + otX*uwreal(dY[:,i], "cl.$fl")
drE[2*dEc-1] = tX*uwreal(dW[:,i-1], "pl.$fl") + otX*uwreal(dY[:,i-1], "cl.$fl")
drt[2*dEc] = t[i]
drt[2*dEc-1] = t[i-1]
dEc += 1
end
end
Et0, dEt0 = Et1, dEt1
end
return rt, drt, rE, drE
end
#########################################
### FUNCTIONS TO BUILD THE DICTIONARY ###
#########################################
### FUNCTION getObs! ###
# Extrapolate and save into dict
#
# Inputs:
# - dict: "Observable" dict to modify.
# - x: float array with the just before
# and after values of the x axis.
# - y: uwreal array with the just before
# and after values of the y axis.
# - refVal: reference value.
# - name: name of the observable
### --- ###
function getObs!(dict, x, y, refVal, name)
r1, r2 = findall(y .< refVal)[end], findall(y .> refVal)[1]
obs = x[r1] + (refVal - y[r1]) * (y[r2] - y[r1])/(x[r2] - x[r1])
uwerr(obs, wpm)
dict[name] = Dict("ADerrors" => obs,
"Value" => value(obs),
"Uncertainty" => err(obs),
"Correlations" => Dict())
end
### FUNCTION corrDicr! ###
# Add the correlations with the rest
# of the observables.
#
# Inputs:
# - dict: "Observable" dict to modify
### --- ###
function corrDict!(dict)
for n1 in keys(dict)
for n2 in keys(dict)
if n1 == n2
continue
end
tempMat = ADerrors.cov([dict[n1]["ADerr"], dict[n2]["ADerr"]], wpm)
dict[n1]["Correlations"][n2] = tempMat[1,2]/sqrt(tempMat[1,1]*tempMat[2,2])
end
end
end
############
### MAIN ###
############
function main()
# Parse command line and input file
inFile = ARGS[1] # to be changed
outFile = ARGS[2]
id, fls, uis, bts, flw, xi, rgB, En, Ev, dEn, dEv = inParse(inFile)
# Create Dict
dictObs = Dict(id => [])
# Iterate over data files
for (i, (fl, bt, ui)) in enumerate(zip(fls, bts, uis))
append!(dictObs[id], [Dict("UID" => ui, "Beta" => bt, "Flow" => flw, "Observables" => Dict())])
rt, drt, rE, drE = fileIteration(fl, bt, xi, rgB, En, Ev, dEn, dEv)
for (name, refVal) in zip(En, Ev)
getObs!(dictObs[id][end]["Observables"], rt, rE, refVal, name)
end
for (name, refVal) in zip(dEn, dEv)
getObs!(dictObs[id][end]["Observables"], drt, drE, refVal, name)
end
corrDict!(dictObs[id][end]["Observables"])
end
# Create a dict copy without uwreals
cdict = copy(dictObs)
for i in eachindex(fls)
for name in keys(cdict[id][i]["Observables"])
delete!(cdict[id][i]["Observables"][name], "ADerrors")
end
end
# JSON save
dictJSON = isfile(outFile*".json") ? merge(JSON.parsefile(outFile*".json"), cdict) : cdict
open(outFile*".json", "w") do io
JSON.print(io, dictJSON)
end
# JLD2 save
jldopen(outFile*".jld2", "a+") do file
file[id] = dictObs[id]
end
end
end
main()