Sampler hangs


#1

Here is a model that causes hangs such that even CTRL-C won’t stop it. I’m in R 3.2.1 and rstan 2.16.2 on ubunutu. Adding the print statement allow CTRL-C to work (and prints mu alternatively as 3.3 and -nan).

library(rstan)

rstan_options(auto_write = TRUE)

modelcode <- "
data {
}

transformed data {
}

parameters {   
real<lower=3.3,upper=3.5>   mu; 
}

model {
	target += 1/(mu-3.3);
	//print(mu);
}
"

fit <- stan(model_code=modelcode, data=list(), iter=1000, thin=10, chains=1)
print(fit)

#2

Sometimes you have to press Control-C many times to get send an interrupt during the instant when it finishes leapfrogging.

But the sampling is unlikely to go well for this particular Stan program because the log-kernel rises too quickly as mu approaches 3.3.


#3

Whoa. Is that how R handles ctrl-c?

I always assumed it was because we called the interrupt callback once an iteration (instead of once a log prob evaluation).


#4

How many is “many times” :)? I’ve held it down for a few minutes and it doesn’t catch (whereas the print will print out many times a second). I’ve also had a sampler in this state gobble lots of memory in /tmp, although the example that I posted doesn’t seem to (I’ll try to make one that does).


#5

I am not sure why but the interrupt does not always get through.


#6

Here is one that gobbles memory in /tmp:

data {
}
transformed data {
}

parameters {
real<lower=3.3,upper=3.5> mu;
real<lower=1,upper=2> y;
}

model {
y ~ uniform(1,2);
target += y/(mu-3.3);
//print(mu);
}

The stan display hangs after this and doesn’t seem to respond to CTRL-C:

Gradient evaluation took 1.4e-05 seconds
1000 transitions using 10 leapfrog steps per transition would take 0.14 seconds.
Adjust your expectations accordingly!

Iteration: 1 / 1000 [ 0%] (Warmup)
Iteration: 100 / 1000 [ 10%] (Warmup)


#7

Oh I see, in /tmp it outputs this message into a file (but seemingly infinitely):

If this warning occurs sporadically, such as for highly constrained variable types like covariance matrices, then the sampler is fine,
but if this warning occurs often then your model may be either severely ill-conditioned or misspecified.

Informational Message: The current Metropolis proposal is about to be rejected because of the following issue:
Exception: uniform_lpdf: Random variable is -nan, but must not be nan! (in ‘model20e5abb126_fba77484d34fca647ce617c1c39ac9ec’ at line 14)