Skip to content

Commit

Permalink
Use Random.default_rng() (#1967)
Browse files Browse the repository at this point in the history
  • Loading branch information
devmotion committed Mar 12, 2023
1 parent b365de7 commit a8a06ed
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 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.24.2"
version = "0.24.3"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/for-developers/compiler.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ A `model::Model` is a callable struct that one can sample from by calling
```julia
(model::Model)([rng, varinfo, sampler, context])
```
where `rng` is a random number generator (default: `Random.GLOBAL_RNG`), `varinfo` is a data structure that stores information
where `rng` is a random number generator (default: `Random.default_rng()`), `varinfo` is a data structure that stores information
about the random variables (default: `DynamicPPL.VarInfo()`), `sampler` is a sampling algorithm (default: `DynamicPPL.SampleFromPrior()`),
and `context` is a sampling context that can, e.g., modify how the log probability is accumulated (default: `DynamicPPL.DefaultContext()`).

Expand Down
2 changes: 1 addition & 1 deletion docs/src/using-turing/performancetips.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ model = tmodel(1.0)
model,
Turing.VarInfo(model),
Turing.SamplingContext(
Random.GLOBAL_RNG, Turing.SampleFromPrior(), Turing.DefaultContext(),
Random.default_rng(), Turing.SampleFromPrior(), Turing.DefaultContext(),
),
model.args...,
)
Expand Down
10 changes: 5 additions & 5 deletions src/inference/Inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function AbstractMCMC.sample(
N::Integer;
kwargs...
)
return AbstractMCMC.sample(Random.GLOBAL_RNG, model, alg, N; kwargs...)
return AbstractMCMC.sample(Random.default_rng(), model, alg, N; kwargs...)
end

function AbstractMCMC.sample(
Expand Down Expand Up @@ -190,7 +190,7 @@ function AbstractMCMC.sample(
n_chains::Integer;
kwargs...
)
return AbstractMCMC.sample(Random.GLOBAL_RNG, model, alg, ensemble, N, n_chains;
return AbstractMCMC.sample(Random.default_rng(), model, alg, ensemble, N, n_chains;
kwargs...)
end

Expand Down Expand Up @@ -397,7 +397,7 @@ function save(c::MCMCChains.Chains, spl::Sampler, model, vi, samples)
end

function resume(chain::MCMCChains.Chains, args...; kwargs...)
return resume(Random.GLOBAL_RNG, chain, args...; kwargs...)
return resume(Random.default_rng(), chain, args...; kwargs...)
end

function resume(rng::Random.AbstractRNG, chain::MCMCChains.Chains, args...;
Expand Down Expand Up @@ -530,7 +530,7 @@ true
```
"""
function predict(model::Model, chain::MCMCChains.Chains; kwargs...)
return predict(Random.GLOBAL_RNG, model, chain; kwargs...)
return predict(Random.default_rng(), model, chain; kwargs...)
end
function predict(rng::AbstractRNG, model::Model, chain::MCMCChains.Chains; include_all = false)
# Don't need all the diagnostics
Expand Down Expand Up @@ -617,7 +617,7 @@ function transitions_from_chain(
chain::MCMCChains.Chains;
kwargs...
)
return transitions_from_chain(Random.GLOBAL_RNG, model, chain; kwargs...)
return transitions_from_chain(Random.default_rng(), model, chain; kwargs...)
end

function transitions_from_chain(
Expand Down
2 changes: 1 addition & 1 deletion src/variational/advi.jl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ end
Creates a mean-field approximation with multivariate normal as underlying distribution.
"""
meanfield(model::DynamicPPL.Model) = meanfield(Random.GLOBAL_RNG, model)
meanfield(model::DynamicPPL.Model) = meanfield(Random.default_rng(), model)
function meanfield(rng::Random.AbstractRNG, model::DynamicPPL.Model)
# Setup.
varinfo = DynamicPPL.VarInfo(model)
Expand Down
2 changes: 1 addition & 1 deletion test/inference/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Test gid of each samplers
g = Turing.Sampler(s3, gdemo_default)

_, state = AbstractMCMC.step(Random.GLOBAL_RNG, gdemo_default, g)
_, state = AbstractMCMC.step(Random.default_rng(), gdemo_default, g)
@test state.samplers[1].selector != g.selector
@test state.samplers[2].selector != g.selector
@test state.samplers[1].selector != state.samplers[2].selector
Expand Down

2 comments on commit a8a06ed

@devmotion
Copy link
Member Author

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/79439

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.24.3 -m "<description of version>" a8a06ed1d88ec0074c188f401dd73ce741feb443
git push origin v0.24.3

Please sign in to comment.