[macOS High Sierra, R 4.0, cmdstanr_0.0.0.9005]
After running a model with cmdstanr and saving it, I am sometimes unable to get the draws.
Specifically, I first do the following:
model = cmdstan_mode("my_model.stan")
sf = model$sample(data = datalist)
save(sf, file = "my_fit.Rdata")
Later I load the model again (on the same machine) and try to get the draws:
load("my_fit.Rdata")
sf$draws()
This works usually, but sometimes i get the following error:
Error in read_sample_csv(files = self$output_files(include_failed = FALSE), :
Assertion on ‘output_file’ failed: File does not exist: ‘/var/folders/yj/ws4lqwt13ms_lqg7hjw4jj7r0000gn/T/RtmpHEFQLD/GammaMix_sWK-202006191532-1-82393a.csv’.
I first thought that I had figured it out and that I needed to do something with the draws once before saving the CmdStanModel object in order to get the draws from the csv file into the CmdStanModel object. If one saves the CmdStanModel before doing something with the draws, the resulting .Rdata file is much smaller. But this does not seem to work consistently as I know have .Rdata file from a model that is so large that it should include the draws, but cmdstanr still wants to access the (temporary?) .csv file with the draws. As this file does not exist anymore, I am getting the error message above.
Is this expected behavior, or am I doing something wrong?
(I didn’t find information about saving CmdStanModel objects in the documentation).
Given the way rstan works, I think it would be best if saving a CmdStanModel object would always automatically be saved together with draws and sampler diagnostics.
PS: I also might have updated cmndstanr between saving an loading the CmdStanModel objects. But I am not sure, and I think this should not lead to the problem i see.