stan-dev / rstan

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

M1 mac, cannot install binary, c++ exception (unknown reason) when using source install #947

Open ltalluto opened 3 years ago

ltalluto commented 3 years ago

Summary:

rstan, which was working 3 weeks ago, suddenly stopped providing informative error messages, instead giving c++ exception (unknown reason). Attempting to reinstall fails with various errors depending on the installation method.

Description:

  1. The initial error causing my problem was that I have suddenly started getting c++ exception (unknown reason) on any error when trying to run a stan model. Following the advice I found from searching around, e.g., here, I tried to reinstall rstan from source:

install.packages("rstan", type = "source")

This seemingly successfully compiles, but fails at the end when it tries to load the package:

Error: package or namespace load failed for ‘rstan’:
 .onLoad failed in loadNamespace() for 'rstan', details:
  call: dyn.load(tbbmalloc_proxy, local = FALSE, now = TRUE)
  error: unable to load shared object '/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/':
  dlopen(/private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/, 10): no suitable image found.  Did find:
    /private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan/: not a file
    /private/var/folders/6w/y9r4gl_x4hs80gtsj4k7ynbh0000gn/T/Rtmp8BXbOH/R.INSTALL1128151514a75/rstan: not a file
Error: loading failed
Execution halted

I tried editing CXX in ~/.R/Makevars to try different compilers (I have g++, apple clang, and macports clang), but this did not change the compiler messages (i.e., it still compiles with clang even when I change CXX to g++).

  1. Next I tried to clone the GitHub repository, run make build, then use R CMD INSTALL to install the package. This succeeds. However, running a test model with a syntax error again gives me c++ exception (unknown reason).

  2. Finally, I tried to re-install the CRAN binary. The installation also succeeds (and is correctly getting the arm64 build). However, I cannot load the package:

> library("rstan")
Loading required package: StanHeaders
Loading required package: ggplot2
Error: package or namespace load failed for ‘rstan’:
 .onLoad failed in loadNamespace() for 'rstan', details:
  call: dyn.load(tbbmalloc_proxy, local = FALSE, now = TRUE)
  error: unable to load shared object '/Users/mtalluto/':
  dlopen(/Users/mtalluto/, 10): no suitable image found.  Did find:
    /Users/mtalluto/: not a file
    /Users/mtalluto: not a file

The directory indicated is my working directory!

Reproducible example

I can only run this after installing using method 2 above.

library(rstan)
code = "
data {
vector [5] x // syntax error, no ;
}
parameters {
real mu;
}
model {
x ~ normal(mu, 1)
}
"

stan_model(model_code = code)

## Error in stanc(file = file, model_code = model_code, model_name = model_name,  : 
##    c++ exception (unknown reason)

RStan Version:

2.21.3

R Version:

4.1.0 (2021-05-18)

Operating System:

macOS 11.4, arm64 version

barracuda156 commented 2 years ago

I got now the same error when trying to build Rstan on a PowerPC Mac:

ar -rs ../inst/lib//libStanServices.a stan_fit.o stan_fit_base.o
ar: creating archive ../inst/lib//libStanServices.a
installing to /Users/svacchanda/Library/R/powerpc/4.1/library/00LOCK-rstan/00new/rstan/libs
** R
** inst
** byte-compile and prepare package for lazy loading
Warning message:
In file(con, "r") :
  cannot open file '/var/db/timezone/zoneinfo/+VERSION': No such file or directory
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
Warning in file(con, "r") :
  cannot open file '/var/db/timezone/zoneinfo/+VERSION': No such file or directory
Error: package or namespace load failed for ‘rstan’:
 .onLoad failed in loadNamespace() for 'rstan', details:
  call: dyn.load(tbbmalloc_proxy, local = FALSE, now = TRUE)
  error: unable to load shared object '/private/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-/RtmpIprbyl/R.INSTALLb6525da2c990/rstan/':
  dlopen(/private/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-/RtmpIprbyl/R.INSTALLb6525da2c990/rstan/, 10): no suitable image found.  Did find:
        /private/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-/RtmpIprbyl/R.INSTALLb6525da2c990/rstan/: not a file
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Users/svacchanda/Library/R/powerpc/4.1/library/rstan’
barracuda156 commented 2 years ago

Removed a relevant call to tbbmalloc from zzz.R file in source, Rstan compiled, however running a test model fails:

[R.app GUI 1.72 (7847) powerpc-apple-darwin10.0.0d2]

[History restored from /Users/svacchanda/.Rapp.history]

> library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
Need help getting started? Try the R Graphics Cookbook: https://r-graphics.org
rstan (Version 2.21.2, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Warning message:
In file(con, "r") :
  cannot open file '/var/db/timezone/zoneinfo/+VERSION': No such file or directory
> scode <- "
+ parameters {
+   real y[2];
+ }
+ model {
+   y[1] ~ normal(0, 1);
+   y[2] ~ double_exponential(0, 2);
+ }
+ "
> fit1 <- stan(model_code = scode, iter = 10, verbose = FALSE)
Error in dyn.load(libLFile) :
  unable to load shared object '/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpnOlqOR/filed69511e8933e.so':
  dlopen(/var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpnOlqOR/filed69511e8933e.so, 6): Library not loaded: @rpath/libtbb.dylib
  Referenced from: /var/folders/rD/rDeCM6SDHv8daLCecrRmrU+++TI/-Tmp-//RtmpnOlqOR/filed69511e8933e.so
  Reason: image not found
Error in sink(type = "output") : invalid connection
>