stan-dev / cmdstanr

CmdStanR: the R interface to CmdStan
https://mc-stan.org/cmdstanr/
Other
144 stars 63 forks source link

Setting `compile_model_methods=TRUE` causes a staged installation to fail #904

Open ben18785 opened 9 months ago

ben18785 commented 9 months ago

Describe the bug I am using a staged installation in an R package I am developing (using the machinery of instantiate). When I use cmdstanr::cmdstan_model without the additional argument compile_model_methods=TRUE, then devtools::install() works fine. However, if I set compile_model_methods=TRUE, it fails. In the below, I replace the code that instantiate uses with cmdstanr code (which it calls), which seems to isolate the bug to cmdstanr. I've got a strong feeling this is to do with my m1 Mac.

To Reproduce

  1. Create a new repo using instantiate::stan_package_create("mypackage")
  2. Create a new RStudio project in the "mypackage" directory
  3. Open the project and run instantiate::stan_package_configure()
  4. Edit the install.libs.R file so that the bottom becomes:
cmdstanr::cmdstan_model(paste0(bin_stan, "/bernoulli.stan"),
                        compile_model_methods=TRUE)

then this returns an error:

Error in dyn.load("/private/var/folders/_f/0kqrxwdn69vgvgb02z2m3kqc0000gp/T/RtmpSf1FcM/sourceCpp-x86_64-apple-darwin17.0-1.0.8/sourcecpp_5c82735ec4f0/sourceCpp_2.so") : unable to load shared object '/private/var/folders/_f/0kqrxwdn69vgvgb02z2m3kqc0000gp/T/RtmpSf1FcM/sourceCpp-x86_64-apple-darwin17.0-1.0.8/sourcecpp_5c82735ec4f0/sourceCpp_2.so': dlopen(/private/var/folders/_f/0kqrxwdn69vgvgb02z2m3kqc0000gp/T/RtmpSf1FcM/sourceCpp-x86_64-apple-darwin17.0-1.0.8/sourcecpp_5c82735ec4f0/sourceCpp_2.so, 0x0006): symbol not found in flat namespace '__ZN3tbb8internal26task_scheduler_observer_v37observeEb'

  • removing ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/example’ Error in (function (command = NULL, args = character(), error_on_status = TRUE, …: ! System command 'R' failed

Expected behavior Package should install. (It does so fine when compile_model_methods=FALSE.)

Operating system Mas OS Monterrey version 12.2.1

CmdStanR version number 0.7.1

Session info

R version 4.1.2 (2021-11-01) Platform: x86_64-apple-darwin17.0 (64-bit) Running under: macOS Monterey 12.2.1

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

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

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

loaded via a namespace (and not attached): [1] pillar_1.9.0 compiler_4.1.2 cmdstanr_0.7.1
[4] remotes_2.4.2 prettyunits_1.1.1 tools_4.1.2
[7] testthat_3.1.2 pkgload_1.2.4 pkgbuild_1.3.1
[10] memoise_2.0.1 lifecycle_1.0.4 tibble_3.2.1
[13] gtable_0.3.4 checkmate_2.3.1 pkgconfig_2.0.3
[16] rlang_1.1.3 cli_3.6.2 rstudioapi_0.15.0
[19] xfun_0.30 fastmap_1.1.0 withr_2.5.2
[22] dplyr_1.1.4 knitr_1.37 desc_1.4.1
[25] generics_0.1.3 fs_1.6.3 vctrs_0.6.5
[28] devtools_2.4.3 rprojroot_2.0.2 grid_4.1.2
[31] tidyselect_1.2.0 glue_1.7.0 R6_2.5.1
[34] processx_3.8.3 fansi_1.0.6 distributional_0.3.2 [37] sessioninfo_1.2.2 tensorA_0.36.2.1 purrr_1.0.2
[40] callr_3.7.0 ggplot2_3.4.4 farver_2.1.1
[43] posterior_1.5.0 magrittr_2.0.3 usethis_2.1.5
[46] backports_1.4.1 scales_1.3.0 ps_1.7.5
[49] ellipsis_0.3.2 abind_1.4-5 instantiate_0.2.0
[52] colorspace_2.1-0 utf8_1.2.4 munsell_0.5.0
[55] cachem_1.0.6 crayon_1.5.0 brio_1.1.3

ben18785 commented 9 months ago

I suspect sometimes relatedly, I get the same error when I call cmdstanr::cmdstan_model from the console and the remedy is to create a new Stan file and compile that instead.

andrjohns commented 9 months ago

The model methods implementation is currently undergoing a fairly significant rework, I'd recommend waiting until that's finished before spending too much time on debugging and workarounds for a package