rmcelreath / rethinking

Statistical Rethinking course and book package
2.1k stars 596 forks source link

Ulam/cmdstan errors #390

Open Lawbarnes opened 1 year ago

Lawbarnes commented 1 year ago

I'm working through the book on my own, and I'm not computer savvy. It's not my generation. In eight grade, I was actually taught to use a slide rule. And didn't pursue a math field (law instead), but I'm here anyway. My problem came in Chapter 9, for first used on Stan. Any help would be appreciated.

m9.1 <- ulam( alist( log_gdp_std ~ dnorm(mu,sigma), mu <- a[cid]+b[cid]*(rugged_std - 0.215), a[cid] ~ dnorm(1,0.1), b[cid] ~ dnorm(0,0.3), sigma ~ dexp(1) ),data=dat_slim, chains = 1 )

Compiling Stan program... Error in (function (command = NULL, args = character(), error_on_status = TRUE, …: ! System command 'make' failed

Exit status: 2 Stderr: make: *** /c/Users/lbarnes/OneDrive: Is a directory. Stop.

torkar commented 1 year ago

Many times working in a OneDrive directory is not good.

rmcelreath commented 1 year ago

Yeah, my guess too is that OneDrive is the problem, given the error message. But I have no experience with OneDrive.

Lawbarnes commented 1 year ago

Thanks. I moved the cmdstan file to a local drive then change the path with set_cmdstan_path(), but I got the same error message. I guess R keeps looking in OneDrive. Still trying to figure out how to fix that.

rok-cesnovar commented 1 year ago

If you just moved the files, that won't work most likely, you need to rebuild cmdstan.

I would actually just run

cmdstanr::install_cmdstan(dir = "THE_NON_ONEDRIVE_DIRECTORY")

And run that. If that does not help, please let me know and we can debug further.

torkar commented 1 year ago

Also make sure to set your work directory to a dir outside OneDrive (I use setwd() in an R terminal)

Lawbarnes commented 1 year ago

Thank you. I really appreciate your help. I ran

cmdstanr::install_cmdstan(dir = "THE_NON_ONEDRIVE_DIRECTORY")

And got the same error. Here's more details on the error. I don't know enough about R to decipher it. I can't tell if the error is originating in rethinking then flowing down. Honestly, I don't know what's going on.

Error in (function (command = NULL, args = character(), error_on_status = TRUE, …: ! System command 'make' failed

Exit status: 2 Stderr: make: *** /c/Users/lbarnes/OneDrive: Is a directory. Stop.

Backtrace:

  1. rethinking::ulam(alist(log_gdp_std ~ dnorm(mu, sigma), mu <- a[cid] + b[cid] …
  2. cmdstanr::cmdstan_model(stan_file = filex[[1]], compile = filex[[3]], cpp_o…
  3. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
  4. local initialize(...)
  5. self$compile(...)
  6. cmdstanr:::get_cmdstan_flags("STANCFLAGS")
  7. cmdstanr:::wsl_compatible_run(command = "make", args = c(paste0("print-", …
  8. base::do.call(processx::run, run_args)
  9. (function (command = NULL, args = character(), error_on_status = …
    1. processx:::throw(new_process_error(res, call = sys.call(), echo = echo, …
bardolater commented 1 year ago

This behavior looks a lot like the one I just posted, except I'm not using OneDrive and my Cmdstan path is set to:

/Users/bardolater/.cmdstan/cmdstan-2.31.0

torkar commented 1 year ago

@bardolater I guess you've done cmdstanr::install_cmdstan(overwrite=TRUE)? @Lawbarnes have you asked about this at https://discourse.mc-stan.org?

bardolater commented 1 year ago

I did not, but that seems to have corrected the issue. I can run the code and get output. Thank you!

On Fri, Apr 7, 2023 at 3:56 AM Richard Torkar @.***> wrote:

@bardolater https://github.com/bardolater I guess you've done cmdstanr::install_cmdstan(overwrite=TRUE)? @Lawbarnes https://github.com/Lawbarnes have you asked about this at https://discourse.mc-stan.org?

— Reply to this email directly, view it on GitHub https://github.com/rmcelreath/rethinking/issues/390#issuecomment-1500042026, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6K2EVEXABFKBQWVYPYVXLW77CBHANCNFSM6AAAAAAUSOM5AU . You are receiving this because you were mentioned.Message ID: @.***>

-- Sam Van Horne

stashlee00 commented 12 months ago

Hello, I'm a coding novice and have a similar problem to Lawbarnes that I would really appreciate help with. Everything was going smoothly until R code 9.14. I've tried many different solutions posted online, including reinstalling Rstan and CmdStanR many different ways, but still no success, although the errors I get when running code 9.14 have evolved. I'm running R version 4.3.0 in Windows 11. Below is a brief summary of some of the errors I have gotten and solutions I have tried. Thanks in advance!

1st error: could not find function "ulam" Installing Rstan via the code below (from https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows) seemed to fix this: install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos"))) install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

2nd error: CmdStan path has not been set yet. See ?set_cmdstan_path. After trying different ways of installing CmdStanR the error changed to...

3rd error: Can't find CmdStan makefile to detect version number. Path may not point to valid installation. After trying still other ways of installing CmdStanR the error changed to...

4th error: Rtools42 was not found but is required to run CmdStan with R version 4.3.0. Please install Rtools42 and run cmdstanr::check_cmdstan_toolchain().

Then I added the following to PATH under System Variables: C:\rtools43 C:\rtools43\mingw64\bin C:\rtools43\usr\bin C:\Users\z3389438\AppData\Local\R\win-library\4.3\cmdstanr\cmdstan-2.32.2 C:\Users\z3389438\AppData\Local\R\win-library\4.3\cmdstanr\cmdstan-2.32.2\stan\lib\stan_math\lib\tbb

And I ran the following in Rtools43 Bash (from https://discourse.mc-stan.org/t/problem-installing-cmdstan-with-r4-2-and-rtools42/28846/5) rm -rf /var/cache/pacman/pkg/* rm -r /etc/pacman.d/gnupg/ pacman-key --init pacman-key --populate msys2 pacman -S msys2-keyring pacman -Syyu pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc pacman -Syu mingw-w64-x86_64-make

5th error: Compiling Stan program... Error in process_initialize(self, private, command, args, stdin, stdout, …: ! Native call to processx_exec failed Caused by error in chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …: ! Command 'mingw32-make.exe' not found @win/processx.c:982 (processx_exec) Type .Last.error to see the more details.

.Last.error <c_error/rlib_error_3_0/rlib_error/error> Error in process_initialize(self, private, command, args, stdin, stdout, …: ! Native call to processx_exec failed Caused by error in chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …: ! Command 'mingw32-make.exe' not found @win/processx.c:982 (processx_exec)

Backtrace:

  1. rethinking::ulam(alist(log_gdp_std ~ dnorm(mu, sigma), mu <- a[cid] + b[cid] * …
  2. cmdstanr::cmdstan_model(stan_file = filex[[1]], compile = filex[[3]], cpp_options = cpp_options, …
  3. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
  4. local initialize(...)
  5. self$compile(...)
  6. withr::with_path(c(toolchain_PATH_env_var(), tbb_path()), run_log <- wsl_compatible_run(com…
  7. base::force(code)
  8. cmdstanr:::wsl_compatible_run(command = make_cmd(), args = c(wsl_safe_path(tmp_exe), …
  9. base::do.call(processx::run, run_args)
  10. (function (command = NULL, args = character(), error_on_status = TRUE, …
  11. process$new(command, args, echo_cmd = echo_cmd, wd = wd, windows_verbatim_args = windows_ve…
  12. local initialize(...)
  13. processx:::process_initialize(self, private, command, args, stdin, stdout, …
  14. processx:::chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …
  15. | base::withCallingHandlers(do.call(".Call", list(.NAME, ...)), error = function(e) { …
  16. | base::do.call(".Call", list(.NAME, ...))
  17. | base::.handleSimpleError(function (e) …
  18. | local h(simpleError(msg, call))
  19. | processx:::throw_error(err, parent = e)
stashlee00 commented 8 months ago

I found a solution to this problem caused by institutional use of OneDrive over at the Stan forums [https://discourse.mc-stan.org/t/system-command-make-failed-models-wont-compile/30528/18?u=stashlee00]. All I needed to do was delete the empty folder that starts with “OneDrive”:

C:\Users\first-last\OneDrive (I deleted this one which was empty) C:\Users\first-last\OneDrive - MMC (This one had OneDrive files in it - I did not delete it)