Unable to install cmdstan: Could not find files for the given pattern(s)

Hi all, I’ve been having consistent issues with Rstudio crashing after fitting a model via rstan, with an error message starting with C stack trace (as described here. Interestingly, this only happens on windows 10 but not linux (on the same machine). I saw a recommendation to try cmdstanr in place of rstan which was less prone to this issue. However, I cannot get it to work. The code I have run is:

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

The first two lines work fine but the last gives this error:

The C++ toolchain required for CmdStan is setup properly!
* Latest CmdStan release is v2.27.0
* Installing CmdStan v2.27.0 in C:/Users/lachy/Documents/.cmdstanr/cmdstan-2.27.0
* Downloading cmdstan-2.27.0.tar.gz from GitHub...
* Download complete
* Unpacking archive...
* Building CmdStan binaries...
INFO: Could not find files for the given pattern(s).
cp bin/windows-stanc bin/stanc.exe
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include   -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_5.7.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS         -c -fvisibility=hidden -o bin/cmdstan/stansummary.o src/cmdstan/stansummary.cpp
g++ -std=c++1y -m64 -D_REENTRANT -Wall -Wno-unused-function -Wno-uninitialized -Wno-unused-but-set-variable -Wno-unused-variable -Wno-sign-compare -Wno-unused-local-typedefs -Wno-int-in-bool-context -Wno-attributes -Wno-ignored-attributes      -I stan/lib/stan_math/lib/tbb_2020.3/include   -O3 -I src -I stan/src -I lib/rapidjson_1.1.0/ -I lib/CLI11-1.9.1/ -I stan/lib/stan_math/ -I stan/lib/stan_math/lib/eigen_3.3.9 -I stan/lib/stan_math/lib/boost_1.75.0 -I stan/lib/stan_math/lib/sundials_5.7.0/include  -D_USE_MATH_DEFINES  -DBOOST_DISABLE_ASSERTS         -c -fvisibility=hidden -o bin/cmdstan/print.o src/cmdstan/print.cpp

The following are in my PATH:

C:\rtools40\usr\bin
C:\rtools40\mingw64\bin

I am on Windows 10, R version 4.1.0, and Rstudio version 1.4.1717

Thank you in advance for any help!

2 Likes

Hi,
sorry for not getting to you earlier - did you manage to resolve the issue in the meantime?

In any case this looks like something @andrjohns or @rok_cesnovar might want to look into for making the installation even more robust.

Martin

Hi Martin, thanks for getting back to me. No, no solution as of yet. It isn’t too pressing since I still have access to rstan.

But these C-stack trace errors are painful and if I can avoid them by using cmdstanr instead of rstan I would like to.

Hey,
this message:

is not actually that problematic. Its just an informational message that pops up on Windows (some patterns used when building only work for Linux not on Windows), but can be ignored. Will look into removing them, but this should not be problematic.

As there is actually no error there, what happens if you do

library(cmdstanr)
file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)
data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
fit <- mod$sample(
  data = data_list,
  seed = 123,
  chains = 4,
  parallel_chains = 4,
  refresh = 500
)
2 Likes

Well, I feel like a bit of a dope. In my defense, the message is printed in scary red text!

I re-ran the installation procedure (allowing it to actually finish this time), which seemed to work:

install_cmdstan(cores = 2, overwrite = T)

Then I ran the suggested code which produced:

Running MCMC with 4 parallel chains...

Warning: Chain 1 finished unexpectedly!

Warning: Chain 2 finished unexpectedly!

Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 0.0 seconds.
Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 finished in 0.1 seconds.
Warning: 2 chain(s) finished unexpectedly!
The remaining chains had a mean execution time of 0.6 seconds.
Warning: The returned fit object will only read in results of successful chains. Please use read_cmdstan_csv() to read the results of the failed chains separately.Use the $output(chain_id) method for more output of the failed chains.

I noticed that the install_cmdstan() output requested that I add the following to path:

C:/..../Documents/.cmdstanr/cmdstan-2.27.0/stan/lib/stan_math/lib/tbb

After doing so, the model samples like it should:

Running MCMC with 4 parallel chains...

Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 1 finished in 0.0 seconds.
Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 2 finished in 0.0 seconds.
Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 3 finished in 0.0 seconds.
Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
Chain 4 finished in 0.0 seconds.

All 4 chains finished successfully.
Mean chain execution time: 0.0 seconds.
Total execution time: 0.4 seconds.

So I think I am all good! Thanks a lot for the help!

2 Likes

Dont feel like that. This is on us, that red text is misleading and definitely scary.

Glad you fixed it!

3 Likes