You might try -mtune=corei7 -march=corei7 instead.
Thanks, I tried both ways, both worked, thanks!
My problem solved by Guoqing_Wangās approach too. Thanks!
Iām getting a very similar problem, though am on linux.
Iām fitting a joint model with rstanarm::stan_jm.
Generally, it works with 1 core and 1 chain, but otherwise I get the āunserializeā error listed above.
Both the stan and parallel example code given above work fine.
I can also implement other parallel procedures (like bootstrap) without a problem.
Have tried chaging the C++ flags in the .R/Makevars as suggested, but it doesnāt seem to help. Any other thoughts to diagnose the issue differently on ubuntu?
R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
This sounds more like the problem of trying to store too much. When you do 1 chain, what is dim(post$stanfit) where post is what is produced by stan_jm?
[1] 1000 1 9371
Hi, @bgoodri,
I seem to have the same issue as @itpetersen described - when I try to fit a model with brms it generates the error.
I ran
example(stan_model, package = "rstan", run.dontrun = TRUE)
to produce output.txt (29.6 KB)
I donāt see any errors there, but maybe Iām missing something.
If I run with one chain, I also get the same crashing of the R session.
Iāve tried without -march and -mtune, changing native to corei7, things currently back to square one at:
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7
Any further clues or help gratefully received.
I am not an expert but I hope I can help by sharing my findings about it.
I had same error last week and for me it was due to trying to store a very large stanfit as pointed out by Ben in the post above. It would be helpful if you could also share your platform details (you can run sessionInfo()) and the output of dim(post$stanfit)
Hi @sam_learner, thanks for the quick response - it does indeed just seem to be a memory issue in the end, so today I managed to get it to run by playing with the memory allocations in R. Thanks though.
Hi, Iām a brms user on Mac (11.6 BigSur, MacBook Pro 2019), I donāt have much experience with Stan directly or with c++ compilers. Everything used to work fine on my machine, but now I updated to R 4.1.1, and when I now run brm, I get the error: Error in unserialize(socklist[[n]]) : error reading from connection (this is when I set ācores = 4ā). When I set ācores = 1ā, then R crashes upon calling brm().
To deal with the problem, I have re-installed my mac os c++ toolchain using this description:
The installer suggested here:
does not work on my machine, it crashes.
Unfortunately, I canāt read/understand the code in Makevars. Currently, I have this deleted (I tried different versions described above without success).
When I execute
example(stan_model, package = ārstanā, run.dontrun = TRUE)
everything seems fine and I donāt see any errors
stan_example_code_output.txt (8.7 KB)
.
However, running brm doesnāt work. The solutions suggested above did not work for me.
Any help is much appreciated, I really need brms for my daily work.
sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] de_DE.UTF-8/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] brms_2.16.3 Rcpp_1.0.7 designr_0.1.12
=======================================
R-Code that generates the errors on my machine:
library(designr)
library(brms)
example(stan_model, package = ārstanā, run.dontrun = TRUE)
no error
Create latin-square design
design ā
fixed.factor(āXā, levels=c(āX1ā, āX2ā)) +
random.factor(āsubjā, instances=21) +
random.factor(āitemā, instances= 8) +
random.factor(c(āsubjā, āitemā), groups=c(āXā))
dat ā design.codes(design)
(contrasts(dat$X) ā c(+1, -1))
dat$so ā model.matrix(~X,dat)[,2]
simulate data
dat$ysim ā exp(simLMM(form = ~ 1 + so + (1 + so | subj) + (1 + so | item),
data = dat,
Fixef = c(6, 0.12),
VC_sd = list(sj=c(0.32, 0.22), it=c(0.04, 0.09), resid=0.31),
CP = 0.6,
empirical = TRUE, verbose=TRUE))
priors ā c( set_prior(ānormal(6, 0.6)ā, class = āInterceptā),
set_prior(ānormal(0.12, 0.04)ā, class = ābā, coef = āsoā),
set_prior(ānormal(0, 0.1)ā, class = āsdā),
set_prior(ānormal(0, 0.5)ā, class = āsigmaā),
set_prior(ālkj(2)ā, class = ācorā) )
brm1 ā brm(ysim ~ so + (so|subj) + (so|item), dat,
family=lognormal(), prior=priors, cores=4,
save_pars = save_pars(all = TRUE),
warmup=2000, iter=10000,
control=list(adapt_delta=0.99, max_treedepth=15))
Ok, installing the development version of rstan solved the problem; see here:
Thanks, this solved a similar issue for me with rstan trying to adjust the max_threedepth on my mac (BigSur) laptop!
Iām going to lock this thread since itās getting a bit overlong. If anyone has a similar issue in the future, please feel free to open a new topic