Skip to content

Resume interface #566

@trappmartin

Description

@trappmartin

Currently, we have two different ways to resume a sampling process.

@model gdemo(x) = begin
  s ~ InverseGamma(2,3)
  m ~ Normal(0, sqrt(s))
  x[1] ~ Normal(m, sqrt(s))
  x[2] ~ Normal(m, sqrt(s))
  return s, m
end
chn1 = sample(gdemo([1.5, 2.0]), sampler; save_state=true)

# version 1
resume(chn1, 1000)

# version 2
sample(gdemo([1.5, 2.0]), sampler; resume_from=chn1)

where the resume function is basically an alias for the second version.

One drawback of the current approach is that we need to store the model function, sampler and further information inside the Chains type.

save!(c::Chain, spl::Sampler, model::Function, vi) = begin
c.info[:spl] = spl
c.info[:model] = model
c.info[:vi] = deepcopy(vi)
end

From my point of view, resuming a sampling process should no restrict the user to a particular sampler but rather to a class of samplers. If I understand the HMC code on this correctly, we currently discard the selected HMC algorithm if we resume a sampling.

spl = reuse_spl_n > 0 ?
resume_from.info[:spl] :
Sampler(alg, adapt_conf)

Question 1: Would it be better to store only the type of the sampler or do we want to keep the sampler as a whole and instead adjust the code base so that we do not discard the user specified algorithm? Keeping the sampler would have the advantage that we can resume with exactly the same parameters.

Question 2: Is there a way that we can drop the VarInfo instance? Many fields can be recovered from the Chains type while others, e.g.

rvs :: Dict{Union{VarName,Vector{VarName}},Any}
dists :: Vector{Distributions.Distribution}
gids :: Vector{Int}
are not recoverable unless we adjust the Chains type. I feel we should think about a refactoring of this.

cc: @yebai @xukai92

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions