Stanc3 compile-failure message for model compiled using rstan

Hello,

While exploring stan, I have the following message:

When you compile models, you are also contributing to development of the NEXT
Stan compiler. In this version of rstan, we compile your model as usual, but
also test our new compiler on your syntactically correct model. In this case,
the new compiler did not work like we hoped. By filing an issue at
https://github.com/stan-dev/stanc3/issues with your model
or a minimal example that shows this warning you will be contributing

functions{// function below generate truncated exponential
  real exponential_ub_rng(real beta, real ub) {
    real p = exponential_cdf(ub, beta);  // cdf for bounds
    real u = uniform_rng(0, p);
    return (-log1m(u) / beta);  // inverse cdf for value
  }
}
data {
    int<lower=1> N_uncensored;                                      
    int<lower=1> N_censored;                                        
    int<lower=0> NC;                                                
    matrix[N_censored,NC] X_censored;                               
    matrix[N_uncensored,NC] X_uncensored;                           
    vector<lower=0>[N_censored] times_censored;                          
    vector<lower=0>[N_uncensored] times_uncensored;                      
}
transformed data {// used when create event time conditiona on they are smaller than a max time;
    real max_time;
    real max_time_censored;
    max_time = max(times_uncensored);
    max_time_censored = max(times_censored);
    if(max_time_censored > max_time) max_time = max_time_censored;
}
parameters {
    vector[NC] betas;                                     
    real intercept;                                 
}
model {
    betas ~ normal(0,2);                                                            
    intercept ~ normal(-5,2);                                                     
    target += exponential_lpdf(times_uncensored | exp(intercept+X_uncensored*betas)); 
    target += exponential_lccdf(times_censored | exp(intercept+X_censored*betas));  
}
generated quantities {
    vector[N_uncensored] times_uncensored_sampled;
    for(i in 1:N_uncensored) times_uncensored_sampled[i] = exponential_ub_rng(exp(intercept+X_uncensored[i,]*betas), max_time);
}
1 Like

What version of rstan are you using? The model still compiles, right?

With the latest version of cmdstanr (2.25), it compiles fine (code below), so I suspect the rstan version you’re using is just using an outdated version of stanc3.

library(tidyverse)
library(cmdstanr)

stan_code = '
functions{// function below generate truncated exponential
  real exponential_ub_rng(real beta, real ub) {
    real p = exponential_cdf(ub, beta);  // cdf for bounds
    real u = uniform_rng(0, p);
    return (-log1m(u) / beta);  // inverse cdf for value
  }
}
data {
    int<lower=1> N_uncensored;                                      
    int<lower=1> N_censored;                                        
    int<lower=0> NC;                                                
    matrix[N_censored,NC] X_censored;                               
    matrix[N_uncensored,NC] X_uncensored;                           
    vector<lower=0>[N_censored] times_censored;                          
    vector<lower=0>[N_uncensored] times_uncensored;                      
}
transformed data {// used when create event time conditiona on they are smaller than a max time;
    real max_time;
    real max_time_censored;
    max_time = max(times_uncensored);
    max_time_censored = max(times_censored);
    if(max_time_censored > max_time) max_time = max_time_censored;
}
parameters {
    vector[NC] betas;                                     
    real intercept;                                 
}
model {
    betas ~ normal(0,2);                                                            
    intercept ~ normal(-5,2);                                                     
    target += exponential_lpdf(times_uncensored | exp(intercept+X_uncensored*betas)); 
    target += exponential_lccdf(times_censored | exp(intercept+X_censored*betas));  
}
generated quantities {
    vector[N_uncensored] times_uncensored_sampled;
    for(i in 1:N_uncensored) times_uncensored_sampled[i] = exponential_ub_rng(exp(intercept+X_uncensored[i,]*betas), max_time);
}
'

mod = 
	(
		stan_code
		%>% cmdstanr::write_stan_file()
		%>% cmdstanr::cmdstan_model()
	)

1 Like