rstan needs gfortran 9+

  • Open
  • quality assurance status badge
Details
2 participants
  • meedstrom
  • Ricardo Wurmus
Owner
unassigned
Submitted by
meedstrom
Severity
normal
M
M
meedstrom wrote on 27 Sep 2021 11:33
(address . bug-guix@gnu.org)
72446ddb47e832e1139c2acd72d10c33@teknik.io
Hi!

With Guix' package for R, it's not possible to use rstan or the things that depend on it at runtime, whether installed via Guix' r-rstan or via R's own package manager install.packages("rstan"). They install fine, but functions such as stan() and brm() try to call make, and then things crash and burn. The exception is the rstanarm package because it ships precompiled Stan models and doesn't need make.

The issue is basically that rstan needs access to gfortran 9+ at runtime (for some minimum GLIBCXX version), and it seems the core R must be defined with it.

You find a related error if you try install.packages("isoband"), which could work as a test case:

/gnu/store/741057r2x06zwg6zcmqmdyv51spm6n9i-gfortran-7.5.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /home/kept/Dotfiles/R/x86_64-unknown-linux-gnu-library/4.1/00LOCK-isoband/00new/isoband/libs/isoband.so)

I've been using custom package definitions that make it work, but for some unrelated reasons I'm having difficulty upgrading my package manifests, so I figured it's high time to fix this thing upstream. Here are my definitions:

(define-public gfortran-9
(package
(inherit ((@@ (gnu packages gcc) custom-gcc)
gcc-9 "gfortran" '("fortran")
(@@ (gnu packages gcc) %generic-search-paths)))
(version "9")))

(define-public gfortran-toolchain-9
(package
(inherit (make-gcc-toolchain gfortran-9))))

(define-public r-minimal-me1
(package
(inherit (@ (gnu packages statistics) r-minimal))
(version "4.99.99-me1")
(inputs `(("gfortran" ,gfortran-9)
,@(alist-delete "gfortran"
(package-inputs (@ (gnu packages statistics) r-minimal)))))))

(define-public r-me1
(package
(inherit (@ (gnu packages statistics) r))
(version "4.99.99-me1")
(inputs `(("r-minimal" ,r-minimal-me1)
,@(alist-delete "r-minimal"
(package-inputs (@ (gnu packages statistics) r)))))))

;; add gcc and make at runtime, also needed
(define-public r-rstan-me1
(package
(inherit (@ (gnu packages cran) r-rstan))
(version "2.99.99-me1")
(propagated-inputs `(("gcc-toolchain" ,gcc-toolchain)
("make" ,gnu-make)
,@(package-propagated-inputs (@ (gnu packages cran) r-rstan))))))

(define-public r-igraph-me1
(package
(inherit (@ (gnu packages cran) r-igraph))
(version "2021-me1")
(inputs `(("r-minimal" ,r-minimal-me1)
,@(alist-delete "r-minimal"
(package-inputs (@ (gnu packages cran) r-igraph)))))
(native-inputs `(("gfortran" ,gfortran-9)
,@(alist-delete "gfortran"
(package-native-inputs (@ (gnu packages cran) r-igraph)))))))

;; ... and all other packages depending on r-rstan need to point to the new r-rstan-me1, better fix r-rstan upstream
R
R
Ricardo Wurmus wrote on 12 Jul 2022 19:19
(address . 50841@debbugs.gnu.org)
87pmiaxmov.fsf@elephly.net
Hi,

thank you for your bug report!

Toggle quote (6 lines)
> You find a related error if you try install.packages("isoband"), which could work as a test case:
>
> /gnu/store/741057r2x06zwg6zcmqmdyv51spm6n9i-gfortran-7.5.0-lib/lib/libstdc++.so.6: version
> `GLIBCXX_3.4.26' not found (required by
> /home/kept/Dotfiles/R/x86_64-unknown-linux-gnu-library/4.1/00LOCK-isoband/00new/isoband/libs/isoband.so)

“install.packages” will only work if you carefully control your
environment. It will not do the right thing when you use it on a
foreign distro, for example, because it would likely pick the system’s
compiler toolchain to build things that are eventually incompatible with
the libraries used by R from Guix.

Here’s an old blog post that explains the problem and how to work around
it if you must use “install.packages”:


I haven’t been able to reproduce your problem, though. Here’s what I did:

Toggle snippet (168 lines)
$ guix shell -C r-minimal r-rstan -D r-minimal -- R

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
code for methods in class "Rcpp_model_base" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_model_base" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_stan_fit" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_stan_fit" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
rstan (Version 2.21.5, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
> scode <- "
parameters {
real y[2];
}
model {
y[1] ~ normal(0, 1);
y[2] ~ double_exponential(0, 2);
}
"
fit1 <- stan(model_code = scode, iter = 10, verbose = FALSE)
+ + + + + + + + >
fit1
code for methods in class "Rcpp_stan_fit4model139796fca_b524cd829fcb9f50f6761f2451b62eec" was not checked for suspicious field assignments (recommended package 'codetools' not available?)
code for methods in class "Rcpp_stan_fit4model139796fca_b524cd829fcb9f50f6761f2451b62eec" was not checked for suspicious field assignments (recommended package 'codetools' not available?)

SAMPLING FOR MODEL 'b524cd829fcb9f50f6761f2451b62eec' NOW (CHAIN 1).
Chain 1:
Chain 1: Gradient evaluation took 6e-06 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1:
Chain 1:
Chain 1: WARNING: No variance estimation is
Chain 1: performed for num_warmup < 20
Chain 1:
Chain 1: Iteration: 1 / 10 [ 10%] (Warmup)
Chain 1: Iteration: 2 / 10 [ 20%] (Warmup)
Chain 1: Iteration: 3 / 10 [ 30%] (Warmup)
Chain 1: Iteration: 4 / 10 [ 40%] (Warmup)
Chain 1: Iteration: 5 / 10 [ 50%] (Warmup)
Chain 1: Iteration: 6 / 10 [ 60%] (Sampling)
Chain 1: Iteration: 7 / 10 [ 70%] (Sampling)
Chain 1: Iteration: 8 / 10 [ 80%] (Sampling)
Chain 1: Iteration: 9 / 10 [ 90%] (Sampling)
Chain 1: Iteration: 10 / 10 [100%] (Sampling)
Chain 1:
Chain 1: Elapsed Time: 0.000157 seconds (Warm-up)
Chain 1: 0.000123 seconds (Sampling)
Chain 1: 0.00028 seconds (Total)
Chain 1:

SAMPLING FOR MODEL 'b524cd829fcb9f50f6761f2451b62eec' NOW (CHAIN 2).
Chain 2:
Chain 2: Gradient evaluation took 3e-06 seconds
Chain 2: 1000 transitions using 10 leapfrog steps per transition would take 0.03 seconds.
Chain 2: Adjust your expectations accordingly!
Chain 2:
Chain 2:
Chain 2: WARNING: No variance estimation is
Chain 2: performed for num_warmup < 20
Chain 2:
Chain 2: Iteration: 1 / 10 [ 10%] (Warmup)
Chain 2: Iteration: 2 / 10 [ 20%] (Warmup)
Chain 2: Iteration: 3 / 10 [ 30%] (Warmup)
Chain 2: Iteration: 4 / 10 [ 40%] (Warmup)
Chain 2: Iteration: 5 / 10 [ 50%] (Warmup)
Chain 2: Iteration: 6 / 10 [ 60%] (Sampling)
Chain 2: Iteration: 7 / 10 [ 70%] (Sampling)
Chain 2: Iteration: 8 / 10 [ 80%] (Sampling)
Chain 2: Iteration: 9 / 10 [ 90%] (Sampling)
Chain 2: Iteration: 10 / 10 [100%] (Sampling)
Chain 2:
Chain 2: Elapsed Time: 0.000146 seconds (Warm-up)
Chain 2: 0.000132 seconds (Sampling)
Chain 2: 0.000278 seconds (Total)
Chain 2:

SAMPLING FOR MODEL 'b524cd829fcb9f50f6761f2451b62eec' NOW (CHAIN 3).
Chain 3:
Chain 3: Gradient evaluation took 6e-06 seconds
Chain 3: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 3: Adjust your expectations accordingly!
Chain 3:
Chain 3:
Chain 3: WARNING: No variance estimation is
Chain 3: performed for num_warmup < 20
Chain 3:
Chain 3: Iteration: 1 / 10 [ 10%] (Warmup)
Chain 3: Iteration: 2 / 10 [ 20%] (Warmup)
Chain 3: Iteration: 3 / 10 [ 30%] (Warmup)
Chain 3: Iteration: 4 / 10 [ 40%] (Warmup)
Chain 3: Iteration: 5 / 10 [ 50%] (Warmup)
Chain 3: Iteration: 6 / 10 [ 60%] (Sampling)
Chain 3: Iteration: 7 / 10 [ 70%] (Sampling)
Chain 3: Iteration: 8 / 10 [ 80%] (Sampling)
Chain 3: Iteration: 9 / 10 [ 90%] (Sampling)
Chain 3: Iteration: 10 / 10 [100%] (Sampling)
Chain 3:
Chain 3: Elapsed Time: 0.000271 seconds (Warm-up)
Chain 3: 0.000253 seconds (Sampling)
Chain 3: 0.000524 seconds (Total)
Chain 3:

SAMPLING FOR MODEL 'b524cd829fcb9f50f6761f2451b62eec' NOW (CHAIN 4).
Chain 4:
Chain 4: Gradient evaluation took 5e-06 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.05 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4:
Chain 4:
Chain 4: WARNING: No variance estimation is
Chain 4: performed for num_warmup < 20
Chain 4:
Chain 4: Iteration: 1 / 10 [ 10%] (Warmup)
Chain 4: Iteration: 2 / 10 [ 20%] (Warmup)
Chain 4: Iteration: 3 / 10 [ 30%] (Warmup)
Chain 4: Iteration: 4 / 10 [ 40%] (Warmup)
Chain 4: Iteration: 5 / 10 [ 50%] (Warmup)
Chain 4: Iteration: 6 / 10 [ 60%] (Sampling)
Chain 4: Iteration: 7 / 10 [ 70%] (Sampling)
Chain 4: Iteration: 8 / 10 [ 80%] (Sampling)
Chain 4: Iteration: 9 / 10 [ 90%] (Sampling)
Chain 4: Iteration: 10 / 10 [100%] (Sampling)
Chain 4:
Chain 4: Elapsed Time: 0.00014 seconds (Warm-up)
Chain 4: 0.000132 seconds (Sampling)
Chain 4: 0.000272 seconds (Total)
Chain 4:
Warning message:
The largest R-hat is 1.07, indicating chains have not mixed.
Running the chains for more iterations may help. See
https://mc-stan.org/misc/warnings.html#r-hat
> > Inference for Stan model: b524cd829fcb9f50f6761f2451b62eec.
4 chains, each with iter=10; warmup=5; thin=1;
post-warmup draws per chain=5, total post-warmup draws=20.

mean se_mean sd 2.5% 25% 50% 75% 97.5% n_eff Rhat
y[1] -0.02 0.20 1.02 -1.80 -0.68 -0.05 0.59 1.86 26 0.89
y[2] 2.06 0.49 1.81 -1.29 0.78 1.96 3.48 5.00 14 1.08
lp__ -1.65 0.17 0.85 -3.08 -2.20 -1.64 -1.01 -0.41 26 0.81

Samples were drawn using NUTS(diag_e) at Tue Jul 12 17:28:00 2022.
For each parameter, n_eff is a crude measure of effective sample size,
and Rhat is the potential scale reduction factor on split chains (at
convergence, Rhat=1).
>

Could you please show us an example like the above that fails when run
in “guix shell -C”? Please also provide the output of “guix describe -f
channels”.
Thank you!

--
Ricardo
?
Your comment

Commenting via the web interface is currently disabled.

To comment on this conversation send an email to 50841@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 50841
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch