Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime error crashes R session on macOS Sonoma (arm64) #1117

Open
ltalluto opened this issue Feb 24, 2024 · 1 comment
Open

Runtime error crashes R session on macOS Sonoma (arm64) #1117

ltalluto opened this issue Feb 24, 2024 · 1 comment

Comments

@ltalluto
Copy link

ltalluto commented Feb 24, 2024

Summary:

Models that contain runtime errors crash my R session across many versions of rstan.

Description:

Any model that contains a runtime error is crashing my R session. Models compile fine. If no runtime errors occur models sample fine in most cases, although I am also experiencing somewhat random crashes. For example using cholesky_decompose will sometimes also produce a crash, this is less reproducible. I have tried the current CRAN versions (2.32.5), development versions
(2.33.1.9000), and have tried downgrading to rstan 2.21.8 with StanHeaders 2.26.28, all of them produce the same crash. My mac is an M1 on Sonoma 14.3.1, R version 4.3.2. An older intel mac on Ventura 13.6.4 has expected behaviour with no crashes. I can confirm that rstan was working normally as of late December, something must have changed since then.

Reproducible Steps:

This code reliably produces a crash on all of the versions mentioned above. Expected output is a runtime error due to the missing 'x' variable in the last line.

library(rstan)
set.seed(123)

stmod = "
data {
	int <lower = 0> n;
	vector [n] x;
}
parameters {
	real mu;
	real <lower = 0> sig;
}
model {
	x ~ normal(mu, sig);
	mu ~ normal(0, 10);
	sig ~ cauchy(0, 5);
}
"


mod = stan_model(model_code = stmod)
samp_works = sampling(mod, data = list(n = 5, x = rnorm(5, 0, 1)), iter = 100, chains = 1)

# missing x in data list, should produce runtime error.
samp_crashes = sampling(mod, data = list(n = 5), iter = 100, chains = 1)

RStan Version:

Tried with 2.33.1.9000, 2.32.5, and 2.21.8.

R Version:

4.3.2

Operating System:

macOS 14.3.1.

@ltalluto
Copy link
Author

Updating to add that I've managed to get it working by switching compilers. My .R/Makevars included the line:

CXX=/opt/local/bin/clang++ -fopenmp

This points to clang 14.0.6 installed via macports. Commenting this line out and reinstalling rstan from source via CRAN eliminates the crashes (using the system C++ compiler).

Leaving this issue open in case you want to investigate the crashes further, but happily resolved on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant