Skip to content

Commit ebe0661

Browse files
committed
Improve loadstate implementation
1 parent 39e4d28 commit ebe0661

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/mcmc/abstractmcmc.jl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,16 @@ function AbstractMCMC.sample(
136136
)
137137
end
138138

139-
loadstate(c::MCMCChains.Chains) = c.info.samplerstate
139+
function loadstate(chain::MCMCChains.Chains)
140+
if !haskey(chain.info, :samplerstate)
141+
throw(
142+
ArgumentError(
143+
"the chain object does not contain the final state of the sampler; to save the final state you must sample with `save_state=true`",
144+
),
145+
)
146+
end
147+
return chain.info[:samplerstate]
148+
end
140149

141150
# TODO(penelopeysm): Remove initialstep and generalise MCMC sampling procedures
142151
function initialstep end

0 commit comments

Comments
 (0)