What does this error mean?

1,942 views
Skip to first unread message

Raghu Naik

unread,
Aug 25, 2015, 8:19:05 AM8/25/15
to Stan users mailing list
I am trying to understand this error. Sometimes, after I get this error and then submit the stan command again, the model compiles without any errors. I am using RStan (Version 2.7.0-2, packaged: , GitRev: 05c3d0058b6a) . Regards. Raghu.

here are whatever error messages were returned
[[1]]
Stan model '775b8fa18dd0085db432687f0b77614a' does not contain samples.

Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug

Ben Goodrich

unread,
Aug 25, 2015, 9:12:34 AM8/25/15
to Stan users mailing list

 Not much, except you should do it with chains = 1 to see the real error messages. Parallelism is for working chains.

Ben

Bob Carpenter

unread,
Aug 25, 2015, 10:34:55 AM8/25/15
to stan-...@googlegroups.com
It's probably an issue with initial values, which is
usually due to variables who pass all declared constraints
but do not have support in the defined model.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lei Zhang

unread,
Aug 26, 2015, 12:43:03 PM8/26/15
to Stan users mailing list
Hi,

I've encountered the same error message several times, even when I've already set chain=1. After careful debug (mostly by hand), I figured them out. 
In short, I agree with Bob, and several mis-declaration could cause this error. Plus, This error message is really not informative, is it possible to make it more specific in future versions of Stan?

Either way, I would share my own experience with this error message. 

EX1. beta(a,b) does not allow a (or/and b) = 0
EX2. x[i]/sum(x) when sum(x)=0, in this case, you could try x[i]/ (sum(x) + machine_precision() )
EX3. the dimension of your parameters is ill specified

L.

Bob Carpenter

unread,
Aug 26, 2015, 12:47:55 PM8/26/15
to stan-...@googlegroups.com

> On Aug 26, 2015, at 12:43 PM, Lei Zhang <bnuzhan...@gmail.com> wrote:
>
> Hi,
>
> I've encountered the same error message several times, even when I've already set chain=1. After careful debug (mostly by hand), I figured them out.
> In short, I agree with Bob, and several mis-declaration could cause this error. Plus, This error message is really not informative, is it possible to make it more specific in future versions of Stan?

Absolutely --- could you let us know exactly what the error message
was and what you'd like it to say? We want to make these interpretable
to our users.

> Either way, I would share my own experience with this error message.
>
> EX1. beta(a,b) does not allow a (or/and b) = 0

Correct --- it's undefined.

> EX2. x[i]/sum(x) when sum(x)=0, in this case, you could try x[i]/ (sum(x) + machine_precision() )

Divide by zero creates NaN. But you probably do not want to do
x[i] / machine_precision() as that will just produce
roughly 1e15 * x[i], which is probably not what you want.

> EX3. the dimension of your parameters is ill specified

Not sure what you mean here. Our vectorization requires all args to
be either scalars or the same size container.

- Bob

Lei Zhang

unread,
Aug 26, 2015, 1:41:03 PM8/26/15
to Stan users mailing list
Hi Bob,


On Wednesday, August 26, 2015 at 6:47:55 PM UTC+2, Bob Carpenter wrote:

> On Aug 26, 2015, at 12:43 PM, Lei Zhang <bnuzhan...@gmail.com> wrote:
>
> Hi,
>
> I've encountered the same error message several times, even when I've already set chain=1. After careful debug (mostly by hand), I figured them out.
> In short, I agree with Bob, and several mis-declaration could cause this error. Plus, This error message is really not informative, is it possible to make it more specific in future versions of Stan?

Absolutely --- could you let us know exactly what the error message
was and what you'd like it to say?  We want to make these interpretable
to our users.

My error message is exactly the same as in the original post.
something like:
here are whatever error messages were returned
[[1]]
Stan model [MY MODEL NAME] does not contain samples.

Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug
> Either way, I would share my own experience with this error message.
>
> EX1. beta(a,b) does not allow a (or/and b) = 0

Correct --- it's undefined.

> EX2. x[i]/sum(x) when sum(x)=0, in this case, you could try x[i]/ (sum(x) + machine_precision() )

Divide by zero creates NaN.  But you probably do not want to do
x[i] / machine_precision() as that will just produce
roughly 1e15 * x[i], which is probably not what you want.

In this example, have a 4-element non-negative vector x. I was trying to normalize it by doing x[i]/sum(x).
In some cases, sum[x]=0. This only happens occasionally, so I guess it's OK.
But do you have any better suggestions to avoid that?
 

> EX3. the dimension of your parameters is ill specified

Not sure what you mean here.  Our vectorization requires all args to
be either scalars or the same size container.

I first declared an 11-by-100 array, but then I only used a sub-part of this array somewhere in the transformed parameters section and model section.
It's actually a copy-paste error, I modified the model file from a previous version, and the the dimension does not match.
 

- Bob


L. 

Bob Carpenter

unread,
Aug 26, 2015, 4:57:42 PM8/26/15
to stan-...@googlegroups.com
Which version of RStan are you using? I believe that issue has
been fixed as of 2.7. If not, do you have a simple example
that reproduces the behavior? Sorry for not being able to follow
details message-to-message --- we get more email than I can track
given my poor memory for who-said-what-where.

- Bob

Raghu Naik

unread,
Aug 27, 2015, 12:08:19 PM8/27/15
to stan-users
Thanks Bob. 

In line with what you suggested, I saw that I had some declared variables in the generated quantities block that I later commented out in the body of that block to simplify things. Maybe the program should tag such declarations that are not being followed through with when bringing out this error message. 

Otherwise Stan has been great that pointing out syntax errors.

Thanks. 

You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/1k2gIjxn2GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.

Raghu Naik

unread,
Aug 27, 2015, 12:22:22 PM8/27/15
to Stan users mailing list
To add to what Lei said, the problem is that this error is kind of flaky. As I had mentioned earlier, sometimes it goes away on re-submitting the code again. 
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/1k2gIjxn2GI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+unsubscribe@googlegroups.com.

Lei Zhang

unread,
Aug 27, 2015, 12:35:55 PM8/27/15
to Stan users mailing list
Hi Bob,

I use Stan 2.7.0 and R3.2.0 on a Windows laptop. With the meaningless toy example attached, you could reproduce the error message. 
The key point is that, I was trying to use Matt Trick. When the dimension of beta and beta_raw is not identical, this error message will occur. 
However, on a Linux server, with the same R and Stan version, I could have some more informative error message.

Lei
toy_script.R
toy_model.stan

Jiqiang Guo

unread,
Aug 27, 2015, 12:49:48 PM8/27/15
to stan-...@googlegroups.com
What error message did you get on Windows?  How do you use R (RGui, RStduio, etc)? 

Jiqiang 

Lei Zhang

unread,
Aug 27, 2015, 1:04:12 PM8/27/15
to Stan users mailing list
I use RStudio on Windows. And on Linux, I just use shell. 

The error message is still the same as in the OP:
here are whatever error messages were returned
[[1]]
Stan model '[MODEL NAME]' does not contain samples.

Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug

Ben Goodrich

unread,
Aug 27, 2015, 1:22:57 PM8/27/15
to Stan users mailing list
On Thursday, August 27, 2015 at 1:04:12 PM UTC-4, Lei Zhang wrote:
I use RStudio on Windows. And on Linux, I just use shell. 

The error message is still the same as in the OP:
here are whatever error messages were returned
[[1]]
Stan model '[MODEL NAME]' does not contain samples.

Warning message:
In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug

I think there are multiple issues here. The first one --- which apparently multiple people are facing --- is that RStudio for Windows is not receiving stdout when chains are executed in parallel. Any help as to why that is would be appreciated. It should be possible to see the real error(s) by specifying chains = 1 or open_progress = TRUE (in which case Internet Explorer will open the progress file that can be refreshed).

The second error is whatever is causing the chain(s) to stop, which could be one of any number of things depending on the model.

Ben

 

Jiqiang Guo

unread,
Aug 27, 2015, 8:40:08 PM8/27/15
to stan-...@googlegroups.com
Ben,

The problem here seems to be that mc.cores is set to be larger than 1, so setting chains=1 is not enough to disable creating multiple processes. 

It looks like we need to change this line of code (from chains > 0 to chains > 1):

Jiqiang 

--

Ben Goodrich

unread,
Aug 27, 2015, 8:56:26 PM8/27/15
to Stan users mailing list
On Thursday, August 27, 2015 at 8:40:08 PM UTC-4, Jiqiang Guo wrote:
The problem here seems to be that mc.cores is set to be larger than 1, so setting chains=1 is not enough to disable creating multiple processes. 

It looks like we need to change this line of code (from chains > 0 to chains > 1):

OK. I've changed that locally. I'm still not sure why RStudio is not receiving stdout though.

Ben


Ben Goodrich

unread,
Aug 27, 2015, 8:56:52 PM8/27/15
to Stan users mailing list
On Thursday, August 27, 2015 at 8:40:08 PM UTC-4, Jiqiang Guo wrote:
The problem here seems to be that mc.cores is set to be larger than 1, so setting chains=1 is not enough to disable creating multiple processes. 

It looks like we need to change this line of code (from chains > 0 to chains > 1):

Ben Lambert

unread,
Sep 9, 2015, 8:59:40 PM9/9/15
to Stan users mailing list
Hi Ben,

I'm also using RStudio on Windows and am getting the same error message as indicated in this thread. When setting: options(mc.cores=1) I have no problem, but with >1 I always get the error:

in.local(object,...)
    some chains had errors: consider specifying chains=1 to debug

Any idea why this might be happening?

Best,

Ben

Ben Goodrich

unread,
Sep 9, 2015, 11:44:17 PM9/9/15
to Stan users mailing list
No, but call stan with open_progress = TRUE to see more information when cores > 1.

Ben Lambert

unread,
Sep 10, 2015, 10:59:55 AM9/10/15
to Stan users mailing list
Ok - when I do the following, a text box pops up, but it doesn't contain anything other than 'Refresh to see progress'.

Any ideas?

Ben

Ben Goodrich

unread,
Sep 10, 2015, 3:33:18 PM9/10/15
to Stan users mailing list
On Thursday, September 10, 2015 at 10:59:55 AM UTC-4, Ben Lambert wrote:
Ok - when I do the following, a text box pops up, but it doesn't contain anything other than 'Refresh to see progress'.

Any ideas?

What happens when you hit Refresh?

Ben

Ben Lambert

unread,
Sep 13, 2015, 10:15:29 AM9/13/15
to Stan users mailing list
What is Refresh? Is there a keyboard shortcut for this?

Ben Goodrich

unread,
Sep 13, 2015, 10:38:25 PM9/13/15
to Stan users mailing list
On Sunday, September 13, 2015 at 10:15:29 AM UTC-4, Ben Lambert wrote:
What is Refresh? Is there a keyboard shortcut for this?

It should open in a web browser
 

Raghu Naik

unread,
Sep 24, 2015, 12:47:41 PM9/24/15
to Stan users mailing list
Stan Team,

I would appreciate your help on this issue with the messages from the single chain and multi-chain runs as below. I am using Rstan 2.80.

The  single chain runs through fine as below with 4000 iterations. 
SAMPLING FOR MODEL 'janu_stan_v2' NOW (CHAIN 1).

Chain 1, Iteration:    1 / 2000 [  0%]  (Warmup)
Chain 1, Iteration:  200 / 2000 [ 10%]  (Warmup)
Chain 1, Iteration:  400 / 2000 [ 20%]  (Warmup)
Chain 1, Iteration:  600 / 2000 [ 30%]  (Warmup)
Chain 1, Iteration:  800 / 2000 [ 40%]  (Warmup)
Chain 1, Iteration: 1000 / 2000 [ 50%]  (Warmup)
Chain 1, Iteration: 1001 / 2000 [ 50%]  (Sampling)
Chain 1, Iteration: 1200 / 2000 [ 60%]  (Sampling)
Chain 1, Iteration: 1400 / 2000 [ 70%]  (Sampling)
Chain 1, Iteration: 1600 / 2000 [ 80%]  (Sampling)
Chain 1, Iteration: 1800 / 2000 [ 90%]  (Sampling)
Chain 1, Iteration: 2000 / 2000 [100%]  (Sampling)
#  Elapsed Time: 5834.62 seconds (Warm-up)
#                3763.76 seconds (Sampling)
#                9598.38 seconds (Total)

Now the message from the four chain run of 10000 iterations. 
SAMPLING FOR MODEL 'janu_stan_v2' NOW (CHAIN 1).

SAMPLING FOR MODEL 'janu_stan_v2' NOW (CHAIN 2).

SAMPLING FOR MODEL 'janu_stan_v2' NOW (CHAIN 3).

SAMPLING FOR MODEL 'janu_stan_v2' NOW (CHAIN 4).

Chain 4, Iteration:    1 / 10000 [  0%]  (Warmup)
Chain 3, Iteration:    1 / 10000 [  0%]  (Warmup)
Chain 1, Iteration:    1 / 10000 [  0%]  (Warmup)
Chain 2, Iteration:    1 / 10000 [  0%]  (Warmup)
Chain 3, Iteration: 2000 / 5000 [ 40%]  (Warmup)
Chain 3, Iteration: 2500 / 5000 [ 50%]  (Warmup)
Chain 3, Iteration: 2501 / 5000 [ 50%]  (Sampling)
Chain 3, Iteration: 3000 / 5000 [ 60%]  (Sampling)
Chain 2, Iteration: 1000 / 10000 [ 10%]  (Warmup)
Chain 3, Iteration: 3500 / 5000 [ 70%]  (Sampling)
Chain 3, Iteration: 1000 / 10000 [ 10%]  (Warmup)
Chain 4, Iteration: 1000 / 10000 [ 10%]  (Warmup)
Chain 1, Iteration: 1000 / 10000 [ 10%]  (Warmup)
Chain 3, Iteration: 4000 / 5000 [ 80%]  (Sampling)
Chain 2, Iteration: 2000 / 10000 [ 20%]  (Warmup)[1] "Error : model7791606bf1b1_janu_stan_v2_namespace::write_array: x_hat[k0__] is -1, but must be greater than or equal to 0"
error occurred during calling the sampler; sampling not done
Error in serialize(data, node$con, xdr = FALSE) : ignoring SIGPIPE signal
Calls: <Anonymous> ... doTryCatch -> sendData -> sendData.SOCK0node -> serialize
Execution halted

Chain 4, Iteration: 2000 / 10000 [ 20%]  (Warmup)
Chain 3, Iteration: 2000 / 10000 [ 20%]  (Warmup)
Chain 2, Iteration: 3000 / 10000 [ 30%]  (Warmup)
Chain 1, Iteration: 2000 / 10000 [ 20%]  (Warmup)
Chain 3, Iteration: 3000 / 10000 [ 30%]  (Warmup)
Chain 4, Iteration: 3000 / 10000 [ 30%]  (Warmup)
Chain 2, Iteration: 4000 / 10000 [ 40%]  (Warmup)
Chain 3, Iteration: 4000 / 10000 [ 40%]  (Warmup)
Chain 4, Iteration: 4000 / 10000 [ 40%]  (Warmup)[1] "Error : model7791264ad09f_janu_stan_v2_namespace::write_array: v_hat[k0__] is -1, but must be greater than or equal to 0"
error occurred during calling the sampler; sampling not done

Chain 1, Iteration: 3000 / 10000 [ 30%]  (Warmup)
Chain 4, Iteration: 5000 / 10000 [ 50%]  (Warmup)
Chain 4, Iteration: 5001 / 10000 [ 50%]  (Sampling)
Chain 2, Iteration: 5000 / 10000 [ 50%]  (Warmup)
Chain 2, Iteration: 5001 / 10000 [ 50%]  (Sampling)
Chain 1, Iteration: 4000 / 10000 [ 40%]  (Warmup)
Chain 2, Iteration: 6000 / 10000 [ 60%]  (Sampling)
Chain 1, Iteration: 5000 / 10000 [ 50%]  (Warmup)
Chain 1, Iteration: 5001 / 10000 [ 50%]  (Sampling)
Chain 4, Iteration: 6000 / 10000 [ 60%]  (Sampling)
Chain 2, Iteration: 7000 / 10000 [ 70%]  (Sampling)
Chain 1, Iteration: 6000 / 10000 [ 60%]  (Sampling)
Chain 2, Iteration: 8000 / 10000 [ 80%]  (Sampling)
Chain 1, Iteration: 7000 / 10000 [ 70%]  (Sampling)
Chain 4, Iteration: 7000 / 10000 [ 70%]  (Sampling)
Chain 2, Iteration: 9000 / 10000 [ 90%]  (Sampling)
Chain 1, Iteration: 8000 / 10000 [ 80%]  (Sampling)
Chain 2, Iteration: 10000 / 10000 [100%]  (Sampling)
#  Elapsed Time: 30470.4 seconds (Warm-up)
#                39078.4 seconds (Sampling)
#                69548.8 seconds (Total)


Chain 1, Iteration: 9000 / 10000 [ 90%]  (Sampling)
Chain 4, Iteration: 8000 / 10000 [ 80%]  (Sampling)
Chain 1, Iteration: 10000 / 10000 [100%]  (Sampling)
#  Elapsed Time: 40647.2 seconds (Warm-up)
#                37930.2 seconds (Sampling)
#                78577.4 seconds (Total)


Chain 4, Iteration: 9000 / 10000 [ 90%]  (Sampling)

Chain 4, Iteration: 10000 / 10000 [100%]  (Sampling)
#  Elapsed Time: 28786.6 seconds (Warm-up)
#                67963.2 seconds (Sampling)
#                96749.8 seconds (Total)

here are whatever error messages were returned
[[1]]
Stan model 'janu_stan_v2' does not contain samples.

Warning messages:
1: In .local(object, ...) :
  some chains had errors; consider specifying chains = 1 to debug
2: There were 29 divergent transitions after warmup. Increasing adapt_delta may help.
3: Examine the pairs() plot to diagnose sampling problems

As mentioned in the thread earlier, still not sure why a parallel run fails where a single chain has run fine.

Regards,

Raghu

Bob Carpenter

unread,
Sep 24, 2015, 1:40:07 PM9/24/15
to stan-...@googlegroups.com
You can just run chain 2 or chain 4 and get more info on where
they failed.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.

Raghu Naik

unread,
Sep 24, 2015, 2:04:30 PM9/24/15
to Stan users mailing list
Thanks Bob. 

I am not sure how I would do that.  The generated stan fit object has no sampling data. Thanks. 

Bob Carpenter

unread,
Sep 24, 2015, 5:14:32 PM9/24/15
to stan-...@googlegroups.com
Use the stan() command and specify the chain id to be 2 or 4 and
to run a single chain.

- Bob

Raghu Naik

unread,
Sep 27, 2015, 12:50:55 PM9/27/15
to Stan users mailing list
Thanks again Bob

I was able to fix the issue by looking at the chain iteration progress that I can now see under Rstan 2.8. 

Chain 2, Iteration: 2000 / 10000 [ 20%]  (Warmup)[1] "Error : model7791606bf1b1_janu_stan_v2_namespace::write_array: x_hat[k0__] is -1, but must be greater than or equal to 0"

 The earlier comments made by you and Ben were very relevant and  made more sense to me now  after this message :-).  

Also, thanks for the 2.8 Rstan update.

Regards.
Reply all
Reply to author
Forward
0 new messages