Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove resume_from #770

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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,6 +1,6 @@
name = "DynamicPPL"
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
version = "0.33.0"
version = "0.34.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
7 changes: 6 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ returned(::Model)

## Utilities

To retrieve the final sampler state from a chain of samples (useful for resuming sampling from a previous point):

```@docs
loadstate
```

It is possible to manually increase (or decrease) the accumulated log density from within a model function.

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

```@docs
DynamicPPL.initialstep
DynamicPPL.loadstate
DynamicPPL.initialsampler
```

Expand Down
1 change: 1 addition & 0 deletions src/DynamicPPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export AbstractVarInfo,
Sampler,
SampleFromPrior,
SampleFromUniform,
loadstate,
# Contexts
SamplingContext,
DefaultContext,
Expand Down
19 changes: 16 additions & 3 deletions src/sampler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@
sampler::Sampler,
N::Integer;
chain_type=default_chain_type(sampler),
resume_from=nothing,
initial_state=loadstate(resume_from),
initial_state=nothing,
kwargs...,
)
if haskey(kwargs, :resume_from)
throw(

Check warning on line 107 in src/sampler.jl

View check run for this annotation

Codecov / codecov/patch

src/sampler.jl#L107

Added line #L107 was not covered by tests
ArgumentError(
"The `resume_from` keyword argument is no longer supported. Please use `initial_state=loadstate(chain)` instead of `resume_from=chain`.",
),
)
end
return AbstractMCMC.mcmcsample(
rng, model, sampler, N; chain_type, initial_state, kwargs...
)
Expand Down Expand Up @@ -135,7 +141,14 @@

Load sampler state from `data`.

By default, `data` is returned.
If `data` isa MCMCChains.Chains object, this attempts to fetch the last state
of the sampler from the metadata stored inside the Chains object. This requires
you to have passed the `save_state=true` keyword argument to the `sample()`
when generating the chain.

This function can be overloaded for specific types of `data` if desired. If
there is no specific implementation for a given type, it falls back to just
returning `data`, i.e. acts as an identity function.
"""
loadstate(data) = data

Expand Down
Loading