Skip to content

Commit

Permalink
parallelism invariance
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelbiron committed Dec 20, 2024
1 parent 0a22c4a commit 1ba7742
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions ext/PigeonsJuliaBUGSExt/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,18 @@ function Pigeons.sample_iid!(log_potential::JuliaBUGSLogPotential, replica, shar
replica.state = _sample_iid(log_potential.private_model, replica.rng)
end

# parameter names
Pigeons.sample_names(::Vector, log_potential::JuliaBUGSLogPotential) =
[(Symbol(string(vn)) for vn in log_potential.private_model.parameters)...,:log_density]

# Parallelism invariance
Pigeons.recursive_equal(a::Union{JuliaBUGSPath,JuliaBUGSLogPotential}, b) =
Pigeons._recursive_equal(a,b)
function Pigeons.recursive_equal(a::T, b) where T <: JuliaBUGS.BUGSModel
included = (:transformed, :model_def, :data)
excluded = Tuple(setdiff(fieldnames(T), included))
Pigeons._recursive_equal(a,b,excluded)
end
# just check the betas match, the model is already checked within path
Pigeons.recursive_equal(a::AbstractVector{<:JuliaBUGSLogPotential}, b) =
all(lp1.beta == lp2.beta for (lp1,lp2) in zip(a,b))
6 changes: 3 additions & 3 deletions test/test_JuliaBUGS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ end
@test res.passed
end

@testset "Model with mixed state types using MPI" begin
@testset "Parallelism invariance using MPI" begin
target=incomplete_count_data()
r = pigeons(;
target,
target=unid_target,
n_rounds = 5,
n_chains = 4,
checkpoint = true,
# checked_round = 4, # NB: doesn't work yet, need a fine-tuned equality check for JuliaBUGS.BUGSModel
checked_round = 4,
multithreaded = true,
on = ChildProcess(
n_local_mpi_processes = set_n_mpis_to_one_on_windows(2),
Expand Down

0 comments on commit 1ba7742

Please sign in to comment.