Cannot run bernoulli.stan example in cmdstanr

Successfully installed CmdStan using the C++ compiler toolchain route and a clone of the github repo (having been unable to get fresh conda env installs to work at all) into C:\ProgramData\cmdstan. Then followed all requirements to add environment variable (system) paths, including:

CMDSTAN: C:\ProgramData\cmdstan
PATH: C:\ProgramData\cmdstan\stan\lib\stan_math\lib\tbb

Opened RStudio and successfully installed cmdstanr

install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

Started to follow the instructions for running the bernoulli.stan example Getting started with CmdStanR • cmdstanr, library calls worked ok:

This is cmdstanr version 0.7.0
- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
- CmdStan path: C:/ProgramData/cmdstan
- CmdStan version: 2.33.1

Then ran the command to run the bernoulli model, and got a load of error messages out, indicating one of the stan executables is not a valid Win32 application - this is on 64-bit Windows, with 64-bit stan install, running via 64-bit RStudio:

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 'bin/stanc.exe' (system error 193, %1 is not a valid Win32 application.
) @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 'bin/stanc.exe' (system error 193, %1 is not a valid Win32 application.
) @win/processx.c:1040 (processx_exec)
---
Backtrace:
 1. cmdstanr::cmdstan_model(file)
 2. CmdStanModel$new(stan_file = stan_file, exe_file = exe_file, …
 3. local initialize(...)
 4. self$compile(...)
 5. cmdstanr:::get_standalone_hpp(temp_stan_file, stancflags_standalone)
 6. withr::with_path(c(toolchain_PATH_env_var(), tbb_path()), wsl_compatible_run(command = stanc_cmd(), …
 7. base::force(code)
 8. cmdstanr:::wsl_compatible_run(command = stanc_cmd(), args = c(stan_file, …
 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_verbatim_args, …
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)

Having now tried and failed to get stan to work with Julia, Python and now R, this is really starting to seem like one software package that does not want to be used. At least, by anyone running on Windows…

Operating System: Windows 11 Pro Build 22631.2861
Interface Version: cmdstanr 0.7.0, CmdStan 2.33.1

Can you try running cmdstanr::rebuild_cmdstan() and then try again?

I’ve reinstalled cmdstan to a '<User>' directory and updated path variables accordingly. I’ve then run cmdstanr::rebuild_cmdstan() and the install rebuilt ok (I had to use admin launch of RStudio to get that to work). I’ve then tried to run the example, and it now gets past the previous error, on to a new error:

In file included from stan/lib/stan_math/lib/boost_1.81.0/boost/multi_array/multi_array_ref.hpp:32,
                 from stan/lib/stan_math/lib/boost_1.81.0/boost/multi_array.hpp:34,
                 from stan/lib/stan_math/lib/boost_1.81.0/boost/numeric/odeint/algebra/multi_array_algebra.hpp:22,
                 from stan/lib/stan_math/lib/boost_1.81.0/boost/numeric/odeint.hpp:63,
                 from stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9,
                 from stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6,
                 from stan/lib/stan_math/stan/math/prim/functor.hpp:16,
                 from stan/lib/stan_math/stan/math/rev/fun.hpp:200,
                 from stan/lib/stan_math/stan/math/rev.hpp:10,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4,
                 from C:/Users/m_lot/AppData/Local/Temp/RtmpUnl9rj/model-308821e16952.hpp:2:
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:180:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  180 |         : public boost::functional::detail::unary_function<typename unary_traits<Predicate>::argument_type,bool>
      |                                             ^~~~~~~~~~~~~~

In file included from C:/rtools43/ucrt64/include/c++/13.2.0/string:49,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/bits/locale_classes.h:40,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/bits/ios_base.h:41,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/ios:44,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/istream:40,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/sstream:40,
                 from C:/rtools43/ucrt64/include/c++/13.2.0/complex:45,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Core:50,
                 from stan/lib/stan_math/lib/eigen_3.4.0/Eigen/Dense:1,
                 from stan/lib/stan_math/stan/math/prim/fun/Eigen.hpp:22,
                 from stan/lib/stan_math/stan/math/rev.hpp:4:
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:214:45: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  214 |         : public boost::functional::detail::binary_function<
      |                                             ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:252:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  252 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:299:45: warning: 'template<cl
ass _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  299 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:345:57: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  345 |     class mem_fun_t : public boost::functional::detail::unary_function<T*, S>
      |                                                         ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:361:58: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  361 |     class mem_fun1_t : public boost::functional::detail::binary_function<T*, A, S>
      |                                                          ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:377:63: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  377 |     class const_mem_fun_t : public boost::functional::detail::unary_function<const T*, S>
      |                                                               ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:393:64: warning: 
'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  393 |     class const_mem_fun1_t : public boost::functional::detail::binary_function<const T*, A, S>
      |                                                                ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:438:61: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  438 |     class mem_fun_ref_t : public boost::functional::detail::unary_function<T&, S>
      |                                                             ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:454:62: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  454 |     class mem_fun1_ref_t : public boost::functional::detail::binary_function<T&, A, S>
      |                                                              ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:470:67: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  470 |     class const_mem_fun_ref_t : public boost::functional::detail::unary_function<const T&, S>
      |                                                                   ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function

      |            ^~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:487:68: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  487 |     class const_mem_fun1_ref_t : public boost::functional::detail::binary_function<const T&, A, S>
      |                                                                    ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:533:73: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  533 |     class pointer_to_unary_function : public boost::functional::detail::unary_function<Arg,Result>
      |                                                                         ^~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.81.0/boost/functional.hpp:557:74: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  557 |     class pointer_to_binary_function : public boost::functional::detail::binary_function<Arg1,Arg2,Result>
      |                                                                          ^~~~~~~~~~~~~~~
C:/rtools43/ucrt64/include/c++/13.2.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~

In file included from stan/lib/stan_math/stan/math/prim/prob/von_mises_lccdf.hpp:5,
                 from stan/lib/stan_math/stan/math/prim/prob/von_mises_ccdf_log.hpp:4,
                 from stan/lib/stan_math/stan/math/prim/prob.hpp:359,
                 from stan/lib/stan_math/stan/math/prim.hpp:16,
                 from stan/lib/stan_math/stan/math/rev.hpp:14:
stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp: In function 'stan::return_type_t<T_x, T_sigma, T_l> stan::math::von_mises_cdf(const T_x&, const T_mu&, const T_k&)':
stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
  194 |       if (cdf_n < 0.0)
      | 

stan/lib/stan_math/stan/math/prim/prob/von_mises_cdf.hpp:194: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory

Error in file(con, "r") : cannot open the connection