Skip to content

Commit

Permalink
Bump turing version 0.36 (#22)
Browse files Browse the repository at this point in the history
* bump turing version
* update Turing compat by implementing mising AbstractMCMC interfaces
* bump SliceSampling compat for docs

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Markus Hauru <[email protected]>
  • Loading branch information
3 people authored Jan 16, 2025
1 parent 731239a commit 08e47db
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SliceSampling"
uuid = "43f4d3e8-9711-4a8c-bd1b-03ac73a255cf"
version = "0.7"
version = "0.7.1"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down Expand Up @@ -29,7 +29,7 @@ LogDensityProblems = "2"
LogDensityProblemsAD = "1"
Random = "1"
Requires = "1"
Turing = "0.33, 0.34, 0.35"
Turing = "0.36"
julia = "1.10"

[extras]
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ model = demo()
sample(model, externalsampler(sampler), n_samples)
```

The following slice samplers can also be used as a conditional sampler in `Turing.Experimental.Gibbs` sampler:
The following slice samplers can also be used as a conditional sampler in `Turing.Gibbs` sampler:
* For multidimensional variables:
* `RandPermGibbs`
* `HitAndRun`
Expand All @@ -69,11 +69,9 @@ using SliceSampling
end
end

sampler = Turing.Experimental.Gibbs(
(
p = externalsampler(SliceSteppingOut(2.0)),
z = PG(20, :z)
)
sampler = Turing.Gibbs(
:p => externalsampler(SliceSteppingOut(2.0)),
:z => PG(20, :z),
)

n_samples = 1000
Expand Down
4 changes: 2 additions & 2 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ PDMats = "0.11"
Plots = "1"
PrettyTables = "2"
Random = "1"
SliceSampling = "0.6, 0.7"
SliceSampling = "0.7.1"
StableRNGs = "1"
Statistics = "1"
Turing = "0.34, 0.35"
Turing = "0.36"
julia = "1.10"
12 changes: 5 additions & 7 deletions docs/src/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ model = demo()
sample(model, externalsampler(sampler), n_samples)
```

### Conditional sampling in a `Turing.Experimental.Gibbs` sampler
`SliceSampling.jl` be used as a conditional sampler in `Turing.Experimental.Gibbs`.
### Conditional sampling in a `Turing.Gibbs` sampler
`SliceSampling.jl` be used as a conditional sampler in `Turing.Gibbs`.

```@example turinggibbs
using Distributions
Expand All @@ -80,11 +80,9 @@ using SliceSampling
end
end
sampler = Turing.Experimental.Gibbs(
(
p = externalsampler(SliceSteppingOut(2.0)),
z = PG(20, :z)
)
sampler = Turing.Gibbs(
:p => externalsampler(SliceSteppingOut(2.0)),
:z => PG(20, :z),
)
n_samples = 1000
Expand Down
26 changes: 9 additions & 17 deletions ext/SliceSamplingTuringExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ if isdefined(Base, :get_extension)
using Random
using SliceSampling
using Turing
# using Turing: Turing, Experimental
else
using ..LogDensityProblemsAD
using ..Random
using ..SliceSampling
using ..Turing
#using ..Turing: Turing, Experimental
end

# Required for using the slice samplers as `externalsampler`s in Turing
Expand All @@ -24,12 +22,18 @@ function Turing.Inference.getparams(
end
# end

# Required for using the slice samplers as `Experimental.Gibbs` samplers in Turing
# Required for using the slice samplers as `Gibbs` samplers in Turing
# begin
Turing.Inference.isgibbscomponent(::SliceSampling.RandPermGibbs) = true
Turing.Inference.isgibbscomponent(::SliceSampling.HitAndRun) = true
Turing.Inference.isgibbscomponent(::SliceSampling.Slice) = true
Turing.Inference.isgibbscomponent(::SliceSampling.SliceSteppingOut) = true
Turing.Inference.isgibbscomponent(::SliceSampling.SliceDoublingOut) = true

function Turing.Inference.getparams(
::Turing.DynamicPPL.Model, state::SliceSampling.UnivariateSliceState
::Turing.DynamicPPL.Model, sample::SliceSampling.UnivariateSliceState
)
return state.transition.params
return sample.transition.params
end

function Turing.Inference.getparams(
Expand All @@ -43,18 +47,6 @@ function Turing.Inference.getparams(
)
return state.transition.params
end

function Turing.Experimental.gibbs_requires_recompute_logprob(
model_dst,
::Turing.DynamicPPL.Sampler{
<:Turing.Inference.ExternalSampler{<:SliceSampling.AbstractSliceSampling,A,U}
},
sampler_src,
state_dst,
state_src,
) where {A,U}
return false
end
# end

function SliceSampling.initial_sample(rng::Random.AbstractRNG, ℓ::Turing.LogDensityFunction)
Expand Down
7 changes: 7 additions & 0 deletions src/multivariate/hitandrun.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ struct HitAndRunState{T<:Transition}
transition::T
end

function AbstractMCMC.setparams!!(
model::AbstractMCMC.LogDensityModel, state::HitAndRunState, params
)
lp = LogDensityProblems.logdensity(model.logdensity, params)
return HitAndRunState(Transition(params, lp, NamedTuple()))
end

struct HitAndRunTarget{Model,Vec<:AbstractVector}
model :: Model
direction :: Vec
Expand Down
7 changes: 7 additions & 0 deletions src/multivariate/randpermgibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ struct GibbsState{T<:Transition}
transition::T
end

function AbstractMCMC.setparams!!(
model::AbstractMCMC.LogDensityModel, state::GibbsState, params
)
lp = LogDensityProblems.logdensity(model.logdensity, params)
return GibbsState(Transition(params, lp, NamedTuple()))
end

struct GibbsTarget{Model,Idx<:Integer,Vec<:AbstractVector}
model :: Model
idx :: Idx
Expand Down
7 changes: 7 additions & 0 deletions src/univariate/univariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ struct UnivariateSliceState{T<:Transition}
transition::T
end

function AbstractMCMC.setparams!!(
model::AbstractMCMC.LogDensityModel, state::UnivariateSliceState, params
)
lp = LogDensityProblems.logdensity(model.logdensity, params)
return UnivariateSliceState(Transition(params, lp, NamedTuple()))
end

function AbstractMCMC.step(
rng::Random.AbstractRNG,
model::AbstractMCMC.LogDensityModel,
Expand Down
2 changes: 1 addition & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ MCMCTesting = "0.3"
Random = "1"
StableRNGs = "1"
Test = "1"
Turing = "0.33, 0.34, 0.35"
Turing = "0.36"
julia = "1.10"
4 changes: 1 addition & 3 deletions test/turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@
]
sample(
model,
Turing.Experimental.Gibbs((
s=externalsampler(sampler), m=externalsampler(sampler)
),),
Turing.Gibbs(:s => externalsampler(sampler), :m => externalsampler(sampler)),
n_samples;
progress=false,
)
Expand Down

2 comments on commit 08e47db

@Red-Portal
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 register

Release notes:

  • Bump Turing version 0.36

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

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.7.1 -m "<description of version>" 08e47db81d4c91922b33c7bf823f45ab212e0d9c
git push origin v0.7.1

Please sign in to comment.