Skip to content

Commit

Permalink
Add cooling and ability to use multiple flow integrators
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaFuwa committed Dec 10, 2024
1 parent 33de254 commit b05feba
Show file tree
Hide file tree
Showing 25 changed files with 267 additions and 230 deletions.
2 changes: 1 addition & 1 deletion MetaAnalysis/src/measurements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct MetaMeasurements
"""
ensemblename
else
path = joinpath(splitpath(@__DIR__())[1:end-2]...) * "/ensembles/$(ensemblename)/measurements/"
path = joinpath(splitpath(@__DIR__())[1:end-2]...) * "/ensembles/$(ensemblename)/"
@assert isdir(path) """
Ensemble \"$(ensemblename)\" could not be found or doesn't exist.
"""
Expand Down
2 changes: 1 addition & 1 deletion src/bias/Bias.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Bias(p::ParameterSet, U; mpi_multi_sim=false, instance=mpi_myrank(), du
else
instance
end
@level1("- Setting Bias instance $(inum)...")
@level1("- Constructing Bias instance $(inum)...")
kind_of_bias = Unicode.normalize(p.kind_of_bias; casefold=true)
TCV = get_cvtype_from_parameters(p)
smearing = StoutSmearing(U; numlayers=p.numsmears_for_cv, rho=p.rhostout_for_cv)
Expand Down
2 changes: 1 addition & 1 deletion src/main/Main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ..Fields: calc_gauge_action, is_distributed, normalize!
import ..Measurements: MYEXT_str
import ..Measurements: MeasurementMethods, calc_measurements, calc_measurements_flowed
import ..Parameters: ParameterSet, construct_params_from_toml
import ..Smearing: GradientFlow
import ..Smearing: construct_flow
import ..Universe: Univ
import ..Updates: HMC, ParityUpdate, Updatemethod, update!, temper!, integrator_from_str
import ..Updates: set_instanton!
Expand Down
4 changes: 2 additions & 2 deletions src/main/Universe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct Univ{TG,TF,TB}
function Univ(
U::Gaugefield{BACKEND,T,M,A,GA}, fermion_action::TF, bias::TB, numinstances
) where {BACKEND,T,M,A,GA,TF,TB}
@level1("- Setting Universe...")
@level1("- Constructing Universe...")
@level1("| NUM INSTANCES: $(numinstances)")
@level1("| BACKEND: $(string(BACKEND))")
@level1("| FP PREC: $(string(T))")
Expand All @@ -53,7 +53,7 @@ struct Univ{TG,TF,TB}
function Univ(
U::Vector{TG}, fermion_action::TF, bias::Vector{TB}, numinstances
) where {B,T,M,A,GA,TG<:Gaugefield{B,T,M,A,GA},TF,TB}
@level1("- Setting Universe...")
@level1("- Constructing Universe...")
@level1("| NUM INSTANCES: $(numinstances)")
@level1("| BACKEND: $(string(B))")
@level1("| FP PREC: $(string(T))")
Expand Down
9 changes: 1 addition & 8 deletions src/main/runbuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ function build_bias!(univ, parameters, updatemethod; mpi_multi_sim=false)
updatemethod = Updatemethod(parameters, U)
end

gflow = GradientFlow(
U;
integrator=parameters.flow_integrator,
numflow=parameters.flow_num,
steps=parameters.flow_steps,
tf=parameters.flow_tf,
measure_every=parameters.flow_measure_every,
)
gflow = construct_flow(U, parameters)

additional_string = "_$(lpad(mpi_myrank(), 3, "0")).txt"

Expand Down
98 changes: 47 additions & 51 deletions src/main/runsim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,74 +138,68 @@ function run_sim!(univ, parameters, updatemethod, updatemethod_pt; mpi_multi_sim
parity = parameters.parity_update ? ParityUpdate(U) : nothing
end

if parameters.tempering_enabled && !mpi_multi_sim
gflow = GradientFlow(
U[1];
integrator=parameters.flow_integrator,
numflow=parameters.flow_num,
steps=parameters.flow_steps,
tf=parameters.flow_tf,
measure_every=parameters.flow_measure_every,
)
measurements = Vector{MeasurementMethods}(undef, parameters.numinstances)
measurements_with_flow = Vector{MeasurementMethods}(undef, parameters.numinstances)
numinstances = parameters.numinstances

if parameters.tempering_enabled && !mpi_multi_sim
gflow = construct_flow(U[1], parameters)
measurements = Vector{MeasurementMethods}(undef, numinstances)
measurements[1] = MeasurementMethods(
U[1], parameters.measure_dir, parameters.measurements;
additional_string="_000.txt",
)

measurements_with_flow[1] = MeasurementMethods(
U[1],
parameters.measure_dir,
parameters.measurements_with_flow;
flow=true,
additional_string="_000.txt",
)
for i in 2:(parameters.numinstances)
for i in 2:numinstances
if parameters.measure_on_all
measurements[i] = MeasurementMethods(
U[i],
parameters.measure_dir,
parameters.measurements;
additional_string = "_$(lpad(i-1, 3, "0")).txt"
)
measurements_with_flow[i] = MeasurementMethods(
U[i],
parameters.measure_dir,
parameters.measurements_with_flow;
flow=true,
additional_string = "_$(lpad(i-1, 3, "0")).txt"
)
else
measurements[i] = MeasurementMethods(
U[i], parameters.measure_dir, Dict[];
additional_string="_$(lpad(i-1, 3, "0")).txt"
)
measurements_with_flow[i] = MeasurementMethods(
U[i], parameters.measure_dir, Dict[];
additional_string="_$(lpad(i-1, 3, "0")).txt"
)
measurements[i] = MeasurementMethods(U[i], parameters.measure_dir, Dict[])
end
end
else
gflow = GradientFlow(
U;
integrator=parameters.flow_integrator,
numflow=parameters.flow_num,
steps=parameters.flow_steps,
tf=parameters.flow_tf,
measure_every=parameters.flow_measure_every,
)

measurements_with_flow = ntuple(length(gflow)) do i
_measurements_with_flow = Vector{MeasurementMethods}(undef, numinstances)
_measurements_with_flow[1] = MeasurementMethods(
U[1],
parameters.measure_dir,
parameters.measurements_with_flow;
flow=gflow[i],
additional_string="_000.txt",
)

for j in 2:numinstances
if parameters.measure_on_all
_measurements_with_flow[j] = MeasurementMethods(
U[j],
parameters.measure_dir,
parameters.measurements_with_flow;
flow=gflow[i],
additional_string = "_$(lpad(j-1, 3, "0")).txt"
)
else
measure_dir = parameters.measure_dir
_measurements_with_flow[i] = MeasurementMethods(U[i], measure_dir, Dict[])
end
end

_measurements_with_flow
end
else
gflow = construct_flow(U, parameters)
measurements = MeasurementMethods(
U, parameters.measure_dir, parameters.measurements;
additional_string="_$(lpad(mpi_myrank(), 3, "0")).txt"
)
measurements_with_flow = MeasurementMethods(
U, parameters.measure_dir, parameters.measurements_with_flow;
flow=true, additional_string="_$(lpad(mpi_myrank(), 3, "0")).txt"
)
measurements_with_flow = ntuple(length(gflow)) do i
MeasurementMethods(
U, parameters.measure_dir, parameters.measurements_with_flow;
flow=gflow[i], additional_string="_$(lpad(mpi_myrank(), 3, "0")).txt"
)
end
end

# initialize functor responsible for saving gaugefield configurations
Expand Down Expand Up @@ -345,10 +339,12 @@ function metaqcd!(
_, mtime = @timed calc_measurements(
measurements, U, itrj, myinstance[]; mpi_multi_sim=mpi_multi_sim
)
_, fmtime = @timed calc_measurements_flowed(
measurements_with_flow, gflow, U, itrj, myinstance[];
mpi_multi_sim=mpi_multi_sim
)
_, fmtime = @timed for i in eachindex(gflow)
calc_measurements_flowed(
measurements_with_flow[i], gflow[i], U, itrj, myinstance[];
mpi_multi_sim=mpi_multi_sim
)
end
calc_weights(bias, U.CV, itrj, myinstance[]; mpi_multi_sim=mpi_multi_sim)
@level1("| Meas. elapsed time: $(mtime) [s]")
@level1("| FlowMeas. elapsed time: $(fmtime) [s]\n-")
Expand Down
3 changes: 2 additions & 1 deletion src/measurements/Measurements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import ..Fields: Gaugefield, Spinorfield, calc_gauge_action, check_dims, clover_
import ..Fields: clover_square, global_dims, local_dims, float_type, plaquette, wilsonloop
import ..Fields: @groupreduce, @latsum, Plaquette, Clover, Improved, CPU, ones!, set_source!
import ..Fields: distributed_reduce, is_distributed, plaquette_trace_sum, wilsonloop
import ..Smearing: StoutSmearing, calc_smearedU!, flow!
import ..Smearing: AbstractSmearing, Cooling, GradientFlow, NoSmearing, StoutSmearing
import ..Smearing: calc_smearedU!, flow!

abstract type AbstractMeasurement end

Expand Down
7 changes: 4 additions & 3 deletions src/measurements/measure_energy_density.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct EnergyDensityMeasurement{T} <: AbstractMeasurement
ED_dict::Dict{String,Float64} # energy density definition => value
filename::T
function EnergyDensityMeasurement(
U::Gaugefield; filename="", ED_methods=["clover"], flow=false
U::Gaugefield; filename="", ED_methods=["clover"], flow=NoSmearing()
)
ED_dict = Dict{String,Float64}()

Expand All @@ -28,7 +28,7 @@ struct EnergyDensityMeasurement{T} <: AbstractMeasurement
rpath = StaticString(filename)
header = ""

if flow
if flow == true || flow != NoSmearing()
header *= @sprintf("%-11s%-7s%-9s", "itrj", "iflow", "tflow")
else
header *= @sprintf("%-11s", "itrj")
Expand Down Expand Up @@ -68,6 +68,7 @@ function measure(
itrj=0,
flow=nothing;
mpi_multi_sim=false,
fstr="",
) where {T}
ED_dict = m.ED_dict
iflow, τ = isnothing(flow) ? (0, 0.0) : flow
Expand All @@ -81,7 +82,7 @@ function measure(
E = ED_dict[method]

if !isnothing(flow)
@level1("$itrj\t$E # energydensity_$(method)_flow_$(iflow)")
@level1("$itrj\t$E # energydensity_$(method)$(fstr)_$(iflow)")
else
@level1("$itrj\t$E # energydensity_$(method)")
end
Expand Down
9 changes: 6 additions & 3 deletions src/measurements/measure_gauge_action.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ struct GaugeActionMeasurement{T} <: AbstractMeasurement
GA_dict::Dict{String,Float64} # gauge action definition => value
factor::Float64 # 1 / (6*U.NV*U.β)
filename::T
function GaugeActionMeasurement(U; filename="", GA_methods=["wilson"], flow=false)
function GaugeActionMeasurement(
U; filename="", GA_methods=["wilson"], flow=NoSmearing()
)
GA_dict = Dict{String,Float64}()

for method in GA_methods
Expand All @@ -14,7 +16,7 @@ struct GaugeActionMeasurement{T} <: AbstractMeasurement
rpath = StaticString(filename)
header = ""

if flow
if flow == true || flow == NoSmearing()
header *= @sprintf("%-11s%-7s%-9s", "itrj", "iflow", "tflow")
else
header *= @sprintf("%-11s", "itrj")
Expand Down Expand Up @@ -55,6 +57,7 @@ function measure(
itrj=0,
flow=nothing;
mpi_multi_sim=false,
fstr="",
) where {T}
GA_dict = m.GA_dict
iflow, τ = isnothing(flow) ? (0, 0.0) : flow
Expand All @@ -68,7 +71,7 @@ function measure(
S = GA_dict[method]

if !isnothing(flow)
@level1("$itrj\t$S # gaction_$(method)_flow_$(iflow)")
@level1("$itrj\t$S # gaction_$(method)$(fstr)_$(iflow)")
else
@level1("$itrj\t$S # gaction_$(method)")
end
Expand Down
5 changes: 3 additions & 2 deletions src/measurements/measure_pion_correlator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct PionCorrelatorMeasurement{T,TD,TF,CT} <: AbstractMeasurement
filename="",
dirac_type="wilson",
eo_precon=false,
flow=false,
flow=NoSmearing(),
mass=0.1,
csw=0,
r=1,
Expand Down Expand Up @@ -58,7 +58,7 @@ struct PionCorrelatorMeasurement{T,TD,TF,CT} <: AbstractMeasurement
rpath = StaticString(filename)
header = ""

if flow
if flow == true || flow == NoSmearing()
header *= @sprintf("%-11s%-7s%-9s", "itrj", "iflow", "tflow")
else
header *= @sprintf("%-11s", "itrj")
Expand Down Expand Up @@ -111,6 +111,7 @@ function measure(
itrj=0,
flow=nothing;
mpi_multi_sim=false,
kwargs...,
) where {T}
pion_correlators_avg!(
m.pion_corr, m.dirac_operator(U), m.temp, m.cg_temps, m.cg_tol, m.cg_maxiters
Expand Down
7 changes: 4 additions & 3 deletions src/measurements/measure_plaquette.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
struct PlaquetteMeasurement{T} <: AbstractMeasurement
factor::Float64 # 1 / (6*U.NV*U.NC)
filename::T
function PlaquetteMeasurement(U::Gaugefield; filename="", flow=false)
function PlaquetteMeasurement(U::Gaugefield; filename="", flow=NoSmearing())
if !isnothing(filename) && filename != ""
rpath = StaticString(filename)
header = ""

if flow
if flow == true || flow == NoSmearing()
header *= @sprintf(
"%-11s%-7s%-9s%-25s", "itrj", "iflow", "tflow", "Re(plaq)"
)
Expand Down Expand Up @@ -40,13 +40,14 @@ function measure(
itrj=0,
flow=nothing;
mpi_multi_sim=false,
fstr="",
) where {T}
plaq = plaquette_trace_sum(U) * m.factor
iflow, τ = isnothing(flow) ? (0, 0.0) : flow

if !is_distributed(U) || mpi_amroot()
if !isnothing(flow)
@level1("$itrj\t$plaq # plaq_flow_$(τ)")
@level1("$itrj\t$plaq # plaq$(fstr)_$(τ)")
else
@level1("$itrj\t$plaq # plaq")
end
Expand Down
7 changes: 4 additions & 3 deletions src/measurements/measure_polyakov.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct PolyakovMeasurement{T} <: AbstractMeasurement
filename::T
function PolyakovMeasurement(U::Gaugefield; filename="", flow=false)
function PolyakovMeasurement(U::Gaugefield; filename="", flow=NoSmearing())
if is_distributed(U)
@assert U.topology.numprocs_cart[4] == 1 "Field cannot be decomposed in time direction for polykov loop calculation"
end
Expand All @@ -9,7 +9,7 @@ struct PolyakovMeasurement{T} <: AbstractMeasurement
rpath = StaticString(filename)
header = ""

if flow
if flow == true || flow == NoSmearing()
header *= @sprintf(
"%-11s%-7s%-9s%-25s%-25s",
"itrj",
Expand Down Expand Up @@ -47,13 +47,14 @@ function measure(
itrj=0,
flow=nothing;
mpi_multi_sim=false,
fstr="",
) where {T}
poly = polyakov_traced(U)
iflow, τ = isnothing(flow) ? (0, 0.0) : flow

if !is_distributed(U) || mpi_amroot()
if !isnothing(flow)
@level1("$itrj\t$(real(poly)) + $(imag(poly))im # poly_flow_$(τ)")
@level1("$itrj\t$(real(poly)) + $(imag(poly))im # poly$(fstr)_$(τ)")
else
@level1("$itrj\t$(real(poly)) + $(imag(poly))im # poly")
end
Expand Down
Loading

0 comments on commit b05feba

Please sign in to comment.