Permissions error running brms on Windows with "cmdstanr" backend

I’m on a work computer that’s very locked down, except for a single folder that is allowed to run stan executables. When I’m using cmdstanr I can force the use of this permitted directory by running: file <- write_stan_file(model_string, dir=PERMITTED_DIRECTORY); cmdstan_model(file)

However, when I run brms with cmdstanr as backend, it seems to be creating the executable in a folder I’m unable to run exe’s from, and I don’t know how to instruct it to use the permitted directory instead.

Here’s the code and error.

> brm_dat <- data.frame( y = c(1,1,0,0,0,0,0,0,0,0)) # rate=20%
> fit <- brm(y ~ 1, data=brm_dat, backend="cmdstanr")
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, …`:
! create process 'C:/Users/myusername/AppData/Local/Temp/RtmpyQ70cg/model_9498b2bf431fce6a1339956b88be15a0.exe' (system error 1260, This program is blocked by group policy. For more information, contact your system administrator.
) @win/processx.c:1040 (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, …`:
! create process 'C:/Users/myusername/AppData/Local/Temp/RtmpyQ70cg/model_9498b2bf431fce6a1339956b88be15a0.exe' (system error 1260, This program is blocked by group policy. For more information, contact your system administrator.
) @win/processx.c:1040 (processx_exec)
---
Backtrace:
 1. brms::brm(y ~ 1, data = brm_dat, backend = "cmdstanr")
 2. brms::do_call(compile_model, compile_args)
 3. brms:::eval2(call, envir = args, enclos = envir)
 4. base::eval(expr, envir, ...)
 5. base::eval(expr, envir, ...)
 6. local .fun(model = .x1, backend = .x2, threads = .x3, opencl = .x4, …
 7. local .compile_model(model, ...)
 8. brms:::eval_silent(do_call(cmdstanr::cmdstan_model, args), type = "message", …
 9. base::eval(expr, envir)
10. base::eval(expr, envir)
11. brms::do_call(cmdstanr::cmdstan_model, args)
12. brms:::eval2(call, envir = args, enclos = envir)
13. base::eval(expr, envir, ...)
14. base::eval(expr, envir, ...)
15. local .fun(stan_file = .x1)
16. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
17. local initialize(...)
18. cmdstanr:::model_compile_info(self$exe_file())
19. withr::with_path(c(toolchain_PATH_env_var(), tbb_path()), ret <- wsl_compatible_run(command = wsl_safe_path(e…
20. base::force(code)
21. cmdstanr:::wsl_compatible_run(command = wsl_safe_path(exe_file), args = "info", …
22. base::do.call(processx::run, run_args)
23. (function (command = NULL, args = character(), error_on_status = TRUE, …
24. process$new(command, args, echo_cmd = echo_cmd, wd = wd, windows_verbatim_args = windows_verbatim_args, …
25. local initialize(...)
26. processx:::process_initialize(self, private, command, args, stdin, stdout, …
27. processx:::chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …
28. | base::withCallingHandlers(do.call(".Call", list(.NAME, ...)), error = function(e) { …
29. | base::do.call(".Call", list(.NAME, ...))
30. | base::.handleSimpleError(function (e) …
31. | local h(simpleError(msg, call))
32. | processx:::throw_error(err, parent = e)

Is there a way to instruct brms to use a specific folder for the cmdstanr backend?

I get even messier errors when using the default rstan as a backend, so figured I’d try to troubleshoot this first.

Thank you so much.

Here are my specs:
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)
brms_2.17.0

1 Like

Have you tried the global cmdstanr option cmdstanr_write_stan_file_dir? But note that cmdstanr v0.5.2 doesn’t support relative file paths for this option (the GitHub version should, I think). So it’s better to specify the full file path.

cmdstanr v0.5.3 has been released which should allow to specify relative file paths for this option (but I haven’t tried it yet).

@peopletrees

Have you tried brm(file = ..., ...) argument to specify where to save models? Using that argument, you can save brmsfit objects as rds file.

Has there been a solution to this? I’m getting the same error message, but fweber144’s solution with cmdstan_write_stan_file_dir hasn’t worked for me.