diff --git a/HISTORY.md b/HISTORY.md index 580932cb71..aa4dbc662f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 0.47.0 + + - Removed Turing's local `PROGRESS` and `setprogress!`; use `AbstractMCMC.PROGRESS` and `AbstractMCMC.setprogress!` instead. + # 0.46.0 ## Breaking changes diff --git a/docs/src/api.md b/docs/src/api.md index 1342014ae6..8ea7049e48 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -144,12 +144,6 @@ See the [AD guide](https://turinglang.org/docs/tutorials/docs-10-using-turing-au | `AutoMooncake` | [`ADTypes.AutoMooncake`](@extref) | Mooncake.jl backend | | `AutoReverseDiff` | [`ADTypes.AutoReverseDiff`](@extref) | ReverseDiff.jl backend | -### Debugging - -```@docs -setprogress! -``` - ### Distributions These distributions are defined in Turing.jl, but not in Distributions.jl. diff --git a/src/Turing.jl b/src/Turing.jl index 45c6459e7f..ec4411fbb4 100644 --- a/src/Turing.jl +++ b/src/Turing.jl @@ -24,21 +24,6 @@ using ADTypes: ADTypes, AutoForwardDiff, AutoReverseDiff, AutoMooncake, AutoEnzy const DEFAULT_ADTYPE = ADTypes.AutoForwardDiff() -const PROGRESS = Ref(true) - -# TODO: remove `PROGRESS` and this function in favour of `AbstractMCMC.PROGRESS` -""" - setprogress!(progress::Bool) - -Enable progress logging in Turing if `progress` is `true`, and disable it otherwise. -""" -function setprogress!(progress::Bool) - @info "[Turing]: progress logging is $(progress ? "enabled" : "disabled") globally" - PROGRESS[] = progress - AbstractMCMC.setprogress!(progress; silent=true) - return progress -end - # Random probability measures. include("stdlib/distributions.jl") include("stdlib/RandomMeasures.jl") @@ -141,8 +126,6 @@ export AutoReverseDiff, AutoMooncake, AutoEnzyme, - # Debugging - Turing - setprogress!, # Distributions Flat, FlatPos, diff --git a/src/mcmc/Inference.jl b/src/mcmc/Inference.jl index b9aa08e8f6..bf5f3fafb1 100644 --- a/src/mcmc/Inference.jl +++ b/src/mcmc/Inference.jl @@ -18,7 +18,7 @@ using DynamicPPL: using Distributions, Libtask, Bijectors using FlexiChains: FlexiChains, VNChain using LinearAlgebra -using ..Turing: PROGRESS, Turing +using ..Turing: Turing using StatsFuns: logsumexp using Random: AbstractRNG using AbstractMCMC: AbstractModel, AbstractSampler diff --git a/src/mcmc/hmc.jl b/src/mcmc/hmc.jl index 3e7a28945c..a990cadf89 100644 --- a/src/mcmc/hmc.jl +++ b/src/mcmc/hmc.jl @@ -91,7 +91,7 @@ function AbstractMCMC.sample( chain_type=DEFAULT_CHAIN_TYPE, initial_params=Turing.Inference.init_strategy(sampler), initial_state=nothing, - progress=PROGRESS[], + progress=AbstractMCMC.PROGRESS[], nadapts=sampler.n_adapts, discard_adapt=true, discard_initial=-1, diff --git a/src/mcmc/particle_mcmc.jl b/src/mcmc/particle_mcmc.jl index 2bef555edc..348d1905f6 100644 --- a/src/mcmc/particle_mcmc.jl +++ b/src/mcmc/particle_mcmc.jl @@ -134,7 +134,7 @@ function AbstractMCMC.sample( check_model=true, chain_type=DEFAULT_CHAIN_TYPE, initial_params=Turing.Inference.init_strategy(sampler), - progress=PROGRESS[], + progress=AbstractMCMC.PROGRESS[], discard_initial=0, thinning=1, verbose=false, diff --git a/src/mcmc/repeat_sampler.jl b/src/mcmc/repeat_sampler.jl index 6f97321da7..3b63c8c1b4 100644 --- a/src/mcmc/repeat_sampler.jl +++ b/src/mcmc/repeat_sampler.jl @@ -116,7 +116,7 @@ function AbstractMCMC.sample( check_model=true, initial_params=Turing.Inference.init_strategy(sampler), chain_type=DEFAULT_CHAIN_TYPE, - progress=PROGRESS[], + progress=AbstractMCMC.PROGRESS[], verbose=true, kwargs..., ) @@ -146,7 +146,7 @@ function AbstractMCMC.sample( check_model=true, initial_params=fill(Turing.Inference.init_strategy(sampler), n_chains), chain_type=DEFAULT_CHAIN_TYPE, - progress=PROGRESS[], + progress=AbstractMCMC.PROGRESS[], kwargs..., ) check_model && Turing._check_model(model, sampler) diff --git a/src/variational/Variational.jl b/src/variational/Variational.jl index 0ab9560231..ef6c4e3877 100644 --- a/src/variational/Variational.jl +++ b/src/variational/Variational.jl @@ -18,7 +18,8 @@ using DynamicPPL: DynamicPPL, LogDensityFunction using LinearAlgebra using LogDensityProblems: LogDensityProblems using Random -using ..Turing: DEFAULT_ADTYPE, PROGRESS +using ..Turing: DEFAULT_ADTYPE +import AbstractMCMC export vi, q_locationscale, @@ -94,7 +95,7 @@ function q_initialize_scale( energy = mean( map(1:num_samples) do _ z = rand(rng, q) - LogDensityProblems.logdensity(ldf, z) + return LogDensityProblems.logdensity(ldf, z) end, ) @@ -347,7 +348,7 @@ Base.rand(res::VIResult, sz::Integer...) = Base.rand(Random.default_rng(), res, ), unconstrained::Bool=requires_unconstrained_space(algorithm), fix_transforms::Bool=false, - show_progress::Bool = Turing.PROGRESS[], + show_progress::Bool = AbstractMCMC.PROGRESS[], kwargs... ) @@ -391,7 +392,7 @@ function vi( ), unconstrained::Bool=requires_unconstrained_space(algorithm), fix_transforms::Bool=false, - show_progress::Bool=PROGRESS[], + show_progress::Bool=AbstractMCMC.PROGRESS[], kwargs..., ) transform_strategy = unconstrained ? DynamicPPL.LinkAll() : DynamicPPL.UnlinkAll() diff --git a/test/mcmc/chains.jl b/test/mcmc/chains.jl index 7189448d4e..3922395c9c 100644 --- a/test/mcmc/chains.jl +++ b/test/mcmc/chains.jl @@ -9,7 +9,7 @@ using Random: Random, Xoshiro using Test using Turing -Turing.setprogress!(false) +AbstractMCMC.setprogress!(false) # This sampler does nothing (it just stays at the existing state) struct StaticSampler <: AbstractMCMC.AbstractSampler end diff --git a/test/runtests.jl b/test/runtests.jl index c4faea5a37..e5e889808d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,6 +4,7 @@ using Pkg using Random: seed! using Test using TimerOutputs: TimerOutputs, @timeit +using AbstractMCMC: AbstractMCMC import Turing # Fix the global Random.seed for reproducibility. @@ -13,7 +14,7 @@ include("test_utils/models.jl") include("test_utils/numerical_tests.jl") include("test_utils/sampler.jl") -Turing.setprogress!(false) +AbstractMCMC.setprogress!(false) included_paths, excluded_paths = parse_args(ARGS) # Filter which tests to run and collect timing and allocations information to show in a diff --git a/test/variational/vi.jl b/test/variational/vi.jl index a8bdcc079b..e685181630 100644 --- a/test/variational/vi.jl +++ b/test/variational/vi.jl @@ -3,7 +3,7 @@ module AdvancedVITests using ..Models: gdemo_default using ..NumericalTests: check_gdemo -using AbstractMCMC: AbstractMCMC +import AbstractMCMC using AdvancedVI using Bijectors: Bijectors using Distributions: Dirichlet, Normal @@ -49,7 +49,9 @@ using Turing.Variational @testset "default interface" begin for q0 in [q_meanfield_gaussian, q_fullrank_gaussian] - result = vi(gdemo_default, q0, 100; show_progress=Turing.PROGRESS[], adtype) + result = vi( + gdemo_default, q0, 100; show_progress=AbstractMCMC.PROGRESS[], adtype + ) @test result isa Turing.Variational.VIResult @test rand(result) isa DynamicPPL.VarNamedTuple @test rand(result, 2) isa Vector{<:DynamicPPL.VarNamedTuple} @@ -76,7 +78,7 @@ using Turing.Variational q_fullrank_gaussian, T; algorithm, - show_progress=Turing.PROGRESS[], + show_progress=AbstractMCMC.PROGRESS[], ) c2 = rand(result, 10) @test c2 isa Vector{<:DynamicPPL.VarNamedTuple} @@ -105,7 +107,7 @@ using Turing.Variational q_fullrank_gaussian, T; algorithm, - show_progress=Turing.PROGRESS[], + show_progress=AbstractMCMC.PROGRESS[], ) N = 1000