issue with streaming output from RStan?

39 views
Skip to first unread message

Bob Carpenter

unread,
Mar 18, 2013, 2:32:32 PM3/18/13
to stan...@googlegroups.com
Jiqiang:

When I run the stan() command in R, I no longer
get streamed output of the iterations. It just
waits until they're all done and prints. Is
this something that could've broken in 1.2.0
or is this what's expected? If it's buffering,
is there a way to flush the prints so they're
visible?

RStan version: 1.2.0

R version: R 2.15.1 GUI 1.52 Leopard build 64-bit (6188)

-------------------------------------------
> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats4 stats graphics grDevices utils datasets methods base

other attached packages:
[1] rstan_1.2.0 inline_0.3.11 Rcpp_0.10.2 MCMCpack_1.2-4 MASS_7.3-18 coda_0.16-1
[7] lattice_0.20-6

loaded via a namespace (and not attached):
[1] codetools_0.2-8 grid_2.15.1 tools_2.15.1
--------------------------------------

- Bob


Andrew Gelman

unread,
Mar 18, 2013, 4:15:41 PM3/18/13
to stan...@googlegroups.com
If we're doing that, let's do that overwriting thing too.
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

Bob Carpenter

unread,
Mar 18, 2013, 4:20:23 PM3/18/13
to stan...@googlegroups.com
But only if we can make it work from the R GUI,
R command-line, and RStudio!

I seem to recall there was some problem with the
overwriting in R.

- Bob

Andrew Gelman

unread,
Mar 18, 2013, 4:20:59 PM3/18/13
to stan...@googlegroups.com
No, Jiqiang sait it worked fine.

Jiqiang Guo

unread,
Mar 18, 2013, 4:45:10 PM3/18/13
to stan...@googlegroups.com
I tested a very simple and I can see csv files are written incrementally during sampling.  In 1.2.0, write_csv function is used to write to the csv files, so 1.2.0 is not different from all previous versions in this respect.  

But I do see that after each iteration, there is not an explicite "flush" got called as in Stan.  I am not sure if an explicit "flush" after each iteration will help, but I will do that. 

I am not sure if I understood overwriting correctly.  But for csv files of sample in RStan, if the R process has the privilege to overwrite previous files, it will overwrite them. 


Jiqiang 

Andrew Gelman

unread,
Mar 18, 2013, 4:48:09 PM3/18/13
to stan...@googlegroups.com
When I said "overwrite," I wasn't talking about overwriting files, I was talking about cat(…, "\r")
A

Jiqiang Guo

unread,
Mar 18, 2013, 4:53:49 PM3/18/13
to stan...@googlegroups.com
I see.  That reminds me that I should test than in RStudio.  Definitely it works in R from command line. 

Jiqiang 

Bob Carpenter

unread,
Mar 18, 2013, 5:33:10 PM3/18/13
to stan...@googlegroups.com
I was just talking about this output:

> fit <- stan("normal_mixture_k.stan", iter=10000, data=c("K","N","y"), chains=1,fit=fit, init=0)
SAMPLING FOR MODEL 'normal_mixture_k' NOW (CHAIN 1).
Iteration: 1 / 10000 [ 0%] (Adapting)
Iteration: 1000 / 10000 [ 10%] (Adapting)
Iteration: 2000 / 10000 [ 20%] (Adapting)
Iteration: 3000 / 10000 [ 30%] (Adapting)
Iteration: 4000 / 10000 [ 40%] (Adapting)
Iteration: 5000 / 10000 [ 50%] (Adapting)
Iteration: 6000 / 10000 [ 60%] (Sampling)
Iteration: 7000 / 10000 [ 70%] (Sampling)
Iteration: 8000 / 10000 [ 80%] (Sampling)
Iteration: 9000 / 10000 [ 90%] (Sampling)
Iteration: 10000 / 10000 [100%] (Sampling)

>

After I hit return after calling stan(), I don't see anything
until all 10K iterations are done. So I don't know how fast
things are going.

What we'd like is to have the lines appear as soon as possible.

Usually in streaming I/O, there's a flush() operation to override
any buffering that might be done.

Andrew just wanted these lines to overwrite each other. At
which point, we can do them more frequently than just 10 total
updates.

- Bob


Andrew Gelman

unread,
Mar 18, 2013, 5:42:31 PM3/18/13
to stan...@googlegroups.com
Yes, I'd overwrite each line. But then start a new line for each new chain.
A

Jiqiang Guo

unread,
Mar 18, 2013, 6:42:41 PM3/18/13
to stan...@googlegroups.com
I guess I know what you were talking about now. Please see the comments below.

Jiqiang 

On Mon, Mar 18, 2013 at 5:33 PM, Bob Carpenter <ca...@alias-i.com> wrote:
I was just talking about this output:

> fit <- stan("normal_mixture_k.stan", iter=10000, data=c("K","N","y"), chains=1,fit=fit, init=0)
SAMPLING FOR MODEL 'normal_mixture_k' NOW (CHAIN 1).
Iteration:    1 / 10000 [  0%]  (Adapting)
Iteration: 1000 / 10000 [ 10%]  (Adapting)
Iteration: 2000 / 10000 [ 20%]  (Adapting)
Iteration: 3000 / 10000 [ 30%]  (Adapting)
Iteration: 4000 / 10000 [ 40%]  (Adapting)
Iteration: 5000 / 10000 [ 50%]  (Adapting)
Iteration: 6000 / 10000 [ 60%]  (Sampling)
Iteration: 7000 / 10000 [ 70%]  (Sampling)
Iteration: 8000 / 10000 [ 80%]  (Sampling)
Iteration: 9000 / 10000 [ 90%]  (Sampling)
Iteration: 10000 / 10000 [100%]  (Sampling)

>

After I hit return after calling stan(), I don't see anything
until all 10K iterations are done.   So I don't know how fast
things are going.
This is not the supposed behavior.  At least using R from the command line, I have the similar behavior as in Stan; when another 10% iteration are done, it prints a line. 

What we'd like is to have the lines appear as soon as possible.

Usually in streaming I/O, there's a flush() operation to override
any buffering that might be done.

The flush is already there.  So I think if the progress percent does not get updated as the sampling goes, it is a bug with the R environment that is used.  

Andrew just wanted these lines to overwrite each other.  At
which point, we can do them more frequently than just 10 total
updates.


- Bob


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

Jiqiang Guo

unread,
Mar 18, 2013, 7:12:19 PM3/18/13
to stan...@googlegroups.com
To make sure I understood.  I have tested three cases on Mac, all are fine:
R from command line
RStuio
R Gui 

Jiqiang 

Ben Goodrich

unread,
Mar 18, 2013, 7:28:51 PM3/18/13
to stan...@googlegroups.com
 My sampling progress also looks fine under RStudio. What version of RStudio is causing problems?

Ben


Bob Carpenter

unread,
Mar 19, 2013, 3:12:03 PM3/19/13
to stan...@googlegroups.com
I wonder if there's something amiss with my R
install or config. Is buffering user controllable?

It's definitely waiting until all the samples on
all the chains are done before printing anything.

I should've showed you what it looks like in
the meeting. But there's not much to see.

- Bob

On 3/18/13 7:12 PM, Jiqiang Guo wrote:
> To make sure I understood. I have tested three cases on Mac, all are fine:
> R from command line
> RStuio
> R Gui
> This is a video: http://dl.dropbox.com/u/646775/tmp/Untitled.mov
>
> Jiqiang
>
> On Mon, Mar 18, 2013 at 6:42 PM, Jiqiang Guo <guo...@gmail.com <mailto:guo...@gmail.com>> wrote:
>
> I guess I know what you were talking about now. Please see the comments below.
>
> Jiqiang
>
> stan-dev+unsubscribe@__googlegroups.com <mailto:stan-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out <https://groups.google.com/groups/opt_out>.
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.

Jiqiang Guo

unread,
Mar 19, 2013, 4:59:29 PM3/19/13
to stan...@googlegroups.com
I see this could happen from http://stackoverflow.com/questions/13327305/making-rcout-output-appear-on-the-r-console-immediately

From the above webpage, it seems there was a bug in R's older version.  I am using R version 2.15.2 (2012-10-26) -- "Trick or Treat".  But I am not sure that the version I am using is free from the bug mentioned. I guess it might be worth trying a new version of R though I never had this problem on any version of R on which we can install rstan.

--
Jiqiang 

To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


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

Bob Carpenter

unread,
Mar 19, 2013, 8:00:48 PM3/19/13
to stan...@googlegroups.com
OK -- I'll try the new R (it's up to 2.15.3 "Security Blanket"
as of March 4).

- Bob

On 3/19/13 4:59 PM, Jiqiang Guo wrote:
> I see this could happen from
> http://stackoverflow.com/questions/13327305/making-rcout-output-appear-on-the-r-console-immediately
>
> From the above webpage, it seems there was a bug in R's older version. I am using R version 2.15.2 (2012-10-26) --
> "Trick or Treat". But I am not sure that the version I am using is free from the bug mentioned. I guess it might be
> worth trying a new version of R though I never had this problem on any version of R on which we can install rstan.
>
> --
> Jiqiang
>
> On Tue, Mar 19, 2013 at 3:12 PM, Bob Carpenter <ca...@alias-i.com <mailto:ca...@alias-i.com>> wrote:
>
> I wonder if there's something amiss with my R
> install or config. Is buffering user controllable?
>
> It's definitely waiting until all the samples on
> all the chains are done before printing anything.
>
> I should've showed you what it looks like in
> the meeting. But there's not much to see.
>
> - Bob
>
>
> On 3/18/13 7:12 PM, Jiqiang Guo wrote:
>
> To make sure I understood. I have tested three cases on Mac, all are fine:
> R from command line
> RStuio
> R Gui
> This is a video: http://dl.dropbox.com/u/__646775/tmp/Untitled.mov <http://dl.dropbox.com/u/646775/tmp/Untitled.mov>
> stan-dev+unsubscribe@__googleg__roups.com <http://googlegroups.com>
> <mailto:stan-dev%__2Buns...@googlegroups.com <mailto:stan-dev%252Buns...@googlegroups.com>__>.
> For more options, visit https://groups.google.com/____groups/opt_out
> <https://groups.google.com/__groups/opt_out> <https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>>.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> stan-dev+unsubscribe@__googlegroups.com <mailto:stan-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> stan-dev+unsubscribe@__googlegroups.com <mailto:stan-dev%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/__groups/opt_out <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.

Bob Carpenter

unread,
Mar 19, 2013, 8:11:35 PM3/19/13
to stan...@googlegroups.com
Upgrading R solved the streaming output problem.

Thanks!

- Bob

On 3/19/13 4:59 PM, Jiqiang Guo wrote:
Reply all
Reply to author
Forward
0 new messages