Hello, I just upgraded my computer (MacBook Air M1 2020) to a more powerful one (MacBook Air M3 with additional RAM), and started to re-use RStan. To my surprise, Stan is extremely slow, both for starting models and completing fits.
All the models I tried had been tested with Stan on my previous computer and could be run very smoothly, yet they all look completely bugged on my new machine. Besides, I noticed that when the models get stuck, that I interrupt the fit and start coding other things on my R, indications of chain progression continue to pop up in the console even minutes after, and despite the fact that the fit is interrupted and that I am able to run other codes.
In one of my attempted fits, a specific error message accompanied the chains that reached 100 % during this after-break progression . The message read:
"Error in serialize(data, node$con, xdr = FALSE) : ignoring SIGPIPE signal
Calls: <Anonymous> ... doTryCatch -> sendData -> sendData.SOCK0node -> serialize
Execution halted"
Something is clearly wrong with rstan on my new computer. This could be a problem of dependencies, but I donβt see where it comes from. Any help would be greatly appreciated.
One example model
data {
int<lower=0> N;
vector[N] Cd_beans;
vector[N] Cd_disp;
}
parameters {
real <lower=0, upper=8> Cd_lim;
real <lower=0, upper=1.5> Cd_aff;
real<lower=0, upper=5> sigma_Cd;
}
transformed parameters {
vector[N] mu;
for (i in 1:N) {
mu[i] = Cd_lim * Cd_disp[i] / (Cd_aff + Cd_disp[i]);
}
}
model {
Cd_beans ~ normal(mu, sigma_Cd);
Cd_lim ~ normal(4, 2);
Cd_aff ~ normal(0.5, 0.5);
sigma_Cd ~ lognormal(0.5, 1);
}
Running the example model
Note: the Stan file containing the model presented above is called β240415_MM_raw.stanβ and is located in a folder called βstan_filesβ in the working directory
library(rstan)
library(shinystan)
fit_stan <- function(dict_mod, stan_file, stan_fold='stan_files') {
options(mc.cores=parallel::detectCores())
path_stan <- paste(stan_fold, paste0(stan_file, '.stan'), sep='/')
mod <- stan(file=path_stan, data=dict_mod, cores=getOption("mc.cores", 1L))
dict_stan_res <- dict_mod
dict_stan_res[['fit']] <- mod
dict_stan_res[['model']] <- stan_file
return(dict_stan_res)
}
dict_stan_res_MM <- fit_stan(dict_mod=dict_mod, stan_file="240415_MM_raw", stan_fold='stan_files')
Code for data simulation
I attach here a simple code that allows to create theoretical data that can immediately be used to launch the model. That being said, I am convinced that the problem doesnβt come from the model (it was rolling perfectly on my former computer). The only thing I can see is that I have some missing dependencies, which I donβt find.
create_MM_data <- function(N, L, K) {
soil_vect <- runif(n=N, min=0, max=1)
err_vect <- rnorm(n=N, mean=0, sd=1)
bean_vect <- apply(X=data.frame(soil_vect), FUN=function(x) {L*x/(x+K)}, MARGIN=1) + err_vect
dict_mod <- list("N"=N, "Cd_disp"=soil_vect, "Cd_beans"=bean_vect)
return(dict_mod)
}
dict_mod <- create_MM_data(N=456, L=4, K=0.7)
Operating system and R information
My operating system is macOS Sonoma 14.5 (working on a MacBook Air M3), my version of RStan is the 2.32.6.
The output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
is:
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file '/Users/lasbatsbaptiste/.R/Makevars': No such file or directory
The output of devtools::session_info(βrstanβ) is:
β Session info ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
setting value
version R version 4.4.1 (2024-06-14)
os macOS Sonoma 14.5
system aarch64, darwin20
ui RStudio
language (EN)
collate en_US.UTF-8
ctype en_US.UTF-8
tz America/Toronto
date 2024-10-11
rstudio 2024.09.0+375 Cranberry Hibiscus (desktop)
pandoc 3.2 @ /private/var/folders/gg/dbn8ywtd5gg8slf5l5qjtsdh0000gn/T/AppTranslocation/453D0071-7BE9-47E0-99BB-BAC19D25AA55/d/RStudio.app/Contents/Resources/app/quarto/bin/tools/aarch64/ (via rmarkdown)
β Packages ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
package * version date (UTC) lib source
abind 1.4-8 2024-09-12 [1] CRAN (R 4.4.1)
backports 1.5.0 2024-05-23 [1] CRAN (R 4.4.0)
BH 1.84.0-0 2024-01-10 [1] CRAN (R 4.4.0)
callr 3.7.6 2024-03-25 [1] CRAN (R 4.4.0)
checkmate 2.3.2 2024-07-29 [1] CRAN (R 4.4.0)
cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.0)
colorspace 2.1-1 2024-07-26 [1] CRAN (R 4.4.0)
desc 1.4.3 2023-12-10 [1] CRAN (R 4.4.0)
distributional 0.5.0 2024-09-17 [1] CRAN (R 4.4.1)
fansi 1.0.6 2023-12-08 [1] CRAN (R 4.4.0)
farver 2.1.2 2024-05-13 [1] CRAN (R 4.4.0)
generics 0.1.3 2022-07-05 [1] CRAN (R 4.4.0)
ggplot2 3.5.1 2024-04-23 [1] CRAN (R 4.4.0)
glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.1)
gridExtra 2.3 2017-09-09 [1] CRAN (R 4.4.0)
gtable 0.3.5 2024-04-22 [1] CRAN (R 4.4.0)
inline 0.3.19 2021-05-31 [1] CRAN (R 4.4.0)
isoband 0.2.7 2022-12-20 [1] CRAN (R 4.4.0)
labeling 0.4.3 2023-08-29 [1] CRAN (R 4.4.0)
lattice 0.22-6 2024-03-20 [1] CRAN (R 4.4.1)
lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0)
loo 2.8.0 2024-07-03 [1] CRAN (R 4.4.0)
magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0)
MASS 7.3-60.2 2024-04-26 [1] CRAN (R 4.4.1)
Matrix 1.7-0 2024-04-26 [1] CRAN (R 4.4.1)
matrixStats 1.4.1 2024-09-08 [1] CRAN (R 4.4.1)
mgcv 1.9-1 2023-12-21 [1] CRAN (R 4.4.1)
munsell 0.5.1 2024-04-01 [1] CRAN (R 4.4.0)
nlme 3.1-164 2023-11-27 [1] CRAN (R 4.4.1)
numDeriv 2016.8-1.1 2019-06-06 [1] CRAN (R 4.4.0)
pillar 1.9.0 2023-03-22 [1] CRAN (R 4.4.0)
pkgbuild 1.4.4 2024-03-17 [1] CRAN (R 4.4.0)
pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0)
posterior 1.6.0 2024-07-03 [1] CRAN (R 4.4.0)
processx 3.8.4 2024-03-16 [1] CRAN (R 4.4.0)
ps 1.8.0 2024-09-12 [1] CRAN (R 4.4.1)
QuickJSR 1.4.0 2024-10-01 [1] CRAN (R 4.4.1)
R6 2.5.1 2021-08-19 [1] CRAN (R 4.4.0)
RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.4.0)
Rcpp 1.0.13 2024-07-17 [1] CRAN (R 4.4.0)
RcppEigen 0.3.4.0.2 2024-08-24 [1] CRAN (R 4.4.1)
RcppParallel 5.1.9 2024-08-19 [1] CRAN (R 4.4.1)
rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.0)
rstan * 2.32.6 2024-03-05 [1] CRAN (R 4.4.0)
scales 1.3.0 2023-11-28 [1] CRAN (R 4.4.0)
StanHeaders * 2.32.10 2024-07-15 [1] CRAN (R 4.4.0)
tensorA 0.36.2.1 2023-12-13 [1] CRAN (R 4.4.0)
tibble 3.2.1 2023-03-20 [1] CRAN (R 4.4.0)
utf8 1.2.4 2023-10-22 [1] CRAN (R 4.4.0)
vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0)
viridisLite 0.4.2 2023-05-02 [1] CRAN (R 4.4.0)
withr 3.0.1 2024-07-31 [1] CRAN (R 4.4.0)
[1] /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
This problem is quite blocking for me, looking forward for any help.
Thanks!