Problems Compiling Model

Hello. I’m trying to compile my model after removing the ‘generate quantities’ block and it will not compile now.

The code of the model is below.

data {    
    int<lower=0> N; // number policy term years
    int<lower=0>  NonCatcvrcnt[N]; // claims
    vector[N] alertflag; //alert flag
}

parameters {
    real<lower=0> mu;
    real beta;

}

model {
       mu ~ normal(0,3);
       beta ~ normal(0,1);
       NonCatcvrcnt ~ poisson_log(mu + alertflag*beta);
}

The code to compile the model is below.

reinstatement_model = os.path.join(cmdstan_path(), 'examples', 'poisson', 'reinstatement.stan')
my_model = CmdStanModel(stan_file=reinstatement_model)
my_model.name
my_model.stan_file
my_model.exe_file
my_model.code()

The error being thrown is below.

my_model = CmdStanModel(stan_file=reinstatement_model)
INFO:cmdstanpy:compiling stan program, exe file: C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.exe
INFO:cmdstanpy:compiler options: stanc_options={}, cpp_options={}
ERROR:cmdstanpy:file C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\cmdstan\Library\bin\cmdstan\examples\poisson\reinstatement.stan, exception Command: ['mingw32-make', 'C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.exe']
failed, returncode: 2, error: No such file or directory, stderr: expr: syntax error
/usr/bin/sh: cl.exe: command not found
process_begin: CreateProcess(NULL, cl.exe -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 -x c++ -o C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.o C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.hpp, ...) failed.
make (e=2): The system cannot find the file specified.
mingw32-make: *** [C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.exe] Error 2 
ERROR:cmdstanpy:model compilation failed
Traceback (most recent call last):

  File "C:\Users\JORDAN~1.GIT\AppData\Local\Temp/ipykernel_9424/3325553376.py", line 1, in <module>
    my_model = CmdStanModel(stan_file=reinstatement_model)

  File "C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\cmdstan\lib\site-packages\cmdstanpy\model.py", line 188, in __init__
    raise ValueError(

ValueError: Unable to compile Stan model file: C:\Users\JORDAN.HOWELL.GITDIR\AppData\Local\Continuum\anaconda3\envs\cmdstan\Library\bin\cmdstan\examples\poisson\reinstatement.stan.

Is this a STAN syntax error? It compiled fine when I had the generated quantities block.

Hmm, that’s strange, I don’t think it’s a syntax error. This model seems to compile ok for me (I checked with CmdStanR not CmdStanPy but both use CmdStan to compile). A few questions that might help narrow down the problem:

  • If you add back in the generated quantities block, can you get this to compile successfully again?
  • How about other models? For example, does the example model from the CmdStanPy documentation compile for you?
  • Does the Stan file exist in the right directory? Part of the error message says “The system cannot find the file specified” but I’m not sure if it’s referring to the Stan program (I’m more familiar with the error messages from R than Python).

Also tagging @mitzimorris since she’ll be more familiar with these python error messages.

@Jordan_Howell ,

the error messages are a bit confusing, but my bet would be that the error messages are from the build environment saying that they cannot locate the tool cl.exe:

failed, returncode: 2, error: No such file or directory, stderr: expr: syntax error
/usr/bin/sh: cl.exe: command not found
process_begin: CreateProcess(NULL, cl.exe -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 -x c++ -o C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.o C:/Users/JORDAN.HOWELL.GITDIR/AppData/Local/Continuum/anaconda3/envs/cmdstan/Library/bin/cmdstan/examples/poisson/reinstatement.hpp, ...) failed.
make (e=2): The system cannot find the file specified.

So my guess would be this error has nothing to do with the content of the stan model, and indicates that the dev environment for compiling stan models is broken or misconfigured.

It looks like cl.exe is part of microsoft visual studio: MSVC Compiler Options | Microsoft Docs

You may need to try reinstalling cmdstan and/or ensuring that your CMDSTAN environment variable are set correctly in the terminal session where you are running cmdstanpy

https://cmdstanpy.readthedocs.io/en/latest/getting_started.html

3 Likes

Reinstalling cmdstan fixed it! Thanks to you both.

3 Likes