Error in rstan_2.16.2 after upgrading to R 3.4.1 with Clang 4.0.0

Yeah

devtools::install_github("stan-dev/rstanarm", args = "--preclean")

also works fine if I change .R/Makevars back to

CXXFLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function -Wno-macro-redefined

CC=clang
CXX=clang++ -arch x86_64 -ftemplate-depth-256

What about R CMD INSTALL --build rstanarm each way?

Without --preclean?

Might not matter but do --preclean to be on the safe side. Also, are you using XCode 9 now?

Yeah XCode 9. I have to step out for a little bit but I can check R CMD INSTALL --build --preclean both ways a little bit later tonight.

Both ways seem to work.

It would be better if you can get rstanarm from CRAN to throw this error, so that we can confirm it goes away with the fix. Try a model with a fixed seed but stupid priors.

Actually after reinstalling the CRAN version from source a second time it isn’t working anymore. With clang4 I get

fit <- stan_glm(mpg ~ wt, data = mtcars)

trying deprecated constructor; please alert package maintainer

SAMPLING FOR MODEL 'continuous' NOW (CHAIN 1).
empty_nested() must be true before calling recover_memory()
[1] "Error in sampler$call_sampler(args_list[[i]]) : "             
[2] "  empty_nested() must be true before calling recover_memory()"
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug

The code above doesn’t produce any errors when using the version installed from GitHub.

I can also get the CRAN version to throw errors like this:

fit <- stan_glm(
  mpg ~ ., data = mtcars,
  iter = 30,
  prior = hs(global_scale = 20),
  adapt_delta = 0.5,
  seed = 1
)

trying deprecated constructor; please alert package maintainer

SAMPLING FOR MODEL 'continuous' NOW (CHAIN 1).

Gradient evaluation took 0.000149 seconds
1000 transitions using 10 leapfrog steps per transition would take 1.49 seconds.
Adjust your expectations accordingly!


WARNING: No variance estimation is
         performed for num_warmup < 20

[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done
Error in check_stanfit(stanfit) : 
  Invalid stanfit object produced please report bug

but the GitHub version is ok. So that’s good news.

1 Like

I have no idea WTF that is about, but let’s assume it is related to the c++ exception (unknown reason) thing, which I am going to consider fixed. Now, we have to figure out how to fix it for rstan.

With clang4, do

funnel <- stan_demo("funnel")

which presumably will die on an exception. Then do Kevin’s hack

SO <- dir(tempdir(), pattern = "so$")
source <- "/usr/local/clang4/lib/libc++.1.dylib"
target <- "/usr/lib/libc++.1.dylib"
cmd <- paste(
  "install_name_tool",
  "-change",
  source,
  target,
  SO
)
system(cmd)

Then do

dyn.unload(SO)
dyn.load(SO)
funnel <- stan_demo("funnel")

to see if that works on a Mac.

Or someone with clang4, try rstan from GitHub

devtools::install_github("stan-dev/rstan", ref = "develop", 
                         subdir = "rstan/rstan")

and then try

library(rstan)
funnel <- stan_demo("funnel")

Will try that now. But funnel was running ok for me. birats definitely had the problem.

You may need StanHeaders 2.17
https://raw.githubusercontent.com/stan-dev/rstan/develop/install_StanHeaders.R

seems to work fine with StanHeaders 2.17 and rstan from GitHub.

I guess adding Kevin’s hack is the solution for the time being?

I guess

Hi guys, I’ve screwed things up badly and I can’t figure out how to fix it.

rstan was running well yesterday — modulo the fact that I got the message Jonah alludes to above:
“trying deprecated constructor; please alert package maintainer”. It would try a
deprecated constructor, however, and then work fine as far as I can tell.

At some point I think I accidentally executed install code for rstan or rstanarm while one or both of those was running.

Afterwards, models that were previously working fine started producing the other kinds of errors Johan alludes to, things like this:

Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”

error occurred during calling the sampler; sampling not done
here are whatever error messages were returned:

[[1]] Stan model ‘bernoulli’ does not contain samples.

[[2]] Stan model ‘bernoulli’ does not contain samples.

I don’t know much but it seems like the problem may be in the Mkdirs (which I presume compiles the C code or something.) I changed the model such that it had very simple priors and set various seeds to help it initialize. I reinstalled rstan and rstanarm from Github and Cran and tried all permutations of the above.
I think I’m out of my league and not sure what to do at this point!

Some thoughts:

I called the following:

system(“clang++ -v”)
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix

I called the following:

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , ’
return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) )
fx( 2L, 5 ) # should be 10
[1] 10

I just updated to Xquartz 2.7.11 trying to fix things (should that matter).
Also, I’m still running OS 10.10.1 on a Mac (trying to avoid precisely these kinds of problems!).
Should I go here and get the compiler binaries (or whatever): http://r.research.att.com/libs/ (I believe I need Darwin 13…and then execute a sudo command
at the unix command line?).
Note my file path is not the usual “/usr/local/clang4/bin/“. Its /.R/Mkvars. Does that matter? (I’m happy to change this).

Any assistance would be greatly appreciated, I’m pretty desperate! Cheers, Will

I think the configuration file has to be ~/.R/Makevars