Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ The main change that this is likely to create is for those who are implementing
The exact way in which this happens will be detailed in the Turing.jl changelog when a new release is made.
Broadly speaking, though, `SamplingContext(MySampler())` will be removed so if your sampler needs custom behaviour with the tilde-pipeline you will likely have to define your own context.

### Removal of `DynamicPPL.Sampler`

`DynamicPPL.Sampler` and **all associated interface functions** have also been removed entirely.
If you were using these, the corresponding replacements are:

- `DynamicPPL.Sampler(S)`: just don't wrap `S`; but make sure `S` subtypes `AbstractMCMC.AbstractSampler`
- `DynamicPPL.initialstep`: directly implement `AbstractMCMC.step` and `AbstractMCMC.step_warmup` as per the AbstractMCMC interface
- `DynamicPPL.loadstate`: `Turing.loadstate` (will be introduced in the next version)
- `DynamicPPL.default_chain_type`: `Turing.default_chain_type` (will be introduced in the next version)
- `DynamicPPL.initialsampler`: `Turing.init_strategy` (will be introduced in the next version; note that this function must return an `AbstractInitStrategy`, see above for explanation)
- `DynamicPPL.default_varinfo`: `Turing.default_varinfo` (will be introduced in the next version)

### Simplification of the tilde-pipeline

There are now only two functions in the tilde-pipeline that need to be overloaded to change the behaviour of tilde-statements, namely, `tilde_assume!!` and `tilde_observe!!`.
Expand Down
22 changes: 1 addition & 21 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,27 +504,7 @@ DynamicPPL.AbstractInitStrategy
DynamicPPL.init
```

### Samplers

In DynamicPPL a generic sampler for inference is implemented.

```@docs
Sampler
```

The default implementation of [`Sampler`](@ref) uses the following unexported functions.

```@docs
DynamicPPL.initialstep
DynamicPPL.loadstate
DynamicPPL.init_strategy
```

Finally, to specify which varinfo type a [`Sampler`](@ref) should use for a given [`Model`](@ref), this is specified by [`DynamicPPL.default_varinfo`](@ref) and can thus be overloaded for each `model`-`sampler` combination. This can be useful in cases where one has explicit knowledge that one type of varinfo will be more performant for the given `model` and `sampler`.

```@docs
DynamicPPL.default_varinfo
```
### Choosing a suitable VarInfo

There is also the _experimental_ [`DynamicPPL.Experimental.determine_suitable_varinfo`](@ref), which uses static checking via [JET.jl](https://github.com/aviatesk/JET.jl) to determine whether one should use [`DynamicPPL.typed_varinfo`](@ref) or [`DynamicPPL.untyped_varinfo`](@ref), depending on which supports the model:

Expand Down
12 changes: 0 additions & 12 deletions ext/DynamicPPLMCMCChainsExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ module DynamicPPLMCMCChainsExt
using DynamicPPL: DynamicPPL, AbstractPPL
using MCMCChains: MCMCChains

# Load state from a `Chains`: By convention, it is stored in `:samplerstate` metadata
function DynamicPPL.loadstate(chain::MCMCChains.Chains)
if !haskey(chain.info, :samplerstate)
throw(
ArgumentError(
"The chain object does not contain the final state of the sampler: Metadata `:samplerstate` missing.",
),
)
end
return chain.info[:samplerstate]
end

_has_varname_to_symbol(info::NamedTuple{names}) where {names} = :varname_to_symbol in names

function DynamicPPL.supports_varname_indexing(chain::MCMCChains.Chains)
Expand Down
5 changes: 0 additions & 5 deletions src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export AbstractVarInfo,
getargnames,
extract_priors,
values_as_in_model,
# Samplers
Sampler,
# LogDensityFunction
LogDensityFunction,
# Contexts
Expand Down Expand Up @@ -128,8 +126,6 @@ export AbstractVarInfo,
prefix,
returned,
to_submodel,
# Chain save/resume
loadstate,
# Convenience macros
@addlogprob!,
value_iterator_from_chain,
Expand Down Expand Up @@ -181,7 +177,6 @@ include("contexts/transformation.jl")
include("contexts/prefix.jl")
include("contexts/conditionfix.jl") # Must come after contexts/prefix.jl
include("model.jl")
include("sampler.jl")
include("varname.jl")
include("distribution_wrappers.jl")
include("submodel.jl")
Expand Down
156 changes: 0 additions & 156 deletions src/sampler.jl

This file was deleted.

1 change: 0 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ include("test_util.jl")
include("varinfo.jl")
include("simple_varinfo.jl")
include("model.jl")
include("sampler.jl")
include("distribution_wrappers.jl")
include("logdensityfunction.jl")
include("linking.jl")
Expand Down
Loading
Loading