stan-dev / rstan

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

8 schools example fails to run. Win10, R3.5.2, Rtools35 #602

Closed alexpbell closed 5 years ago

alexpbell commented 5 years ago

Summary:

8 schools example fails to run. Possibly failing to correctly build and/or load the dll. Happens only with manual install of Rtools (as opposed to letting RStudio's script do the job).

Description:

This issue only occurs when I install Rtools 'manually'. If I allow RStudio to take care of the installation (through the pop-up that appears after calling pkgbuild::has_build_tools) then everything works fine. However, I need to get rstan working on a number of machines in an environment with the following limitation: users can only call on admin privileges to install specific programs (they cannot log on to the OS with admin privileges) AND programs running in admin don't have access to the internet. For most use cases this is fine: just right-click on the executable installer and select "run as administrator". Then fire the program up as user. However this combo means that RStudio's install script fails, as I know of no way to tell the script to install Rtools as admin (without running R as admin because then no internet). I'm hoping to get around this by installing Rtools manually. This is when I run into the aforementioned error.

I have access to an identical machine without the authentication limitation and it all works fine. Poking around on this version I see RStudio's automated installer puts Rtools in C:\RBuildTools\3.5\ rather than C:\Rtools\ but clearly that is not all it is doing differently.

I have managed to build the dll in question directly at the command line (on a machine with the limitation), and unfortunately it not only builds without error but a dump indicates the dll is exporting the symbol in question (file34b443d642f2). So the error message from R is .. intriguing. From memory inline's compileCode function returns, the error is caught later.

Reproducible Steps:

install.packages("rstan", repos = "https://cloud.r-project.org/", dependencies = TRUE) ... pkgbuild::has_build_tools(debug = TRUE) [1] FALSE # here RStudio does it's pop-up thing, downloads Rtools, then the OS tells me I'm not authorised

here I go and install Rtools (Rtools35.exe) myself, following the steps here https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows#download-and-install-rtools

pkgbuild::has_build_tools(debug = TRUE) [1] TRUE # seems promising schools_dat <- list(J = 8, y = c(28, 8, -3, 7, -1, 1, 18, 12), sigma = c(15, 10, 16, 11, 9, 11, 10, 18)) fit <- stan(model_code="data { int J; // number of schools real y[J]; // estimated treatment effects real sigma[J]; // standard error of effect estimates } parameters { real mu; // population treatment effect real tau; // standard deviation in treatment effects vector[J] eta; // unscaled deviation from mu by school } transformed parameters { vector[J] theta = mu + tau * eta; // school treatment effects } model { target += normal_lpdf(eta | 0, 1); // prior log-density target += normal_lpdf(y | theta, sigma); // log-likelihood }", data = schools_dat, verbose=TRUE)

Current Output:

TRANSLATING MODEL '20a8edfdaa8a680a356eadf8c4be5d42' FROM Stan CODE TO C++ CODE NOW. successful in parsing the Stan model '20a8edfdaa8a680a356eadf8c4be5d42'. COMPILING THE C++ CODE FOR MODEL '20a8edfdaa8a680a356eadf8c4be5d42' NOW. OS: x86_64, mingw32; rstan: 2.18.2; Rcpp: 1.0.0; inline: 0.3.15

setting environment variables: PKG_LIBS = -L"C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/libs/x64" -lStanHeaders PKG_CPPFLAGS = -I"C:/Users/campbella3/Documents/R/win-library/3.5/Rcpp/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/RcppEigen/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/RcppEigen/include/unsupported" -I"C:/Users/campbella3/Documents/R/win-library/3.5/BH/include" -I"C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/src/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y Program source :

1 : 2 : // includes from the plugin 3 : // [[Rcpp::plugins(cpp14)]] 4 : 5 : // user includes 6 : #define STANSERVICESCOMMAND_HPP// Code generated by Stan version 2.18.0 7 : 8 : #include <stan/model/model_header.hpp> 9 : 10 : namespace model34b476b341b6_20a8edfdaa8a680a356eadf8c4be5d42_namespace { ... 528 : SEXP file34b443d642f2( ){ 529 : return Rcpp::wrap("20a8edfdaa8a680a356eadf8c4be5d42"); 530 : } 531 : 532 : Compilation argument: C:/PROGRA~1/R/R-35~1.2/bin/x64/R CMD SHLIB file34b443d642f2.cpp 2> file34b443d642f2.cpp.err.txt C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-35~1.2/include" -DNDEBUG -I"C:/Users/campbella3/Documents/R/win-library/3.5/Rcpp/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/RcppEigen/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/RcppEigen/include/unsupported" -I"C:/Users/campbella3/Documents/R/win-library/3.5/BH/include" -I"C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/src/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/" -I"C:/Users/campbella3/Documents/R/win-library/3.5/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -std=c++1y -march=core2 -O2 -Wall -mtune=generic -c file34b443d642f2.cpp -o file34b443d642f2.o C:/Rtools/mingw_64/bin/g++ -shared -s -static-libgcc -o file34b443d642f2.dll tmp.def file34b443d642f2.o -LC:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/libs/x64 -lStanHeaders -LC:/PROGRA~1/R/R-35~1.2/bin/x64 -lR In file included from C:/Users/campbella3/Documents/R/win-library/3.5/BH/include/boost/random/detail/integer_log2.hpp:19:0, from C:/Users/campbella3/Documents/R/win-library/3.5/BH/include/boost/random/detail/int_float_pair.hpp:26, from C:/Users/campbella3/Documents/R/win-library/3.5/BH/include/boost/random/exponential_distribution.hpp:27, from C:/Users/campbella3/Documents/R/win-library/3.5/BH/include/boost/random/gamma_distribution.hpp:25, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/prim/mat.hpp:276, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:12, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math.hpp:4, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/src/stan/model/model_header.hpp:4, from file34b443d642f2.cpp:8: C:/Users/campbella3/Documents/R/win-library/3.5/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead. BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>"); ^ In file included from C:/Users/campbella3/Documents/R/win-library/3.5/rstan/include/rstan/rstaninc.hpp:3:0, from file34b443d642f2.cpp:476: C:/Users/campbella3/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp: In instantiation of 'SEXPREC rstan::stan_fit<Model, RNG_t>::standalone_gqs(SEXP, SEXP) [with Model = model34b476b341b6_20a8edfdaa8a680a356eadf8c4be5d42_namespace::model34b476b341b6_20a8edfdaa8a680a356eadf8c4be5d42; RNG_t = boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014u, 0u, 2147483563u>, boost::random::linear_congruential_engine<unsigned int, 40692u, 0u, 2147483399u> >; SEXP = SEXPREC]': file34b443d642f2.cpp:517:0: required from here C:/Users/campbella3/Documents/R/win-library/3.5/rstan/include/rstan/stan_fit.hpp:1222:9: warning: variable 'ret' set but not used [-Wunused-but-set-variable] int ret; ^ In file included from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core.hpp:44:0, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/mat.hpp:4, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math.hpp:4, from C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/src/stan/model/model_header.hpp:4, from file34b443d642f2.cpp:8: C:/Users/campbella3/Documents/R/win-library/3.5/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:13: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function] static void set_zero_all_adjoints() { ^ Error in FUN(X[[i]], ...) : no such symbol file34b443d642f2 in package C:/Users/CAMPBE~1/AppData/Local/Temp/RtmpmyGlZ6/file34b443d642f2.dll

Expected Output:

Successful model run

RStan Version:

packageVersion("rstan") [1] ‘2.18.2’

R Version:

R.version.string [1] "R version 3.5.2 (2018-12-20)"

Operating System:

OS Name Microsoft Windows 10 Enterprise Version 10.0.17134 Build 17134

alexpbell commented 5 years ago

Just posed a question to the RStudio community

bgoodri commented 5 years ago

I don't know if there is anything I can do about this. Did you get it to work in your use case?

alexpbell commented 5 years ago

This turned out to be due to a organisation-wide standard operating environment restriction that prevents applications from loading dlls unless white-listed. I got them to push a patch for this case, so all good. Apologies for not responding sooner.

The error message from R was misleading and made tracking this down quite difficult. I will report this to the R dev community when I get a chance.

bgoodri commented 5 years ago

OK, thanks.