Skip to content
Merged
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
17 changes: 15 additions & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ 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`: removed, just use the `chain_type` keyword argument directly
- `DynamicPPL.initialsampler`: `Turing.Inference.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.Inference.default_varinfo` (will be introduced in the next version)
- `DynamicPPL.TestUtils.test_sampler` and related methods: removed, please implement your own testing utilities as needed

### 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 All @@ -58,8 +71,8 @@ The only flag other than `"del"` that `Metadata` ever used was `"trans"`. Thus t

### Removal of `resume_from`

The `resume_from=chn` keyword argument to `sample` has been removed; please use `initial_state=DynamicPPL.loadstate(chn)` instead.
`loadstate` is exported from DynamicPPL.
The `resume_from=chn` keyword argument to `sample` has been removed; please use the `initial_state` argument instead.
`loadstate` will be exported from Turing in the next release of Turing.

### Change of output type for `pointwise_logdensities`

Expand Down
31 changes: 2 additions & 29 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,7 @@ DynamicPPL.TestUtils.AD.ADIncorrectException

## Demo models

DynamicPPL provides several demo models and helpers for testing samplers in the `DynamicPPL.TestUtils` submodule.

```@docs
DynamicPPL.TestUtils.test_sampler
DynamicPPL.TestUtils.test_sampler_on_demo_models
DynamicPPL.TestUtils.test_sampler_continuous
DynamicPPL.TestUtils.marginal_mean_of_samples
```
DynamicPPL provides several demo models in the `DynamicPPL.TestUtils` submodule.

```@docs
DynamicPPL.TestUtils.DEMO_MODELS
Expand Down Expand Up @@ -504,27 +497,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 src/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ include("test_utils/model_interface.jl")
include("test_utils/models.jl")
include("test_utils/contexts.jl")
include("test_utils/varinfo.jl")
include("test_utils/sampler.jl")
include("test_utils/ad.jl")

end
87 changes: 0 additions & 87 deletions src/test_utils/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