Skip to content

Commit a0e6f32

Browse files
committed
Remove resume_from argument
1 parent 003ff2f commit a0e6f32

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.33.0"
3+
version = "0.34.0"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

docs/src/api.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,12 @@ returned(::Model)
134134

135135
## Utilities
136136

137+
To retrieve the final sampler state from a chain of samples (useful for resuming sampling from a previous point):
138+
139+
```@docs
140+
loadstate
141+
```
142+
137143
It is possible to manually increase (or decrease) the accumulated log density from within a model function.
138144

139145
```@docs
@@ -425,7 +431,6 @@ The default implementation of [`Sampler`](@ref) uses the following unexported fu
425431

426432
```@docs
427433
DynamicPPL.initialstep
428-
DynamicPPL.loadstate
429434
DynamicPPL.initialsampler
430435
```
431436

src/DynamicPPL.jl

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export AbstractVarInfo,
9292
Sampler,
9393
SampleFromPrior,
9494
SampleFromUniform,
95+
loadstate,
9596
# Contexts
9697
SamplingContext,
9798
DefaultContext,

src/sampler.jl

+16-3
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ function AbstractMCMC.sample(
100100
sampler::Sampler,
101101
N::Integer;
102102
chain_type=default_chain_type(sampler),
103-
resume_from=nothing,
104-
initial_state=loadstate(resume_from),
103+
initial_state=nothing,
105104
kwargs...,
106105
)
106+
if haskey(kwargs, :resume_from)
107+
throw(
108+
ArgumentError(
109+
"The `resume_from` keyword argument is no longer supported. Please use `initial_state=loadstate(chain)` instead of `resume_from=chain`.",
110+
),
111+
)
112+
end
107113
return AbstractMCMC.mcmcsample(
108114
rng, model, sampler, N; chain_type, initial_state, kwargs...
109115
)
@@ -135,7 +141,14 @@ end
135141
136142
Load sampler state from `data`.
137143
138-
By default, `data` is returned.
144+
If `data` isa MCMCChains.Chains object, this attempts to fetch the last state
145+
of the sampler from the metadata stored inside the Chains object. This requires
146+
you to have passed the `save_state=true` keyword argument to the `sample()`
147+
when generating the chain.
148+
149+
This function can be overloaded for specific types of `data` if desired. If
150+
there is no specific implementation for a given type, it falls back to just
151+
returning `data`, i.e. acts as an identity function.
139152
"""
140153
loadstate(data) = data
141154

0 commit comments

Comments
 (0)