Cmdstanr gets stuck in compilation

Operating System: Catalina
Interface Version: cmdstanr 0.0.9000, stanc v2.22.1(unix)
Compiler/Toolkit: macos-rtools

I got the problem that cmdstanr gets stuck when compiling a stan model or even installing cmdstan.

I starting using cmdstan awhile ago. Last week, I installed the macos-rtools to get rstanarm and brms working again on Catalina. All went well as far as I could see. However, when I tried to use cmdstanr again I got errors that made me think that because I switched compilers I had to recompile cmdstan. That did not finish after >12hours. I then recompiled cmdstan from the command line and it was a breeze (5 minutes).

The problem now is that cmdstanr is taking ages (killed it after 10 minutes) to compile simple models. Again from the command line, everything is fine. In fact, it’s so fast that I thought nothing has happened at first (kudos on that!).


As a side note: the bernoulli example in cmdstan throws an error.

Semantic error in 'examples/bernoulli/bernoulli.stan', line 10, column 6 to column 15:
   -------------------------------------------------
     8:  model {
     9:    theta ~ beta(1,1);  // uniform prior on interval 0,1
    10:    y ~ bernoulli(theta);
               ^
    11:  }
   -------------------------------------------------

Identifier 'bernoulli' clashes with model name.

Current ~/.R/makevars

# clang: start
CFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CCFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CXXFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include

SHLIB_CXXLDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
SHLIB_CXX14LDFLAGS+=-Wl,-rpath,${R_HOME}/lib ${R_HOME}/lib/libc++abi.1.dylib
# clang: end

I am not an expert on anything Mac related but @andrewgelman had a similar issue installing on Catalina.

@mitzimorris got to the bottom of this and found out that Catalina has added a bunch of security features such that the stanc binaries when downloaded are automatically quarantined (sign of the times :) ) because they are not signed using Apple developer program credentials.

This issue was fixed on the cmdstan side but is currently only available on the Github repository. You need to install cmdstan from the repo using
install_cmdstan(repo_clone = TRUE, cores = 4)

Hm, I am confused by this one. We did change the compilation of models so that we now explicitly set the name stanc flag so it could come from that. But I am unable to reproduce this one :/

library(cmdstanr)

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

This runs ok for me.

Can you make sure you are using the latest version of cmdstanr. Sorry for the troubles.

1 Like

Thanks, Rok. Unfortunately that did not work for me. I got a lot of clang++ messages like these

clang++ -std=c++1y -Wno-unknown-warning-option -Wno-tautological-compare -Wno-sign-compare -D_REENTRANT       -I stan/lib/stan_math/lib/tbb_2019_U8/include -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.3 -I stan/lib/stan_math/lib/boost_1.72.0 -I stan/lib/stan_math/lib/sundials_5.2.0/include    -DBOOST_DISABLE_ASSERTS      -c -MT bin/cmdstan/lang/grammars/bare_type_grammar_inst.o -MT stan/src/stan/lang/grammars/bare_type_grammar_inst.d -MM -E -MG -MP -MF stan/src/stan/lang/grammars/bare_type_grammar_inst.d stan/src/stan/lang/grammars/bare_type_grammar_inst.cpp

and then cmdstan_install times out. The command line building worked fine again. cmdstan_model just hangs again.

I reinstalled cmdstanr from github. No worries about the troubles. I know cmdstanr is still beta and Catalina has been something else. I can work with rstan for the moment. I am going to miss those sweet compile times though :-).


sidenote:

bin/stanc --name=bernoulli examples/bernoulli/bernoulli.stan

throws the error I mentioned before. I used that because that is what the cmdstan starting guide suggests. The following two calls work without a hitch.

bin/stanc examples/bernoulli/bernoulli.stan
bin/stanc --name=bernoulli2 examples/bernoulli/bernoulli.stan
1 Like
bin/stanc --name=bernoulli examples/bernoulli/bernoulli.stan

That needs to be fixed ASAP as it wont work with cmdstan 2.21+. Didnt realize that was an example somewhere. Thanks. EDIT: Fix in process https://github.com/stan-dev/cmdstan/pull/849

Yeah, this has something to do with clang and Catalina. I am sorry, cant help much there as I am complete noob when it comes to Macs. Hopefully @mitzimorris has an idea.

1 Like

we should definitely go with the first example - get rid of the --name arg in both the example and the makefile.

maybe the stanc3 compiler changed something, if so, wondering why this didn’t get noticed sooner. investigating.

Yes, stanc3 requires the model name not to be used. The default name is usually filename_model so its not really an issue.
I will delete the use of name from the example on the PR.

Not sure what you mean by removing it from makefile? I think @stijn just played around directly with the stanc3 compiler binaries.

Is this a Mac specific issue? I am not sure I completely understand what the issue is :/

perhaps this is due to the ~/.Renviron file? cf CmdStanR - install_cmdstan() not finishing build of cmdstan

here’s the initial report:

2 Likes

Thanks Mitzi!

Removing ~/.Renviron did the trick. My apologies, I should have found that thread on my own. Back to the sweet compile times for me.

Stijn.

1 Like

no need to apologize - this is not something we expect people to know about.

thanks for confirming that this was the problem. @bgoodri and @jonah - this is a problem - file issue on RStan? or?