Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Distributions = "0.25"
LinearAlgebra = "1"
LogDensityProblems = "2"
Random = "1"
Turing = "0.39.5"
Turing = "0.39.5, 0.40"
julia = "1.10"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ Random = "1"
SliceSampling = "0.7.1"
StableRNGs = "1"
Statistics = "1"
Turing = "0.37, 0.38, 0.39"
Turing = "0.37, 0.38, 0.39, 0.40"
julia = "1.10"
18 changes: 8 additions & 10 deletions ext/SliceSamplingTuringExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,13 @@ const SliceSamplingStates = Union{
function Turing.Inference.getparams(::Turing.DynamicPPL.Model, sample::SliceSamplingStates)
return sample.transition.params
end

function Turing.Inference.getlogp_external(
::Turing.DynamicPPL.Model, t::SliceSampling.Transition, state
)
return t.lp
end
# end

function SliceSampling.initial_sample(rng::Random.AbstractRNG, ℓ::Turing.LogDensityFunction)
model = ℓ.model
vi = Turing.DynamicPPL.VarInfo(rng, model, Turing.SampleFromUniform())
vi_spl = last(Turing.DynamicPPL.evaluate!!(model, rng, vi, Turing.SampleFromUniform()))
θ = vi_spl[:]
vi_spl = last(Turing.DynamicPPL.evaluate_and_sample!!(rng, model, vi, Turing.SampleFromUniform()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this will only work on DynamicPPL 0.37, so only Turing 0.40, so I think it might be better to restrict the compat to only 0.40.

Alternatively to be explicit you could make both Turing and DynamicPPL triggers for the Turing extension, then that way you can control both compat entries. I think that's the best way although it is a bit of boilerplate.

Otherwise LGTM :)

Copy link
Member Author

@Red-Portal Red-Portal Aug 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. Hmm let me just restrict to Turing 0.40 to keep things simple. Thanks for taking a look!

θ = vi_spl[:]

init_attempt_count = 1
while !all(isfinite.(θ))
Expand All @@ -53,8 +47,12 @@ function SliceSampling.initial_sample(rng::Random.AbstractRNG, ℓ::Turing.LogDe
end

# NOTE: This will sample in the unconstrained space.
vi_spl = last(Turing.DynamicPPL.evaluate!!(model, rng, vi, Turing.SampleFromUniform()))
θ = vi_spl[:]
vi_spl = last(
Turing.DynamicPPL.evaluate_and_sample!!(
rng, model, vi, Turing.SampleFromUniform()
),
)
θ = vi_spl[:]

init_attempt_count += 1
end
Expand Down
2 changes: 1 addition & 1 deletion src/SliceSampling.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ls

module SliceSampling

using AbstractMCMC
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.37, 0.38, 0.39"
Turing = "0.37, 0.38, 0.39, 0.40"
julia = "1.10"
Loading