Rstan - constrain_pars fails with cholesky, log_prob and gradient are fine

I’ve often found the cholesky behaviour a little spooky, here I have an example I can really pin down and make no sense of… loading the following two files (a stanmodel and standata object), log_prob and the gradient work fine, but constrain_pars generates a nan cholesky issue. I have managed to change something seemingly unrelated and make the glitch go away, I just wonder if a) I’m misunderstanding something, or b) there is a bug somewhere. I thought if the gradient was successfully computed, and it’s not an issue in generated quantities, there should be no reason for a cholesky failure during constrain_pars .

[https://www.dropbox.com/s/gazx9nlkccj0iel/sd.rda?dl=0]
[https://www.dropbox.com/s/ab6y95ktu1b2tyf/sm.rda?dl=0]

library(rstan)
sf <- sampling(sm,iter=0,chains=0,init=0,data=sd,check_data=FALSE,
  control=list(max_treedepth=0),save_warmup=FALSE,test_grad=FALSE)
pars <- rep(0,get_num_upars(sf))
log_prob(sf,pars,gradient=TRUE)
constrain_pars(sf,pars) 

Error in object@.MISC$stan_fit_instance$constrain_pars(upars) :
Exception: cholesky_decompose: m is not symmetric. m[1,2] = nan, but m[2,1] = nan (in ‘model_ctsm’ at line 882)

1 Like

Could you please provied the code of the model (as an attachment or inline in the post)? Having to jump through an .rda file is not great :-)

But at first glance it looks like a bug - could you try to get the smallest model that triggers the error?

Thanks!

small models are not my specialty unfortunately, I didn’t want to paste the 1000 odd lines here. It may take me quite a while to work out a small model, I was hoping the line where the error occurs might provide enough guide, but I’ll try and get back to this!