I finally created a simpler case that allowed me to reproduce the error on a more limited scale. While playing with it, I noticed that when I was first removing the precompiled model from the disk (.rds file), and let Stan recompile the model before launching the tasks, the sharing of the compiled model to the different tasks could be done without any error occuring. While when I was reading the precompiled model from disk, the above described error sysmatically happaned.
I think the mistake probably lies in the following piece of code :
0. check that modelScript.stan
exists
stanScriptFile ← paste0(modelScript, “.stan”)
if(!file.exists(stanScriptFile))
stop(paste0(stanScriptFile, " does not exist!"))
1. check if modelScript.rds
exists.
2. if not, compile it. Then save it as rds.
3. if modelScript.rds
exists, make sure it is more recent
than modelScript.stan
.
4 if more recent, load it, otherwise execute step 2
stanModelFile ← paste0(modelScript, “.rds”)
compile ← TRUE
if (file.exists(stanModelFile)){
fileTimes ← file.mtime(c(stanScriptFile, stanModelFile))
if(fileTimes[2] > fileTimes[1])
compile ← FALSE
}
if(compile)
{
cat(paste0("Compiling Stan script : ", stanScriptFile, “\n”))
stanc_ret ← stanc(file = stanScriptFile, verbose = TRUE)
stan_mod <- stan_model(stanc_ret = stanc_ret,
verbose = TRUE,
auto_write = TRUE)
cat("Model compilation successful! Wrighting model on disk...\n")
saveRDS(object = stan_mod, file = stanModelFile)
cat("Done!\n")
} else {
cat(paste0("Found an updated Stan model : ", stanModelFile, “\n”))
cat(“Uploading…”)
stan_mod ← readRDS(file = stanModelFile)
cat(“Done!\n”)
}