Skip to content

Commit

Permalink
Fix deprecations and default ADTypes (#2156)
Browse files Browse the repository at this point in the history
* Fix deprecations and default ADTypes

* Bump version
  • Loading branch information
devmotion authored Jan 20, 2024
1 parent a7bafb5 commit bb45a1f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 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.30.1"
version = "0.30.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
7 changes: 1 addition & 6 deletions src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ ForwardDiff.checktag(::Type{ForwardDiff.Tag{TuringTag, V}}, ::Base.Fix1{typeof(L
include("stdlib/distributions.jl")
include("stdlib/RandomMeasures.jl")
include("essential/Essential.jl")
Base.@deprecate_binding Core Essential false
using .Essential
include("mcmc/Inference.jl") # inference algorithms
using .Inference
Expand Down Expand Up @@ -131,11 +130,7 @@ export @model, # modelling
get_parameter_bounds,
optim_objective,
optim_function,
optim_problem,

setbackend, # deprecated
setchunksize,
setadsafe
optim_problem

if !isdefined(Base, :get_extension)
using Requires
Expand Down
8 changes: 6 additions & 2 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
function setbackend(::Union{Symbol, Val})
export setadbackend, setchunksize, setadsafe

function setadbackend(::Union{Symbol, Val})
Base.depwarn("`ADBACKEND` and `setbackend` are deprecated. Please specify the chunk size directly in the sampler constructor, e.g., `HMC(0.1, 5; adtype=AutoForwardDiff(; chunksize=0))`.\n This function has no effects.", :setbackend; force=true)
nothing
end
Expand All @@ -8,7 +10,7 @@ function setchunksize(::Int)
nothing
end

function setrdcache(::Bool)
function setrdcache(::Union{Bool, Val})
Base.depwarn("`RDCACHE` and `setrdcache` are deprecated. Please specify if you wish to use compiled tape for ReverseDiff directly in the sampler constructor, e.g., `HMC(0.1, 5; adtype=AutoReverseDiff(false))`.\n This function has no effects.", :setrdcache; force=true)
nothing
end
Expand All @@ -17,3 +19,5 @@ function setadsafe(::Bool)
Base.depwarn("`ADSAFE` and `setadsafe` are outdated and no longer in use.", :setadsafe; force=true)
nothing
end

Base.@deprecate_binding Core Essential false
16 changes: 8 additions & 8 deletions src/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ struct HMC{AD, space, metricT <: AHMC.AbstractMetric} <: StaticHamiltonian
adtype::AD
end

function HMC::Float64, n_leapfrog::Int, ::Type{metricT}, space::Tuple; adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0)) where {metricT<:AHMC.AbstractMetric}
function HMC::Float64, n_leapfrog::Int, ::Type{metricT}, space::Tuple; adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0)) where {metricT<:AHMC.AbstractMetric}
return HMC{typeof(adtype),space,metricT}(ϵ, n_leapfrog, adtype)
end
function HMC(
ϵ::Float64,
n_leapfrog::Int,
space::Symbol...;
metricT=AHMC.UnitEuclideanMetric,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
return HMC(ϵ, n_leapfrog, metricT, space; adtype = adtype)
end
Expand Down Expand Up @@ -316,7 +316,7 @@ struct HMCDA{AD, space, metricT <: AHMC.AbstractMetric} <: AdaptiveHamiltonian
adtype::AD
end

function HMCDA(n_adapts::Int, δ::Float64, λ::Float64, ϵ::Float64, ::Type{metricT}, space::Tuple; adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0)) where {metricT<:AHMC.AbstractMetric}
function HMCDA(n_adapts::Int, δ::Float64, λ::Float64, ϵ::Float64, ::Type{metricT}, space::Tuple; adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0)) where {metricT<:AHMC.AbstractMetric}
return HMCDA{typeof(adtype),space,metricT}(n_adapts, δ, λ, ϵ, adtype)
end

Expand All @@ -325,7 +325,7 @@ function HMCDA(
λ::Float64;
init_ϵ::Float64=0.0,
metricT=AHMC.UnitEuclideanMetric,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
return HMCDA(-1, δ, λ, init_ϵ, metricT, (); adtype = adtype)
end
Expand All @@ -347,7 +347,7 @@ function HMCDA(
space::Symbol...;
init_ϵ::Float64=0.0,
metricT=AHMC.UnitEuclideanMetric,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
return HMCDA(n_adapts, δ, λ, init_ϵ, metricT, space; adtype = adtype)
end
Expand Down Expand Up @@ -393,7 +393,7 @@ function NUTS(
ϵ::Float64,
::Type{metricT},
space::Tuple;
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
) where {metricT}
return NUTS{typeof(adtype),space,metricT}(n_adapts, δ, max_depth, Δ_max, ϵ, adtype)
end
Expand All @@ -415,7 +415,7 @@ function NUTS(
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
NUTS(n_adapts, δ, max_depth, Δ_max, init_ϵ, metricT, space; adtype=adtype)
end
Expand All @@ -426,7 +426,7 @@ function NUTS(
Δ_max::Float64=1000.0,
init_ϵ::Float64=0.0,
metricT=AHMC.DiagEuclideanMetric,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
NUTS(-1, δ, max_depth, Δ_max, init_ϵ, metricT, (); adtype=adtype)
end
Expand Down
4 changes: 2 additions & 2 deletions src/mcmc/sghmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function SGHMC(
space::Symbol...;
learning_rate::Real,
momentum_decay::Real,
adtype::ADTypes.AbstractADType=AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType=ADTypes.AutoForwardDiff(; chunksize=0),
)
_learning_rate, _momentum_decay = promote(learning_rate, momentum_decay)
return SGHMC{typeof(adtype),space,typeof(_learning_rate)}(_learning_rate, _momentum_decay, adtype)
Expand Down Expand Up @@ -184,7 +184,7 @@ See also: [`PolynomialStepsize`](@ref)
function SGLD(
space::Symbol...;
stepsize = PolynomialStepsize(0.01),
adtype::ADTypes.AbstractADType = AutoForwardDiff(; chunksize=0),
adtype::ADTypes.AbstractADType = ADTypes.AutoForwardDiff(; chunksize=0),
)
return SGLD{typeof(adtype),space,typeof(stepsize)}(stepsize, adtype)
end
Expand Down

2 comments on commit bb45a1f

@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/99215

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

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

Please sign in to comment.