Problem running rstan on Apple M2 Mac

Hi–I just switched from a Mac with intel processors to an M2 silicon Mac with Ventura 13.4.1. Rstan loads, but when I try to run a stan fit that used to work on the intel Mac I see this error:
SAMPLING FOR MODEL ‘lnYield_hier_noncentered_v4’ NOW (CHAIN 1).
SAMPLING FOR MODEL ‘lnYield_hier_noncentered_v4’ NOW (CHAIN 2).
Error in unserialize(socklist[[n]]) : error reading from connection

Additional info on Makevars and session_info is listed below. I believe I created the Makevars file with some content recommended in another post, so maybe that’s part of the problem.
Thanks! Jay

  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
    CXX14FLAGS += -03 -arch arm64 -ftemplate-depth-256
  • Output of devtools::session_info("rstan")
    ─ Session info ────────────────────────────────────────────────────────────────────────────────────
    setting value
    version R version 4.3.1 (2023-06-16)
    os macOS Ventura 13.4.1
    system aarch64, darwin20
    ui RStudio
    language (EN)
    collate en_US.UTF-8
    ctype en_US.UTF-8
    tz America/Los_Angeles
    date 2023-08-03
    rstudio 2023.06.1+524 Mountain Hydrangea (desktop)
    pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)

─ Packages ────────────────────────────────────────────────────────────────────────────────────────
package * version date (UTC) lib source
backports 1.4.1 2021-12-13 [1] CRAN (R 4.3.0)
BH 1.81.0-1 2023-01-22 [1] CRAN (R 4.3.0)
callr 3.7.3 2022-11-02 [1] CRAN (R 4.3.0)
checkmate 2.2.0 2023-04-27 [1] CRAN (R 4.3.0)
cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0)
colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0)
crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0)
desc 1.4.2 2022-09-08 [1] CRAN (R 4.3.0)
fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0)
farver 2.1.1 2022-07-06 [1] CRAN (R 4.3.0)
ggplot2 * 3.4.2 2023-04-03 [1] CRAN (R 4.3.0)
glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.3.0)
gtable 0.3.3 2023-03-21 [1] CRAN (R 4.3.0)
inline 0.3.19 2021-05-31 [1] CRAN (R 4.3.0)
isoband 0.2.7 2022-12-20 [1] CRAN (R 4.3.0)
labeling 0.4.2 2020-10-20 [1] CRAN (R 4.3.0)
lattice * 0.21-8 2023-04-05 [1] CRAN (R 4.3.1)
lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0)
loo 2.6.0 2023-03-31 [1] CRAN (R 4.3.0)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0)
MASS 7.3-60 2023-05-04 [1] CRAN (R 4.3.1)
Matrix 1.5-4.1 2023-05-18 [1] CRAN (R 4.3.1)
matrixStats 1.0.0 2023-06-02 [1] CRAN (R 4.3.0)
mgcv 1.8-42 2023-03-02 [1] CRAN (R 4.3.1)
munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0)
nlme 3.1-162 2023-01-31 [1] CRAN (R 4.3.1)
pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0)
pkgbuild 1.4.1 2023-06-14 [1] CRAN (R 4.3.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0)
prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.3.0)
processx 3.8.1 2023-04-18 [1] CRAN (R 4.3.0)
ps 1.7.5 2023-04-18 [1] CRAN (R 4.3.0)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0)
RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.3.0)
Rcpp * 1.0.10 2023-01-22 [1] CRAN (R 4.3.0)
RcppEigen 0.3.3.9.3 2022-11-05 [1] CRAN (R 4.3.0)
RcppParallel 5.1.7 2023-02-27 [1] CRAN (R 4.3.0)
rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0)
rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.3.0)
rstan * 2.21.8 2023-01-17 [1] CRAN (R 4.3.0)
scales 1.2.1 2022-08-20 [1] CRAN (R 4.3.0)
StanHeaders * 2.26.26 2023-05-30 [1] CRAN (R 4.3.0)
tibble * 3.2.1 2023-03-20 [1] CRAN (R 4.3.0)
utf8 1.2.3 2023-01-31 [1] CRAN (R 4.3.0)
vctrs 0.6.2 2023-04-19 [1] CRAN (R 4.3.0)
viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.3.0)
withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0)

[1] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library

Can you post the output from running:

example(stan_model, package="rstan", run.dontrun=T)

Error in compileCode(f, code, language = language, verbose = verbose) :
using C++ compiler: ‘Apple clang version 14.0.3 (clang-1403.0.22.14.1)’using C++14using SDK: ‘MacOSX13.3.sdk’clang: error: unknown argument: '-03’make: *** [file100c87f48822e.o] Error 1

That indicates that the error is due to your Makevars. You’ve specified -03 instead of -O3 (i.e., it should be a capital O, not a zero)

I changed the Makevars file and example(stan_model, package="rstan", run.dontrun=T) now runs properly. However, when I try to run my model, I still get the same error. It occurs after sampling for the second chain starts (as shown in initial post)–could that be a clue?

If the example model runs, but not your model, then that indicates an issue with your model specifically.

Are any errors reported if you run the model with only 1 chain?

Finally resolved this by following this post (response to someone else with the same issue, see https://discourse.mc-stan.org/t/error-in-unserialize-socklist-n-error-reading-from-connection/31692): https://discourse.mc-stan.org/t/installing-rstan/20743/2

1 Like