ropensci / dynamite

Bayesian Inference of Complex Panel Data
https://docs.ropensci.org/dynamite/
GNU General Public License v3.0
27 stars 1 forks source link

Custom Stan code vignette compilation error on docs pages #82

Open santikka opened 3 months ago

santikka commented 3 months ago

@mpadge We're getting a compilation error on the rOpenSci docs pages for one vignette (see the third code block): https://docs.ropensci.org/dynamite/articles/dynamite_custom.html, could you provide any insight into what might be happening? Curiously though the fit object still seems to be accessible in the next code block unless it is using a cached result somehow. The example runs without issues locally.

mpadge commented 3 months ago

I have no idea. cmath should be part of std in any installation. It's pulled in whenever any routine anywhere in the compilation chain requires any function defined there, so should never be missing in practice. You can't directly pull it in here because you've got no source code. There error can't directly arise from RcppEigen either, because the #include <cmath> statements there are perfectly legitimate. I can only guess as you suggest that there's some kind of cache issue happening. @jeroen Any ideas?

jeroen commented 3 months ago

This error happens because it is trying to compile c++ files with gcc (the c compiler) instead of g++.

helske commented 3 months ago

But why is it doing so? This seems to happen now with other models as well, e.g. https://docs.ropensci.org/dynamite/articles/dynamite.html#sec:seatbelt. Same code runs without error locally and in github actions, as well as in r-universe: https://ropensci.r-universe.dev/articles/dynamite/dynamite.html which I though was used in the pkgdown site as well?

I can't find exactly the same issue with google, but I've encountered similar issues sometimes when somekind of mismatch with the versions of various packages used by rstan (e.g., BH, RcppEigen, StanHeaders, RcppParallel) and/or compilers.

mpadge commented 3 months ago

Dunno. The include flags (-I) are pulling in the C++ headers from Rcpp, RcppEigen, and BH for a "simple C file":

> Trying to compile a simple C file
#> Running /usr/lib/R/bin/R CMD SHLIB foo.c
#> using C compiler: ‘gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0’
#> gcc -I"/usr/share/R/include" -DNDEBUG   -I"/usr/local/lib/R/site-library/Rcpp/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/"  -I"/usr/local/lib/R/site-library/RcppEigen/include/unsupported"  -I"/usr/local/lib/R/site-library/BH/include" -I"/usr/local/lib/R/site-library/StanHeaders/include/src/"  -I"/usr/local/lib/R/site-library/StanHeaders/include/"  -I"/usr/local/lib/R/site-library/RcppParallel/include/"  -I"/usr/local/lib/R/site-library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DUSE_STANC3 -DSTRICT_R_HEADERS  -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION  -D_HAS_AUTO_PTR_ETC=0  -include '/usr/local/lib/R/site-library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'  -D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1       -fpic  -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/r-base-RCJDS4/r-base-4.4.0=. -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/r-base-RCJDS4/r-base-4.4.0=/usr/src/r-base-4.4.0-2.2404.0 -Wdate-time -D_FORTIFY_SOURCE=3  -c foo.c -o foo.o

Something going wrong in cmdstanr? I'd check there.


Update: You could step through rstan/R/stan.R, which should return a strict C object long before it pulls in the C++ headers. Seems like something there is failing.

helske commented 3 months ago

The example is using rstan, not cmdstanr, but it's difficult to debug this as we see this issue only on the ropensci pkgdown site.

santikka commented 3 months ago

As a workaround in 6a01d3e5bad85645129ad3a4e40236aea2ba5580, I've wrapped all model fits in the vignettes with invisible(capture.output(...)) with error = FALSE, message = FALSE, warning = FALSE in the chunk options. This at least prevents the Trying to compile a simple C file "errors" from being displayed, as they don't seem to influence the actual model fitting.