Skip to content

Commit

Permalink
Fixes in metaqcd_PT!
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaFuwa committed Jul 9, 2024
1 parent 1260e7a commit bdbe74e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 23 deletions.
29 changes: 13 additions & 16 deletions src/main/Universe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ even if stated otherwise in the parameters.
"""
struct Univ{TG,TF,TB}
U::TG
fermion_actions::TF
fermion_action::TF
bias::TB
myinstance::Base.RefValue{Int64}
numinstances::Int64
function Univ(
U::Gaugefield{BACKEND,T,A,GA}, fermion_actions::TF, bias::TB, numinstances
U::Gaugefield{BACKEND,T,A,GA}, fermion_action::TF, bias::TB, numinstances
) where {BACKEND,T,A,GA,TF<:Tuple,TB}
@level1("┌ Setting Universe...")
@level1("| NUM INSTANCES: $(numinstances)")
Expand All @@ -43,16 +43,16 @@ struct Univ{TG,TF,TB}
@level1("| GAUGE ACTION: $(GA)")
@level1("| BETA: $(U.β)")
if TF === Tuple{}
@level1("| FERMION ACTIONS:\n\n")
@level1("| FERMION ACTION:\n\n")
else
@level1("| FERMION ACTIONS: $(fermion_actions...)\n")
@level1("| FERMION ACTION: $(fermion_action...)\n")
end
TG = typeof(U)
return new{TG,TF,TB}(U, fermion_actions, bias, Base.RefValue{MYRANK}, numinstances)
return new{TG,TF,TB}(U, fermion_action, bias, Base.RefValue{MYRANK}, numinstances)
end

function Univ(
U::Vector{Gaugefield{BACKEND,T,A,GA}}, fermion_actions::TF, bias::TB, numinstances
U::Vector{Gaugefield{BACKEND,T,A,GA}}, fermion_action::TF, bias::TB, numinstances
) where {BACKEND,T,A,GA,TF<:Tuple,TB}
@level1("┌ Setting Universe...")
@level1("| NUM INSTANCES: $(numinstances)")
Expand All @@ -62,12 +62,12 @@ struct Univ{TG,TF,TB}
@level1("| GAUGE ACTION: $(GA)")
@level1("| BETA: $(U[1].β)")
if TF === Tuple{}
@level1("| FERMION ACTIONS:\n\n")
@level1("| FERMION ACTION:\n\n")
else
@level1("| FERMION ACTIONS: $(fermion_actions...)\n")
@level1("| FERMION ACTION: $(fermion_action...)\n")
end
TG = typeof(U)
return new{TG,TF,TB}(U, fermion_actions, bias, Base.RefValue{MYRANK}, numinstances)
return new{TG,TF,TB}(U, fermion_action, bias, Base.RefValue{MYRANK}, numinstances)
end
end

Expand All @@ -76,36 +76,33 @@ function Univ(parameters::ParameterSet; use_mpi=false)
if parameters.tempering_enabled && use_mpi == false
numinstances = parameters.numinstances
U₁ = Gaugefield(parameters)
fermion_actions₁ = init_fermion_actions(parameters, U₁)
fermion_action = init_fermion_actions(parameters, U₁)
bias₁ = Bias(parameters, U₁; instance=0) # instance=0 -> dummy bias for non-MetaD stream

U = Vector{typeof(U₁)}(undef, numinstances)
fermion_actions = Vector{typeof(fermion_actions₁)}(undef, numinstances)
bias = Vector{typeof(bias₁)}(undef, numinstances)

U[1] = U₁
fermion_actions[1] = fermion_actions₁
bias[1] = bias₁
for i in 2:numinstances
U[i] = Gaugefield(parameters)
fermion_actions[i] = deepcopy(fermion_actions₁)
bias[i] = Bias(parameters, U[i]; instance=i - 1)
end
else
numinstances = 1
U = Gaugefield(parameters)
fermion_actions = init_fermion_actions(parameters, U)
fermion_action = init_fermion_actions(parameters, U)
bias = Bias(parameters, U; use_mpi=use_mpi)
end
else
@assert parameters.tempering_enabled == false "tempering can only be enabled with bias"
numinstances = 1
U = Gaugefield(parameters)
fermion_actions = init_fermion_actions(parameters, U)
fermion_action = init_fermion_actions(parameters, U)
bias = NoBias()
end

return Univ(U, fermion_actions, bias, Base.RefValue{MYRANK}, numinstances)
return Univ(U, fermion_action, bias, Base.RefValue{MYRANK}, numinstances)
end

function init_fermion_actions(parameters::ParameterSet, U)
Expand Down
4 changes: 2 additions & 2 deletions src/main/runbuild.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function build_bias(filenamein::String; backend="cpu", mpi_enabled=false)
end

# load parameters from toml file
parameters = construct_params_from_toml(filename; backend=backend)
parameters = construct_params_from_toml(filenamein; backend=backend)
MPI.Barrier(COMM)

if MYRANK == 0
Expand Down Expand Up @@ -113,7 +113,7 @@ function metabuild!(
checkpointer,
)
U = univ.U
fermion_action = univ.fermion_actions
fermion_action = univ.fermion_action
bias = univ.bias
# This used to be in Bias itself, but I took all the IOBuffers away from structs
# that are needed for checkpointing
Expand Down
30 changes: 25 additions & 5 deletions src/main/runsim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function run_sim(filenamein::String; backend="cpu", mpi_enabled=false)
end

# load parameters from toml file
parameters = construct_params_from_toml(filename; backend=backend)
parameters = construct_params_from_toml(filenamein; backend=backend)
MPI.Barrier(COMM)

if MYRANK == 0
Expand Down Expand Up @@ -209,7 +209,7 @@ function metaqcd!(
checkpointer,
)
U = univ.U
fermion_action = univ.fermion_actions
fermion_action = univ.fermion_action
bias = univ.bias

# load in config and recalculate gauge action if given
Expand Down Expand Up @@ -299,6 +299,7 @@ function metaqcd_PT!(
numinstances = parameters.numinstances
U = univ.U
bias = univ.bias
fermion_action = univ.fermion_action
swap_every = parameters.swap_every
rank0_updates = parameters.non_metadynamics_updates
measure_on_all = parameters.measure_on_all
Expand All @@ -315,7 +316,14 @@ function metaqcd_PT!(
# thermalize all streams with the updatemethod of stream 1
# shouldnt be a problem for HMC, since we force 0-friction
# for thermalization updates and reverse the order, so stream 1 is last
update!(updatemethod, U[i]; bias=NoBias(), metro_test=false, friction=0)
update!(
updatemethod,
U[i];
fermion_action=fermion_action[i],
bias=NoBias(),
metro_test=false,
friction=0,
)
end
end
@level1("| Elapsed time:\t$(updatetime) [s] @ $(current_time())")
Expand All @@ -335,13 +343,25 @@ function metaqcd_PT!(
_, updatetime = @timed begin
tmp = 0.0
for _ in 1:rank0_updates
tmp += update!(updatemethod, U[1]; bias=NoBias())
tmp += update!(
updatemethod,
U[1];
fermion_action=fermion_action,
bias=NoBias(),
metro_test=true,
)
end
numaccepts[1] += tmp / rank0_updates
rand() < 0.5 && update!(parity, U[1])

for i in 2:numinstances
accepted = update!(updatemethod_pt, U[i]; bias=bias[i])
accepted = update!(
updatemethod_pt,
U[i];
fermion_action=fermion_action,
bias=bias[i],
metro_test=true,
)
accepted == true && update_bias!(bias[i], U[i].CV, itrj)
numaccepts[i] += accepted
end
Expand Down

0 comments on commit bdbe74e

Please sign in to comment.