Skip to content

Commit

Permalink
Fix non-reproducible step sizes (#1924)
Browse files Browse the repository at this point in the history
* Fix non-reproducible step sizes

* Add test
  • Loading branch information
devmotion authored Dec 24, 2022
1 parent 61b06f6 commit f9353f0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "Turing"
uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
version = "0.23.1"
version = "0.23.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
4 changes: 2 additions & 2 deletions src/inference/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function DynamicPPL.initialstep(

# Find good eps if not provided one
if iszero(spl.alg.ϵ)
ϵ = AHMC.find_good_stepsize(hamiltonian, theta)
ϵ = AHMC.find_good_stepsize(rng, hamiltonian, theta)
@info "Found initial step size" ϵ
else
ϵ = spl.alg.ϵ
Expand Down Expand Up @@ -550,7 +550,7 @@ function HMCState(

# Find good eps if not provided one
if iszero(spl.alg.ϵ)
ϵ = AHMC.find_good_stepsize(h, θ_init)
ϵ = AHMC.find_good_stepsize(rng, h, θ_init)
@info "Found initial step size" ϵ
else
ϵ = spl.alg.ϵ
Expand Down
9 changes: 9 additions & 0 deletions test/inference/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,13 @@
end
@test sample(rng, mwe3(), HMC(0.2, 4), 1_000) isa Chains
end

# issue #1923
@turing_testset "reproducibility" begin
alg = NUTS(1000, 0.8)
res1 = sample(StableRNG(123), gdemo_default, alg, 1000)
res2 = sample(StableRNG(123), gdemo_default, alg, 1000)
res3 = sample(StableRNG(123), gdemo_default, alg, 1000)
@test Array(res1) == Array(res2) == Array(res3)
end
end

2 comments on commit f9353f0

@yebai
Copy link
Member

@yebai yebai commented on f9353f0 Dec 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/74600

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.23.2 -m "<description of version>" f9353f0f287504a6fa02809cb2e32cc5173b58ae
git push origin v0.23.2

Please sign in to comment.