Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
@@ -1,7 +1,7 @@
name = "AdvancedPS"
uuid = "576499cb-2369-40b2-a588-c64705576edc"
authors = ["TuringLang"]
version = "0.7.1"
version = "0.7.2"

[deps]
AbstractMCMC = "80f14c24-f653-4e6a-9b94-39d6b0f70001"
Expand Down
29 changes: 26 additions & 3 deletions ext/AdvancedPSLibtaskExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,31 @@ function AdvancedPS.LibtaskModel(
) # Changed the API, need to take care of the RNG properly
return AdvancedPS.LibtaskModel(f, Libtask.TapedTask(TapedGlobals(rng), f, args...))
end
# TODO: Upstream this to Turing
function AdvancedPS.LibtaskModel(
f::AdvancedPS.AbstractTuringLibtaskModel, rng::Random.AbstractRNG
)
return AdvancedPS.LibtaskModel(
f, Libtask.TapedTask(TapedGlobals(rng), f.fargs...; f.kwargs...)
)
end

const LibtaskTrace{R} = AdvancedPS.Trace{<:AdvancedPS.LibtaskModel,R}

function to_tapedtask(
newf::AdvancedPS.AbstractGenericModel, trace::LibtaskTrace, rng::Random.AbstractRNG
)
return Libtask.TapedTask(TapedGlobals(rng, get_other_global(trace)), newf)
end
function to_tapedtask(
newf::AdvancedPS.AbstractTuringLibtaskModel,
trace::LibtaskTrace,
rng::Random.AbstractRNG,
)
return Libtask.TapedTask(
TapedGlobals(rng, get_other_global(trace)), newf.fargs...; newf.kwargs...
)
end

"""
copy(model::AdvancedPS.LibtaskModel)
Expand All @@ -47,8 +72,6 @@ function Base.copy(model::AdvancedPS.LibtaskModel)
return AdvancedPS.LibtaskModel(deepcopy(model.f), copy(model.ctask))
end

const LibtaskTrace{R} = AdvancedPS.Trace{<:AdvancedPS.LibtaskModel,R}

function Base.copy(trace::LibtaskTrace)
newtrace = AdvancedPS.Trace(copy(trace.model), deepcopy(trace.rng))
set_other_global!(newtrace, newtrace)
Expand Down Expand Up @@ -114,7 +137,7 @@ function AdvancedPS.forkr(trace::LibtaskTrace)
newf = AdvancedPS.reset_model(trace.model.f)
Random123.set_counter!(rng, 1)

ctask = Libtask.TapedTask(TapedGlobals(rng, get_other_global(trace)), newf)
ctask = to_tapedtask(newf, trace, rng)
new_tapedmodel = AdvancedPS.LibtaskModel(newf, ctask)

# add backward reference
Expand Down
4 changes: 4 additions & 0 deletions src/AdvancedPS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ abstract type AbstractParticleSampler <: AbstractMCMC.AbstractSampler end
abstract type AbstractStateSpaceModel <: AbstractParticleModel end
abstract type AbstractGenericModel <: AbstractParticleModel end

# TODO(penelopeysm): This should be upstreamed to Turing together with anything that is
# Turing-specific in LibtaskExt.
abstract type AbstractTuringLibtaskModel <: AbstractGenericModel end

include("resampling.jl")
include("rng.jl")
include("model.jl")
Expand Down
Loading