My system had been working perfectly but I am now getting the following error fitting a brms
model (a straightforward linear regression with random effects):
Error in unserialize(socklist[[n]]) : error reading from connection
So I thought I would switch to backend = cmdstanr
, but that results in the following error when fitting the model:
error: PCH file uses an older PCH format that is no longer supported
1 error generated.
make: *** [/var/folders/zs/pfyxhxss4qj914sl77gw12pw0000gn/T/RtmprYGTwR/model-e0501cc26e51] Error 1
Error: An error occured during compilation! See the message above for more information.
In addition: Warning message:
CmdStan's precompiled header (PCH) files may need to be rebuilt.
If your model failed to compile please run rebuild_cmdstan().
If the issue persists please open a bug report.
I then ran, as suggested
cmdstanr::rebuild_cmdstan()
but the error persists.
I don’t know if the socklist error in rstan
and the PCH error in cmdstanr
are related and I am pretty mystified as to why these errors have suddenly appeared. Any suggestions for a fix would be gratefully received.
Operating System: macOS 11.5.2
My colleague is now getting the same socklist errors, so this isn’t just my problem anymore!
Can you run the following:
library(cmdstanr)
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file, force_recompile = TRUE)
# names correspond to the data block in the Stan program
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
fit <- mod$sample(
data = data_list,
seed = 123,
chains = 4,
parallel_chains = 4,
refresh = 500
)
I get the following error directly after the mod <- cmdstan_model
line:
Compiling Stan program...
error: PCH file uses an older PCH format that is no longer supported
1 error generated.
make: *** [/var/folders/zs/pfyxhxss4qj914sl77gw12pw0000gn/T/Rtmp9Dbk1k/model-10422510d6d69] Error 1
Error: An error occured during compilation! See the message above for more information.
In addition: Warning message:
CmdStan's precompiled header (PCH) files may need to be rebuilt.
If your model failed to compile please run rebuild_cmdstan().
If the issue persists please open a bug report.
And if you run cmdstanr::install_cmdstan(overwrite = TRUE, cores = 2)
and run it again you get the exact same issue?
That works! And the brms model (using backend = cmdstanr
), which was previously giving errors, now runs too. Thank you so much.
I still get the socklist error with backend = rstan
, so presumably these two problems were just coincidental. But I wonder what has broken rstan on my and my colleague’s systems?
Yeah, the rstan problem is a different story and has a different cause I am afraid.
There are a few threads on discourse if you search for that error. For example Some models run without problems, but more complex give error: Error in unserialize(socklist[[n]]) : error reading/writing from connection - #9 by di4oi4
Hopefully those would help.
I have seen those errors reported a few times for rstan and Mac and I am afraid I dont have enough knowledge there to help.
2 Likes
The solution for the socklist error using backend = "rstan"
– suggested here Error in unserialize(socklist[[n]]) : error reading from connection - #13 by t-anton – is quite straightforward:
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
This installs a more recent version of rstan than what is available on cran (and hence “seen” by RStudio).