Skip to content

Commit 4addb5f

Browse files
authored
Remove Sampler and its interface (#1037)
* Remove `Sampler` and `initialstep` * Actually just remove the entire file * forgot one function * Move sampling test utils to Turing as well * Update changelog to correctly reflect changes
1 parent e4c5bbd commit 4addb5f

File tree

9 files changed

+17
-509
lines changed

9 files changed

+17
-509
lines changed

HISTORY.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ The main change that this is likely to create is for those who are implementing
4242
The exact way in which this happens will be detailed in the Turing.jl changelog when a new release is made.
4343
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.
4444

45+
### Removal of `DynamicPPL.Sampler`
46+
47+
`DynamicPPL.Sampler` and **all associated interface functions** have also been removed entirely.
48+
If you were using these, the corresponding replacements are:
49+
50+
- `DynamicPPL.Sampler(S)`: just don't wrap `S`; but make sure `S` subtypes `AbstractMCMC.AbstractSampler`
51+
- `DynamicPPL.initialstep`: directly implement `AbstractMCMC.step` and `AbstractMCMC.step_warmup` as per the AbstractMCMC interface
52+
- `DynamicPPL.loadstate`: `Turing.loadstate` (will be introduced in the next version)
53+
- `DynamicPPL.default_chain_type`: removed, just use the `chain_type` keyword argument directly
54+
- `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)
55+
- `DynamicPPL.default_varinfo`: `Turing.Inference.default_varinfo` (will be introduced in the next version)
56+
- `DynamicPPL.TestUtils.test_sampler` and related methods: removed, please implement your own testing utilities as needed
57+
4558
### Simplification of the tilde-pipeline
4659

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

5972
### Removal of `resume_from`
6073

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

6477
### Change of output type for `pointwise_logdensities`
6578

docs/src/api.md

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,7 @@ DynamicPPL.TestUtils.AD.ADIncorrectException
243243

244244
## Demo models
245245

246-
DynamicPPL provides several demo models and helpers for testing samplers in the `DynamicPPL.TestUtils` submodule.
247-
248-
```@docs
249-
DynamicPPL.TestUtils.test_sampler
250-
DynamicPPL.TestUtils.test_sampler_on_demo_models
251-
DynamicPPL.TestUtils.test_sampler_continuous
252-
DynamicPPL.TestUtils.marginal_mean_of_samples
253-
```
246+
DynamicPPL provides several demo models in the `DynamicPPL.TestUtils` submodule.
254247

255248
```@docs
256249
DynamicPPL.TestUtils.DEMO_MODELS
@@ -504,27 +497,7 @@ DynamicPPL.AbstractInitStrategy
504497
DynamicPPL.init
505498
```
506499

507-
### Samplers
508-
509-
In DynamicPPL a generic sampler for inference is implemented.
510-
511-
```@docs
512-
Sampler
513-
```
514-
515-
The default implementation of [`Sampler`](@ref) uses the following unexported functions.
516-
517-
```@docs
518-
DynamicPPL.initialstep
519-
DynamicPPL.loadstate
520-
DynamicPPL.init_strategy
521-
```
522-
523-
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`.
524-
525-
```@docs
526-
DynamicPPL.default_varinfo
527-
```
500+
### Choosing a suitable VarInfo
528501

529502
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:
530503

ext/DynamicPPLMCMCChainsExt.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,6 @@ module DynamicPPLMCMCChainsExt
33
using DynamicPPL: DynamicPPL, AbstractPPL
44
using MCMCChains: MCMCChains
55

6-
# Load state from a `Chains`: By convention, it is stored in `:samplerstate` metadata
7-
function DynamicPPL.loadstate(chain::MCMCChains.Chains)
8-
if !haskey(chain.info, :samplerstate)
9-
throw(
10-
ArgumentError(
11-
"The chain object does not contain the final state of the sampler: Metadata `:samplerstate` missing.",
12-
),
13-
)
14-
end
15-
return chain.info[:samplerstate]
16-
end
17-
186
_has_varname_to_symbol(info::NamedTuple{names}) where {names} = :varname_to_symbol in names
197

208
function DynamicPPL.supports_varname_indexing(chain::MCMCChains.Chains)

src/DynamicPPL.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ export AbstractVarInfo,
9292
getargnames,
9393
extract_priors,
9494
values_as_in_model,
95-
# Samplers
96-
Sampler,
9795
# LogDensityFunction
9896
LogDensityFunction,
9997
# Contexts
@@ -128,8 +126,6 @@ export AbstractVarInfo,
128126
prefix,
129127
returned,
130128
to_submodel,
131-
# Chain save/resume
132-
loadstate,
133129
# Convenience macros
134130
@addlogprob!,
135131
value_iterator_from_chain,
@@ -181,7 +177,6 @@ include("contexts/transformation.jl")
181177
include("contexts/prefix.jl")
182178
include("contexts/conditionfix.jl") # Must come after contexts/prefix.jl
183179
include("model.jl")
184-
include("sampler.jl")
185180
include("varname.jl")
186181
include("distribution_wrappers.jl")
187182
include("submodel.jl")

src/sampler.jl

Lines changed: 0 additions & 156 deletions
This file was deleted.

src/test_utils.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ include("test_utils/model_interface.jl")
1717
include("test_utils/models.jl")
1818
include("test_utils/contexts.jl")
1919
include("test_utils/varinfo.jl")
20-
include("test_utils/sampler.jl")
2120
include("test_utils/ad.jl")
2221

2322
end

src/test_utils/sampler.jl

Lines changed: 0 additions & 87 deletions
This file was deleted.

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ include("test_util.jl")
6161
include("varinfo.jl")
6262
include("simple_varinfo.jl")
6363
include("model.jl")
64-
include("sampler.jl")
6564
include("distribution_wrappers.jl")
6665
include("logdensityfunction.jl")
6766
include("linking.jl")

0 commit comments

Comments
 (0)