rocker-org / rocker

R configurations for Docker
https://rocker-project.org
GNU General Public License v2.0
1.45k stars 273 forks source link

rstan example doesn't compile in rocker/r-bspm containers #447

Closed adviksh closed 3 years ago

adviksh commented 3 years ago

Thank you for making these tools widely available! I've found rocker very helpful in my research, but am having trouble installing rstan in a container. I would appreciate any advice on resolving the error below or installing rstan another way. I'm not sure if I should be raising on the rocker side, the rstan side, or neither—apologies if this is the wrong place to do so.

Summary:

A minimal container that throws this error is:

Bootstrap: docker
From: rocker/r-bspm:20.04

%post
  apt-get update

  install.r rstan

%runscript
  Rscript -e 'example(stan_model, package = "rstan", run.dontrun = TRUE)'

In this container, trying to run the Script command produces this error:

Error in compileCode(f, code, language = language, verbose = verbose) :
    650 |   return internal::first_aligned<int(unpacket_traits<DefaultPacketType>::alignment),Derived>(m);      |     
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~/usr/bin/ld: /usr/lib/R/site-library/rstan/lib//libStanServices.a(stan_fit.o): relocation R_X86_64_PC32 against undefined hidden symbol 
`_ZTCN5boost10wrapexceptINS_4math14rounding_errorEEE0_NS_16exception_detail10clone_implINS4_19error_info_injectorIS2_EEEE' can not be used when making a shared object/usr/bin/ld: final link failed: bad valuecollect2: error: ld returned 1 exit 
statusmake: *** [/usr/share/R/share/make/shlib.mk:10: file200dd3ea0254b.so] Error 1

I've tried two fixes, both of which produce the same error as above:

1) Updating the boost libraries before installing rstan, adding the following immediately after updating apt-get:

apt-get install -y --no-install-recommends libboost-all-dev

When this failed, I also tried explicitly installing RcppEigen via install.r RcppEigen. This didn't resolve the error (I expect because RcppEigen was being installed from binary anyway).

2) Per the recommendation here, trying to install StanHeaders and rstan from source rather than binary by replacing the install.r command with:

Rscript -e 'options(repos = "https://cran.rstudio.com"); install.packages(c("StanHeaders", "rstan"), type = "source")'
eddelbuettel commented 3 years ago

There are two issues here.

First, does bspm get you the underlying r-cran-* package it promises. The answer appears to be yes.

Second, does that package, built by a different project, work. The answer may be no. But that is something for @marutter and me in a different project.

eddelbuettel commented 3 years ago

I can reproduce this. What I did is

  1. Start the same rocker/r-bspm:20.04 container
  2. apt update and apt upgrade which takes a minute or two.
  3. The install.r rstan which takes another minute or two and pulls in quite a few binaries
  4. Start R, load library(rstan) and launch example(stan_model, run.dontrun=TRUE)

which ends in the Boost linker error. That, as far as I can see, is an error in package rstan.

eddelbuettel commented 3 years ago

For what it is worth, under Ubuntu 20.10, I had to re-install rstan as the version installed was out of sync with V8 (and I might have gotten by just re-installing V8...).

Reinstalling from source took a few good moments (while I did all the other things reported above) but ... it leads to a working rstan. I can run the example. So again this would suggest that maybe we just have bad luck with the versions of rstan, stanheaders, BH and Boost. Sorry,

eddelbuettel commented 3 years ago

It works with rocker/r-bspm:testing after I took care of another little wart: we use an 'empty' package r-cran-bh there that is supposed to take care of the Boost dependencies without requiring the footprint of BH. That did not work, compilation of the example just fails with 'no Boost'. Lesson learned. So after temporarily disabling bspm and installing BH explicitly the example works for rstan under Debian testing with 'almost all' packages brought in via bspm.

So I am sorry 20.04 fell short for you. I am not sure any easy fixes can correct that.

adviksh commented 3 years ago

Thank you so much for looking into this so quickly and thoroughly! I think I'll try installing CmdStan into the container for stan purposes, and use bspm for everything else — it beats my old source installs by a mile.

I'm closing the issue because I have next steps for my particular case in mind. But, I'm happy to try other fixes on my end or stay part of the discussion if either would be helpful.