Skip to content

Commit

Permalink
Only enable progress logging on Julia < 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed May 31, 2022
1 parent ea158d9 commit b3705a2
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions test/sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,12 @@
@test !ismissing(chain[1].a)

# Repeat sampling without discarding initial samples.
# On Julia < 1.6 progress logging changes the global RNG and hence is enabled here.
# https://github.com/TuringLang/AbstractMCMC.jl/pull/102#issuecomment-1142253258
Random.seed!(1234)
ref_chain = sample(MyModel(), MySampler(), N + discard_initial)
ref_chain = sample(
MyModel(), MySampler(), N + discard_initial; progress=VERSION < v"1.6"
)
@test all(chain[i].a === ref_chain[i + discard_initial].a for i in 1:N)
@test all(chain[i].b === ref_chain[i + discard_initial].b for i in 1:N)
end
Expand All @@ -498,8 +502,10 @@
@test ismissing(chain[1].a)

# Repeat sampling without thinning.
# On Julia < 1.6 progress logging changes the global RNG and hence is enabled here.
# https://github.com/TuringLang/AbstractMCMC.jl/pull/102#issuecomment-1142253258
Random.seed!(1234)
ref_chain = sample(MyModel(), MySampler(), N * thinning)
ref_chain = sample(MyModel(), MySampler(), N * thinning; progress=VERSION < v"1.6")
@test all(chain[i].a === ref_chain[(i - 1) * thinning + 1].a for i in 1:N)
end

Expand All @@ -518,9 +524,17 @@
@test !ismissing(chain[1].a)
@test abs(bmean) <= 0.001 || length(chain) == 10_000

# On Julia < 1.6 progress logging changes the global RNG and hence is enabled here.
# https://github.com/TuringLang/AbstractMCMC.jl/pull/102#issuecomment-1142253258
Random.seed!(1234)
N = length(chain)
ref_chain = sample(MyModel(), MySampler(), N; discard_initial=discard_initial)
ref_chain = sample(
MyModel(),
MySampler(),
N;
discard_initial=discard_initial,
progress=VERSION < v"1.6",
)
@test all(chain[i].a === ref_chain[i].a for i in 1:N)
@test all(chain[i].b === ref_chain[i].b for i in 1:N)

Expand All @@ -532,9 +546,13 @@
@test ismissing(chain[1].a)
@test abs(bmean) <= 0.001 || length(chain) == 10_000

# On Julia < 1.6 progress logging changes the global RNG and hence is enabled here.
# https://github.com/TuringLang/AbstractMCMC.jl/pull/102#issuecomment-1142253258
Random.seed!(1234)
N = length(chain)
ref_chain = sample(MyModel(), MySampler(), N; thinning=thinning)
ref_chain = sample(
MyModel(), MySampler(), N; thinning=thinning, progress=VERSION < v"1.6"
)
@test all(chain[i].a === ref_chain[i].a for i in 1:N)
@test all(chain[i].b === ref_chain[i].b for i in 1:N)
end
Expand Down

0 comments on commit b3705a2

Please sign in to comment.