diff --git a/HISTORY.md b/HISTORY.md index d325001698..25d1357573 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 0.47.1 + +`setprogress!` is now a re-export of `AbstractMCMC.setprogress!`, so `Turing.setprogress!(false)` keeps working and there is a single progress logging switch instead of two. The internal `Turing.PROGRESS` flag is gone, its state lives in `AbstractMCMC.PROGRESS`. + # 0.47.0 ## Breaking changes diff --git a/Project.toml b/Project.toml index c113c5bbb9..b73fdf98bd 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "Turing" uuid = "fce5fe82-541a-59a6-adf8-730c64b5f9a0" -version = "0.47.0" +version = "0.47.1" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/docs/src/api.md b/docs/src/api.md index 1342014ae6..6d6a59505d 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -146,9 +146,7 @@ See the [AD guide](https://turinglang.org/docs/tutorials/docs-10-using-turing-au ### Debugging -```@docs -setprogress! -``` +`setprogress!` is re-exported from AbstractMCMC. See [`AbstractMCMC.setprogress!`](@extref). ### Distributions diff --git a/src/Turing.jl b/src/Turing.jl index 45c6459e7f..7fbddf2140 100644 --- a/src/Turing.jl +++ b/src/Turing.jl @@ -14,6 +14,7 @@ using LogDensityProblems: LogDensityProblems using StatsAPI: StatsAPI using StatsBase: StatsBase using AbstractMCMC +using AbstractMCMC: setprogress! using FlexiChains using Printf: Printf @@ -24,21 +25,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,7 +127,7 @@ export AutoReverseDiff, AutoMooncake, AutoEnzyme, - # Debugging - Turing + # Progress logging - re-exported from AbstractMCMC setprogress!, # Distributions Flat, diff --git a/src/mcmc/Inference.jl b/src/mcmc/Inference.jl index 5d5cf28669..094f63f032 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/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..f6ae823235 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, @@ -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/variational/vi.jl b/test/variational/vi.jl index a8bdcc079b..d692653424 100644 --- a/test/variational/vi.jl +++ b/test/variational/vi.jl @@ -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