Skip to content

Commit d0d180f

Browse files
authored
Make particle Gibbs deterministic across architectures (#109)
* Make split() deterministic across architectures * Increase number of test samples to make it pass
1 parent 6c2cee3 commit d0d180f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AdvancedPS"
22
uuid = "576499cb-2369-40b2-a588-c64705576edc"
33
authors = ["TuringLang"]
4-
version = "0.6"
4+
version = "0.6.1"
55

66
[deps]
77
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"

src/rng.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ Base.rand(rng::TracedRNG, ::Type{T}) where {T} = Base.rand(rng.rng, T)
3636
Split `key` into `n` new keys
3737
"""
3838
function split(key::Integer, n::Integer=1)
39-
T = typeof(key) # Make sure the type of `key` is consistent on W32 and W64 systems.
40-
return T[hash(key, i) for i in UInt(1):UInt(n)]
39+
T = typeof(key)
40+
inner_rng = Random.MersenneTwister(key)
41+
return rand(inner_rng, T, n)
4142
end
4243

4344
"""

test/linear-gaussian.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
@testset "linear-gaussian.jl" begin
2727
T = 3
2828
N_PARTICLES = 100
29-
N_SAMPLES = 50
29+
N_SAMPLES = 200
3030

3131
# Model dynamics
3232
a = 0.5
@@ -100,12 +100,14 @@ end
100100
@testset "PGAS" begin
101101
pgas = AdvancedPS.PGAS(N_PARTICLES)
102102
p = test_algorithm(rng, pgas, model, N_SAMPLES, Xf)
103+
@info p
103104
@test p > 0.05
104105
end
105106

106107
@testset "PG" begin
107108
pg = AdvancedPS.PG(N_PARTICLES)
108109
p = test_algorithm(rng, pg, model, N_SAMPLES, Xf)
110+
@info p
109111
@test p > 0.05
110112
end
111113
end

0 commit comments

Comments
 (0)