Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function sample(
Draw `n_samples` samples using the kernel `κ` under the Hamiltonian system `h`

- The randomness is controlled by `rng`.
- If `rng` is not provided, `GLOBAL_RNG` will be used.
- If `rng` is not provided, the default random number generator (`Random.default_rng()`) will be used.
- The initial point is given by `θ`.
- The adaptor is set by `adaptor`, for which the default is no adaptation.
- It will perform `n_adapts` steps of adaptation, for which the default is `1_000` or 10% of `n_samples`, whichever is lower.
Expand Down
2 changes: 1 addition & 1 deletion research/src/riemannian_hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Base.rand(rng::AbstractRNG, metric::AbstractMetric, kinetic, θ) =
_rand(rng, metric, kinetic) # this disambiguity is required by Random.rand
Base.rand(rng::AbstractVector{<:AbstractRNG}, metric::AbstractMetric, kinetic, θ) =
_rand(rng, metric, kinetic)
Base.rand(metric::AbstractMetric, kinetic, θ) = rand(GLOBAL_RNG, metric, kinetic)
Base.rand(metric::AbstractMetric, kinetic, θ) = rand(Random.default_rng(), metric, kinetic)

### metric.jl

Expand Down
2 changes: 1 addition & 1 deletion src/AdvancedHMC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using LinearAlgebra:
Symmetric, UpperTriangular, mul!, ldiv!, dot, I, diag, cholesky, UniformScaling
using StatsFuns: logaddexp, logsumexp
import Random
using Random: GLOBAL_RNG, AbstractRNG
using Random: AbstractRNG
using ProgressMeter: ProgressMeter
using SimpleUnPack: @unpack

Expand Down
2 changes: 1 addition & 1 deletion src/metric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ Base.rand(
kinetic::AbstractKinetic,
) = _rand(rng, metric, kinetic)
Base.rand(metric::AbstractMetric, kinetic::AbstractKinetic) =
rand(GLOBAL_RNG, metric, kinetic)
rand(Random.default_rng(), metric, kinetic)

# ignore θ by default unless defined by the specific kinetic (i.e. not position-dependent)
Base.rand(
Expand Down
4 changes: 2 additions & 2 deletions src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ sample(
progress::Bool = false,
(pm_next!)::Function = pm_next!,
) = sample(
GLOBAL_RNG,
Random.default_rng(),
h,
κ,
θ,
Expand Down Expand Up @@ -146,7 +146,7 @@ sample(
)
Sample `n_samples` samples using the proposal `κ` under Hamiltonian `h`.
- The randomness is controlled by `rng`.
- If `rng` is not provided, `GLOBAL_RNG` will be used.
- If `rng` is not provided, the default random number generator (`Random.default_rng()`) will be used.
- The initial point is given by `θ`.
- The adaptor is set by `adaptor`, for which the default is no adaptation.
- It will perform `n_adapts` steps of adaptation, for which the default is the minimum of `1_000` and 10% of `n_samples`
Expand Down
8 changes: 4 additions & 4 deletions src/trajectory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
####
#### Developers' Notes
####
#### Not all functions that use `rng` require a fallback function with `GLOBAL_RNG`
#### Not all functions that use `rng` require a fallback function with `Random.default_rng()`
#### as default. In short, only those exported to other libries need such a fallback
#### function. Internal uses shall always use the explict `rng` version. (Kai Xu 6/Jul/19)

Expand Down Expand Up @@ -241,10 +241,10 @@ $(SIGNATURES)

Make a MCMC transition from phase point `z` using the trajectory `τ` under Hamiltonian `h`.

NOTE: This is a RNG-implicit fallback function for `transition(GLOBAL_RNG, τ, h, z)`
NOTE: This is a RNG-implicit fallback function for `transition(Random.default_rng(), τ, h, z)`
"""
function transition(τ::Trajectory, h::Hamiltonian, z::PhasePoint)
return transition(GLOBAL_RNG, τ, h, z)
return transition(Random.default_rng(), τ, h, z)
end

###
Expand Down Expand Up @@ -834,7 +834,7 @@ function find_good_stepsize(
θ::AbstractVector{<:AbstractFloat};
max_n_iters::Int = 100,
)
return find_good_stepsize(GLOBAL_RNG, h, θ; max_n_iters = max_n_iters)
return find_good_stepsize(Random.default_rng(), h, θ; max_n_iters = max_n_iters)
end

"Perform MH acceptance based on energy, i.e. negative log probability."
Expand Down
4 changes: 2 additions & 2 deletions test/integrator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ using Statistics: mean
@test AdvancedHMC.nom_step_size(lf) == ϵ0
@test AdvancedHMC.step_size(lf) == ϵ0

lf2 = AdvancedHMC.jitter(Random.GLOBAL_RNG, lf)
lf2 = AdvancedHMC.jitter(Random.default_rng(), lf)
@test lf2 === lf
@test AdvancedHMC.nom_step_size(lf2) == ϵ0
@test AdvancedHMC.step_size(lf2) == ϵ0
Expand All @@ -53,7 +53,7 @@ using Statistics: mean
@test lf.ϵ == ϵ0
@test AdvancedHMC.step_size(lf) == lf.ϵ

lf2 = AdvancedHMC.jitter(Random.GLOBAL_RNG, lf)
lf2 = AdvancedHMC.jitter(Random.default_rng(), lf)
@test lf2.ϵ0 == ϵ0
@test AdvancedHMC.nom_step_size(lf2) == ϵ0
@test lf2.ϵ != ϵ0
Expand Down
Loading