Bug related to auto_write?

I’m getting some errors running a number of brms models in parallel, I think because more than one of the “workers” is trying to write the compiled model out to the same file. (The error is with writeRDS, and none of my code uses writeRDS). I tried setting options(auto_write = FALSE), and that didn’t seem to help. I then dug into the code for stan_model, and it looks like the compiled model object gets written out to the temp directory whenever auto_write = FALSE. See line 182 here:

@bgoodri, am I reading this wrong, or is it a bug?

You are reading it right. But I don’t understand why brms would be writing the same file to the same filename at the same time. It should either write it once and do like 4 chains in parallel. Or if you are calling brms in parallel, you should compile it once and call update in parallel.

Thanks for confirming the bug.

I am calling brms in parallel, so you’re right I probably should be compiling the model once and using update. For these models the compile time is insignificant relative to the sampling time, so I didn’t bother, but I’ll keep this in mind in the future because it sounds like a simple fix.