C++ failure while compiling cmdstanpy model with reduce_sum_static

Hello all. My model with reduce_sum_static fials to compile with the error that begins with the following (the entire error is really long):

ROR:cmdstanpy:file model.stan, exception ERROR
 In file included from /include/c++/4.9.3/bits/move.h:57:0,
                 from /include/c++/4.9.3/bits/stl_pair.h:59,
                 from /include/c++/4.9.3/bits/stl_algobase.h:64,
                 from /include/c++/4.9.3/bits/char_traits.h:39,
                 from /include/c++/4.9.3/ios:40,
                 from /include/c++/4.9.3/istream:38,
                 from /include/c++/4.9.3/sstream:38,
                 from /include/c++/4.9.3/complex:45,
                 from stan/lib/stan_math/lib/eigen_3.3.7/Eigen/Core:96,
                 from stan/lib/stan_math/lib/eigen_3.3.7/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,
                 from stan/lib/stan_math/stan/math.hpp:19,
                 from stan/src/stan/model/model_header.hpp:4,
                 from model.hpp:3:
/include/c++/4.9.3/type_traits:512:12: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ?struct std::__or_<std::is_lvalue_reference<std::_Tuple_impl<63ul, const int&>&>, std::is_rvalue_reference<std::_Tuple_impl<63ul, const int&>&> >?
     struct is_reference
            ^ 

The model is attached. Any ideas what’s wrong will be highly highly appreciated!

model.txt (6.6 KB)

The model you supplied has a syntax error:

functions {

real partial_sum(real[] dummy, int start, int end, real[,] X, vector mu_prior_x, real sigma_v,
                                matrix A, matrix B, real[,,] U, real Q, matrix C, real sigma_r,

                                int[,,] pressed_gng, int[,,] cue_gng, real[,,] outcome_gng, int[,] Tr_gng, int[] idx_gng_obs, 
                                real[] b_gng_pr, real[] pi_gng_pr, real[] xi_gng_pr, real[] ep_gng_pr, real[] rho_gng_pr,
                                real[] b_gng, real[] pi_gng, real[] xi_gng, real[] ep_gng, real[] rho_gng, vector initV_gng, int Bl) {   

    real lt = 0;

    if (w == 1) {                                           
        lt += normal_lpdf(to_vector(X[start,])|mu_prior_x,sigma_v);                           
    }     

w is not defined before that.

Also please specify the C++ compiler & OS.

So sorry, I attached the wrong model file. Even with w I get the same error.
OS is centOS7 and C++ compiler is 4.9.3

model.txt (6.6 KB)

Oh, so you only got the sysadmins to upgrade from 4.8 to 4.9.3? That is unfortunate as that is quite an old compiler (5years+). It should still work though.

The generated C++ from your Stan model is complex and g++ 4.9.3 is not the most efficient with it so its default settings are not able to handle compiling it. Let’s see if setting the limits higher would work:

Put
CXXFLAGS_PROGRAM += -ftemplate-depth=2000
in your make/local.

FTR the model compiles fine with default settings with g++ 9.3.0 and clang++.

@syclik @stevebronder @Bob_Carpenter @bbbales2 @wds15 @tadej

Just a heads up that we might really need to start thinking about setting the compiler bar a bit higher than g++ 4.9.3 or we will need to stop increasing compile-time complexity of our codebase.

We might get around it with overriding defaults for some more time, but not much longer.

Yup. That’s what major version bumps can be used for.

That’s super helpful! Is there a tutorial on how to make changes to make/local? Bc I saw I will have to edit make/local also to make MPI work.

Thanks!

The instructions are:

In your cmdstan folder (if you installed with cmdstanpy check the home folder for .cmdstanpy) you should find a folder named make. Create a file named local in it and put the above line in that file.

Linking to the previous discussion here

The tl;dr is that if we want to bump up we should get C++17 along the way. we could bump up to gcc-7* and leave clang* as is. But to do this we need to fixup the pystan wheel builder so that it uses the python package docker builder with gcc-8. I’m for having a 2-3 months deprecation notice before the bump (so about 9 month deprecation notice)

*clang-6 has c++17 support but there are some defect reports that weren’t resolved till later version. Same goes for gcc-7 where some defect reports weren’t resolved till gcc-8.

UPDATE - I updated to g++ 9.3.0 and the model compiled just fine, but I have a sampling error now:

RuntimeError: Error during sampling.
chain 1 returned error code -11

Should I recomplie cmdstan from scratch using g++ 9.3.0, or that’s fine using the cmdstan version I downloaded with g++ 4.9.3 loaded?

You definitely need to recompile cmdstan.

Update 2 - the model compiles and begins to sample, but now exists with :

   raise RuntimeError(err_msg)
RuntimeError: Error during sampling.
chain 1 returned error code 70

Same happens for another model that worked just fine with g++ 4.9.3.

Autofix – it failed bc of bad initial values, which I changed and it samples alright now. Thanks!

So is error code 70 get triggered because of bad initial values?

You can read more on this here:

But in my code it was solved after changing the initial values.