Skip to content

Commit

Permalink
Make particle Gibbs deterministic across architectures (#109)
Browse files Browse the repository at this point in the history
* Make split() deterministic across architectures

* Increase number of test samples to make it pass
  • Loading branch information
penelopeysm authored Jan 23, 2025
1 parent 6c2cee3 commit d0d180f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AdvancedPS"
uuid = "576499cb-2369-40b2-a588-c64705576edc"
authors = ["TuringLang"]
version = "0.6"
version = "0.6.1"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
5 changes: 3 additions & 2 deletions src/rng.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ Base.rand(rng::TracedRNG, ::Type{T}) where {T} = Base.rand(rng.rng, T)
Split `key` into `n` new keys
"""
function split(key::Integer, n::Integer=1)
T = typeof(key) # Make sure the type of `key` is consistent on W32 and W64 systems.
return T[hash(key, i) for i in UInt(1):UInt(n)]
T = typeof(key)
inner_rng = Random.MersenneTwister(key)
return rand(inner_rng, T, n)
end

"""
Expand Down
4 changes: 3 additions & 1 deletion test/linear-gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
@testset "linear-gaussian.jl" begin
T = 3
N_PARTICLES = 100
N_SAMPLES = 50
N_SAMPLES = 200

# Model dynamics
a = 0.5
Expand Down Expand Up @@ -100,12 +100,14 @@ end
@testset "PGAS" begin
pgas = AdvancedPS.PGAS(N_PARTICLES)
p = test_algorithm(rng, pgas, model, N_SAMPLES, Xf)
@info p
@test p > 0.05
end

@testset "PG" begin
pg = AdvancedPS.PG(N_PARTICLES)
p = test_algorithm(rng, pg, model, N_SAMPLES, Xf)
@info p
@test p > 0.05
end
end

0 comments on commit d0d180f

Please sign in to comment.