R 4.0.0 and CRAN MacOS binaries

Hi!

This was actually a call to the community to test this. It is really straightforward to do so. Anyone with Catalina problems should join in resolving the matter.

Now, I went ahead and installed the latest R 4.0.0 RC on my macOS Catalina. As CRAN now provides binary packages pre-build with the new toolchain (based on clang macOS High Sierra toolchain) this promises to solve all problems… and there is a lot of light here:

  • IT WORKS TO DOWNLOAD PRE-BUILD RSTAN BASED PACKAGES AND RUN THEM JUST FINE ON CATALINA
  • compling a Stan model with stan_model works fine
  • sampling a Stan model with Sampling works just fine - with/without running chains in parallel
  • sampling with my own packages OncoBayes2 + RBesT works only fine when avoiding parallel sampling strangely
  • sampling with rstanarm in parallel does work

@bgoodri while there is some oddity going on with OncoBayes2 & RBesT for parallel sampling, I think this all looks very promising!

All I have in my ~/.R/Makevars is:

CFLAGS+=-O3 -march=native -mtune=native
CCFLAGS+=-O3 -march=native -mtune=native
CXXFLAGS+=-O3 -march=native -mtune=native

CXX14FLAGS+=-O3 -march=native -mtune=native

CXX14FLAGS += -DSTAN_THREADS
CXX14FLAGS += -arch x86_64 -ftemplate-depth-256
CXX14FLAGS += -DBOOST_MATH_PROMOTE_DOUBLE_POLICY=false

Below is the R script with the key outputs as produced by my R session:

pkgs <- c("rstan", "RBesT", "OncoBayes2", "rstanarm")

for(p in pkgs) {
    if(!require(p, character.only=TRUE))
        install.packages(p)
    require(p, character.only=TRUE)
}

## ok
example_model("combo2_trial")


options(mc.cores=4)
example_model("combo3")
## fails with
## Error in unserialize(node$con) : error reading from connection
## Calls: <Anonymous> -> slaveLoop -> makeSOCKmaster
## Execution halted


options(mc.cores=1)

## ok
set.seed(34563)
map_AS <- gMAP(cbind(r, n-r) ~ 1 | study,
               family=binomial,
               data=AS,
               tau.dist="HalfNormal", tau.prior=1,
               beta.prior=2)

map_AS

forest_plot(map_AS)

save_stan_model  <- function(fit) {
    model_name  <- attr(fit, "model_name")
    stan_model_file  <- paste0(model_name, ".stan")
    cat(paste0(get_stancode(fit), "\n"), file=stan_model_file)
    stan_model_file
}

library(rstan)
stan_model_file <- save_stan_model(map_AS$fit)

sm <- stan_model(stan_model_file)

fit_AS  <- sampling(sm, data=map_AS$fit.data, control=list(adapt_delta=0.9), cores=4)

print(fit_AS, pars="theta_pred")



## rstanarm - all ok
data(roaches)
roaches$roach1 <- roaches$roach1 / 100
roaches$log_exposure2 <- log(roaches$exposure2)
post <- stan_gamm4(
  y ~ s(roach1) + treatment + log_exposure2,
  random = ~(1 | senior),
  data = roaches,
  family = neg_binomial_2,
  QR = TRUE,
  cores = 2,
  chains = 2,
  adapt_delta = 0.99,
  seed = 12345)

R session:

> sessionInfo()
R version 4.0.0 RC (2020-04-21 r78267)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] C/UTF-8/C/C/C/C

attached base packages:
[1] stats     graphics  datasets  grDevices utils     methods   base     

other attached packages:
 [1] rstan_2.19.3       ggplot2_3.3.0      StanHeaders_2.19.2 abind_1.4-5       
 [5] tidyr_1.0.2        dplyr_0.8.5        tibble_3.0.1       OncoBayes2_0.6-4  
 [9] RBesT_1.6-0        Rcpp_1.0.4.6      

loaded via a namespace (and not attached):
 [1] tidyselect_1.0.0   purrr_0.3.4        reshape2_1.4.4     tcltk_4.0.0       
 [5] colorspace_1.4-1   vctrs_0.2.4        stats4_4.0.0       loo_2.2.0         
 [9] rlang_0.4.5        pkgbuild_1.0.6     pillar_1.4.3       withr_2.2.0       
[13] glue_1.4.0         matrixStats_0.56.0 lifecycle_0.2.0    plyr_1.8.6        
[17] stringr_1.4.0      munsell_0.5.0      gtable_0.3.0       mvtnorm_1.1-0     
[21] codetools_0.2-16   labeling_0.3       inline_0.3.15      callr_3.4.3       
[25] ps_1.3.2           parallel_4.0.0     fansi_0.4.1        bayesplot_1.7.1   
[29] rstantools_2.0.0   scales_1.1.0       backports_1.1.6    checkmate_2.0.0   
[33] farver_2.0.3       gridExtra_2.3      digest_0.6.25      stringi_1.4.6     
[37] processx_3.4.2     grid_4.0.0         cli_2.0.2          tools_4.0.0       
[41] magrittr_1.5       Formula_1.2-3      crayon_1.3.4       pkgconfig_2.0.3   
[45] ellipsis_0.3.0     prettyunits_1.1.1  ggridges_0.5.2     assertthat_0.2.1  
[49] R6_2.4.1           compiler_4.0.0    
> 
5 Likes