Cmdstanr can no longer find include file

After upgrading cmdstanr from 0.5.2 to 0.5.3, I getting “could not find include file” errors. I’m using cmdstan 2.30.1. Here’s a simple example:

Model file test.stan

data {
#include test_include.stan
  
  int<lower=0> N;
  vector[N] y;
}

parameters {
  real mu;
  real<lower=0> sigma;
}

model {
  y ~ normal(mu, sigma);
}

Include file test_include.stan

int abc;

Output

> dir(pattern = "test.*.stan")
[1] "test_include.stan" "test.stan" 
> cmdstan_model("test.stan", quiet = FALSE)
Compiling Stan program...

--- Translating Stan model to C++ code ---
bin/stanc  --o=/home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.hpp /home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.stan
Syntax error in '/home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.stan', line 2, column 0, include error:
   -------------------------------------------------
     1:  data {
     2:  #include test_include.stan
         ^
     3:    
     4:    int<lower=0> N;
   -------------------------------------------------

Could not find include file test_include.stan in specified include paths.
Syntax error in '/home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.stan', line 2, column 0, include error:
   -------------------------------------------------
     1:  data {
     2:  #include test_include.stan
         ^
     3:    
     4:    int<lower=0> N;
   -------------------------------------------------

Could not find include file test_include.stan in specified include paths.

make: *** [make/program:50: /home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.hpp] Error 1
make: *** [make/program:50: /home/karim/Code/rtemp/Rtmp2RffNR/model-3cc9c15d3306f.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

Hi!

I’ve been having the exact same issue with cmdstanr 0.5.3 and cmdstan 2.31.0 running on Manjaro Linux 6.1.12-1 (22.0.4. Sikaris).

Have you managed to find a solution to the issue?

I’ve tried prepending the file name with / to no luck. I’ve also checked and rechecked the file names and paths multiple times, but there doesn’t seem to be an issue (both files are in the same folder, and I don’t get an error for the main file, just the one included).

@rok_cesnovar @jonah

I just tried and I’m not able to reproduce this on my Mac unfortunately, or fortunately, depending on your perspective ;)

@rok_cesnovar or @andrjohns are either of you able to reproduce this error?

It seems like the above file was compiled in a temporary location, so possibly the included file isn’t being copied over? Does cmdstanr copy to temp locations to avoid things like spaces in paths?

1 Like

This is the reprex for my situation:

stan_main.stan:

generated quantities {
    #include stan_include.stan

    a = normal_rng(0, 1);
}

stan_include.stan:

real a;

main.R:

library(cmdstanr)

m <- cmdstan_model(
  "stan_main.stan",
  include_paths = "/tmp/stan_includes/"
)

sessionInfo():

R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Manjaro Linux

Matrix products: default
BLAS:   /usr/lib/libblas.so.3.11.0
LAPACK: /usr/lib/liblapack.so.3.11.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=hr_HR.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=hr_HR.UTF-8   
 [6] LC_MESSAGES=en_US.UTF-8    LC_PAPER=hr_HR.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=hr_HR.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] cmdstanr_0.5.3  nvimcom_0.9-144

loaded via a namespace (and not attached):
 [1] knitr_1.42           magrittr_2.0.3       tidyselect_1.2.0     munsell_0.5.0        colorspace_2.1-0     R6_2.5.1             rlang_1.0.6         
 [8] fansi_1.0.4          dplyr_1.1.0          tools_4.2.2          grid_4.2.2           checkmate_2.1.0      gtable_0.3.1         xfun_0.37           
[15] utf8_1.2.3           cli_3.6.0            withr_2.5.0          posterior_1.4.0      abind_1.4-5          tibble_3.2.0         lifecycle_1.0.3     
[22] processx_3.8.0       tensorA_0.36.2       farver_2.1.1         ggplot2_3.4.1        ps_1.7.2             vctrs_0.5.2          glue_1.6.2          
[29] compiler_4.2.2       pillar_1.8.1         generics_0.1.3       scales_1.2.1         backports_1.4.1      distributional_0.3.1 jsonlite_1.8.4      
[36] pkgconfig_2.0.3 

getwd():

[1] "/tmp/stan_includes"

list.files():

[1] "main.R"            "stan_include.stan" "stan_main.stan" 

Output of running code in main.R:

Compiling Stan program...
Syntax error in '/tmp/RtmpwsQqiU/model-173245198317a.stan', line 2, column 4, include error:
   -------------------------------------------------
     1:  generated quantities {
     2:      #include stan_include.stan
             ^
     3:  
     4:      a = normal_rng(0, 1);
   -------------------------------------------------

Could not find include file stan_include.stan in specified include paths.

make: *** [make/program:50: /tmp/RtmpwsQqiU/model-173245198317a.hpp] Error 1

Error: An error occured during compilation! See the message above for more information.

I’m really not sure what could be the case. I’ve previously successfully used the functionality on the same OS (but more than six months ago); I’ve tried rerunning the old code, and got the same error message.

I believe this is resolved in the Github version of cmdstanr. Can you run remotes::install_github("stan-dev/cmdstanr"), then restart your session and try again?

4 Likes

Hi, thanks a lot for the tip. Installing the GitHub version really did the trick!

1 Like