stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 267 forks source link

"The NEXT version of Stan will not be able to pre-process your Stan program." #818

Open christineymshen opened 4 years ago

christineymshen commented 4 years ago

Summary:

I re-installed my rstan package earlier today, and warning msg starts to show up, and also some models that used to work ok now cannot be run.

Description:

After re-installing rstan, I followed the start guide and checked the following:

pkgbuild::has_build_tools(debug = TRUE)

Somehow it showed FALSE. So I further installed the C++ toolchain using the macOS R toolchain installer.

Now whenever I need to do model fit, I see this message

sh: clang++ -mmacosx-version-min=10.13: command not found The NEXT version of Stan will not be able to pre-process your Stan program. Please open an issue at https://github.com/stan-dev/stanc3/issues if you can share or at least describe your Stan program. This will help ensure that Stan continues to work on your Stan programs in the future. Thank you! This message can be avoided by wrapping your function call inside suppressMessages(). Error in FUN(X[[i]], ...) : trying to get slot "mode" from an object of a basic class ("NULL") with no slots

And it's usually accompanied with this error msg:

Warning messages: 1: In system2(CXX, args = ARGS) : error in running command 2: In file.remove(c(unprocessed, processed)) : cannot remove file '/var/folders/fr/b4bvkc_11vj3ntd1r6859x5m0000gn/T//RtmpjkdCOb/file13be45025d82.stan', reason 'No such file or directory'

Sometimes the model can run. Sometimes it failed (whereas previously works ok). And when it fails, in addition to the previous msg, I also got the following one:

3: In mccollect(jobs) : 2 parallel jobs did not deliver results

Reproducible

Here's the codes I was using where it fails to run:

stan file (filename:lab-02-nopool.stan) :

data { 
  int<lower=0> n;           // items 
  int<lower=0> N[n];        // initial trials 
  int<lower=0> y[n];        // initial successes 
  real<lower = 0> a;        // beta param1
  real<lower = 0> b;        // beta param2
} 
parameters { 
  vector<lower=0, upper=1>[n] theta;  // chance of success (unpooled) 
} 
model { 
  y ~ binomial(N, theta);  // likelihood 
  theta ~ beta(a,b);
}

R code

tumors <- read.csv(file = url("http://www.stat.columbia.edu/~gelman/book/data/rats.asc"),
                     skip = 2, header = T, sep = " ")[,c(1,2)]
y <- tumors$y
N <- tumors$N
n <- length(y)

stan_dat <- list(n = n, N = N, y =y, a = 1, b = 1)
fit_nopool <- stan('lab-02-nopool.stan', data = stan_dat, chains = 2, refresh = 0)
nopool_output <- rstan::extract(fit_nopool)

Here's info on my systems:

RStan Version:

2.21.1

R Version:

R 4.0.1

Operating System:

macOS Catalina 10.15.5

christineymshen commented 4 years ago

In addition, now that as I'm editing my codes in .stan file in Rstudio, I noticed that I'm constantly getting this message in my console (every a few mins):

sh: clang++ -mmacosx-version-min=10.13: command not found

christineymshen commented 4 years ago

Updates:

I've installed R 4.0.2. I'm still getting all these messages. And for the example I mentioned above where it fails to run, now instead of generating error msg, my R session would crash with message saying:

R Session Aborted. R encountered a fatal error. The session was terminated.

Would really appreciate your help! Thanks!

christineymshen commented 4 years ago

Another update, I made the following change and then it can run without crashing. But I don't see why the original declaration is illegal.

original code:

parameters { 
  vector<lower=0, upper=1>[n] theta;  // chance of success (unpooled) 
} 

new code:

parameters { 
  real<lower=0, upper=1> theta[n];  // chance of success (unpooled) 
} 
Tasia21 commented 4 years ago

did you get the same following error again in R or Rstudio ? 2: In file.remove(c(unprocessed, processed)) : cannot remove file '/var/folders/fr/b4bvkc_11vj3ntd1r6859x5m0000gn/T//RtmpjkdCOb/file13be45025d82.stan', reason 'No such file or directory'

Tasia21 commented 4 years ago

maybe the solution tips put on this link (https://discourse.mc-stan.org/t/rstan-on-windows/16673) can help you solve the problem

christineymshen commented 4 years ago

did you get the same following error again in R or Rstudio ? 2: In file.remove(c(unprocessed, processed)) : cannot remove file '/var/folders/fr/b4bvkc_11vj3ntd1r6859x5m0000gn/T//RtmpjkdCOb/file13be45025d82.stan', reason 'No such file or directory'

I've been using Rstudio the whole time. The error msg appears in the console.

christineymshen commented 4 years ago

maybe the solution tips put on this link (https://discourse.mc-stan.org/t/rstan-on-windows/16673) can help you solve the problem

I saw this link, but wasn't sure whether I should follow the suggestions there since it's said to be for windows, while I'm using a mac~~

Tasia21 commented 4 years ago

well, maybe reinstall an earlier version of rstan. there are a large number of people who are having problems with rstan 2.21.x....

christineymshen commented 4 years ago

well, maybe reinstall an earlier version of rstan. there are a large number of people who are having problems with rstan 2.21.x....

I was just about to come and tell you that I've falled back to using 2.19.3 now and it works much better!! [facepalm

Tasia21 commented 4 years ago

hahah..congratulations!

jgabry commented 4 years ago

Sorry for the hassle! A few questions and suggestions:

Does installing RStan from GitHub with

remove.packages("rstan") # restart R after doing this before running the next line
remotes::install_github("stan-dev/rstan", ref = "develop", subdir =
"rstan/rstan")

work for you? Some people reported success with that in this other issue: https://github.com/stan-dev/rstan/issues/774

Also, what are the contents of your Makevars file? That can be accessed using file.edit(file.path(Sys.getenv("HOME"), ".R", "Makevars")).

christineymshen commented 4 years ago

file.edit(file.path(Sys.getenv("HOME"), ".R", "Makevars"))

Here's my Makevars file:

CXX14FLAGS=-O3 -march=native -mtune=native CXX14FLAGS += -arch x86_64 -ftemplate-depth-256

I think I was trying to follow the rstan get started page to set up this thing. But I remember when I installed the latest rstan, somehow it can't detect the buildtool so I was re-installing that and had to go over the process on get started page a few times. In the end I wasn't sure what I did... it was a blur.

I haven't tried installing from github. I need to use stan for something recently so guess I'll stick to the old version for now~~ I'll try that later!! Thanks for the suggestion!

jgabry commented 4 years ago

Ok that's the same as my Makevars file and I'm using the same operating system as you (Catalina), so that's not the problem. So yeah I recommend trying installing from GitHub, but totally fine to use the older version until then. If you do end up trying the GitHub installation let us know if that resolves the problem.

christineymshen commented 4 years ago

Ok that's the same as my Makevars file and I'm using the same operating system as you (Catalina), so that's not the problem. So yeah I recommend trying installing from GitHub, but totally fine to use the older version until then. If you do end up trying the GitHub installation let us know if that resolves the problem.

Thanks a lot for following up on this! I'll let you know later if I get to explore the development version on GitHub.

I just want to mention, when I was using v2.21.1, one issue is I constantly get R Session Aborted error, at random time running the same codes. And now that I've switched to using the old version, the same code runs fine. Also one time when I was exploring, I noticed that after rstan finished running, my R console was flooded (endlessly) with the following msg. And I had to terminate my R session manually. It seems like there's sth wrong with rstan working with C++...

*** recursive gc invocation

I've been noting down my issues here as well. Um... just in case it might be useful in any way...

https://discourse.mc-stan.org/t/r-session-aborted/17005 https://discourse.mc-stan.org/t/r-session-crash-while-using-vb-function-fullrank/16986

Again thanks a lot!!

jgabry commented 4 years ago

Thanks a lot for letting us know about the weird messages and other issues! I'll also respond to your discourse post(s) with a few other suggestions.

macl0029 commented 3 years ago

For what it's worth I had exactly (macOS=big sur; R=4.0.2; rstudio=1.4.1103) the same problem. None of the solutions here worked for me. I ended up deleting RStudio, R, every hidden R and R studio file (there are a few) and (i think crucially) all the R packages. I rebooted and reinstalled and all errors have vanished.

my first few attempts did not delete all the R packages because I couldn't find them all, so i suspect whatever was causing this warning/message was embedded in an ancillary package. (and i did try removing 'rstan' on through R a few times to no avail).