Resume chkptstanr after starting a new R session

Short summary of the problem

I’m able to run either chkpt_brms or chkpt_stan, interrupt and resume the run. But I want to close the R session and then resume it later, possibly another day.

With chkpt, I can save the step_size, metric file, and init file. But I can’t tell if there is a way to use this info when restarting chkpt_stan in the new. session. Alternatively, I can use them with mod$sample in cmdstanr, but then if I want to interrupt that, the next init file would have to be created by hand - awkward. Also, minor problem, $sample only takes one value of step_size rather then separate values for different chains (as in the chkpt output).

happy to give an example but that isn’t really the point for this question.

thanks

Greg

  • Operating System: Linux Mint 21.2 Victoria
  • brms Version: 2.22.0

Don’t forget to add relevant tags to your topic (top right of this form) especially for application area. Delete this text before posting your question :-) Thx!

Looking forward to your topic!

Tagging @Ven_Popov. If I remember correctly I think he has worked on this package most recently.

thanks - yes, I’m sure he’ll know. It may be something for the future if not currently possible.

Greg

@Ven_Popov

I think this turned out to be trivial. As long as the data, stancode and standata are saved and can be reloaded in the new R session, chkptstanr will pick up where it left off.

example

set.seed(1)
x<-runif(400)
f<-function(t) sin(12t)exp(-3t)
lp<-f(x)
y<-0.7+lp+0.3
rnorm(400)
plot(x,y)

dat<-data.frame(x,y)
bf1<-bf(y ~ s(x))

reset_checkpoints(‘checkpt’, recompile = TRUE)

stanc1<-make_stancode(bf1,data=dat)
stand1<-make_standata(bf1,data=dat)

save(stanc1,stand1,dat,file=“stanc1.txt”)
#load(“stanc1.txt”,verbose=TRUE)

fit1 ← chkpt_stan(model_code = stanc1,
data = stand1,
family = “gaussian”,
iter_adaptation = 1000,
iter_warmup = 100,
iter_per_chkpt = 100,
parallel_chains = 2,
control = list(max_treedepth=15),
path = ‘checkpt’)

stop the run somewhere after the adaptation stage, but in the midst of the checkpoints.
close the R session, stop and restart the machine, navigate to the same directory as before. Then reload the data etc and continue.

load(“stanc1.txt”,verbose=TRUE)

fit1 ← chkpt_stan(model_code = stanc1,
data = stand1,
family = “gaussian”,
iter_adaptation = 1000,
iter_warmup = 100,
iter_per_chkpt = 100,
parallel_chains = 2,
control = list(max_treedepth=15),
path = ‘checkpt’)

ok?

Greg

the blockquote interpreted 3*t as 3t etc