rstan icon indicating copy to clipboard operation
rstan copied to clipboard

Can't print from transformed data

Open elbamos opened this issue 4 years ago • 17 comments

Summary:

print() statements executed from the transformed data block are not displayed back to the user.

Description:

print() statements executed in transformed data should be shown to the user. This was the old behavior (not sure when it changed, but I think around 2.19). See the 'print frequency' section here: https://mc-stan.org/docs/2_24/reference-manual/print-statements-section.html for confirmation that these print statements should show up.

This is particularly useful from rstan to, e.g., keep track of making sure the correct version of the source code is running.

Reproducible Steps:

See source code in the attached file: stanprint.txt

Current Output:

samples <- sampling(test_model, data = list(n = 3), chains = 1, iter = 2, open_progress = T, show_messages = T)

SAMPLING FOR MODEL '67e266178e2a1aef57a3b6ce7f76543e' NOW (CHAIN 1). Chain 1: alpha= 1.54289 beta = -0.313112

Chain 1: alpha= 1.54289 beta = -0.313112

Expected Output:

samples <- sampling(test_model, data = list(n = 3), chains = 1, iter = 2, open_progress = T, show_messages = T) Chain 1: n= 3 SAMPLING FOR MODEL '67e266178e2a1aef57a3b6ce7f76543e' NOW (CHAIN 1). Chain 1: alpha= 1.54289 beta = -0.313112

Chain 1: alpha= 1.54289 beta = -0.313112

RStan Version:

2.21.2

R Version:

R version 3.6.2 (2019-12-12)

Operating System:

OS X 10.15.5

elbamos avatar Aug 11 '20 21:08 elbamos

@elbamos Thanks for reporting this.

@bgoodri I can confirm that this reproduces (i.e., doesn't print). Looks like a bug. Any idea where the problem is?

jgabry avatar Aug 11 '20 23:08 jgabry

This prints for me inside and outside RStudio. I suspect this may be an RStudio / Mac thing.

bgoodri avatar Aug 12 '20 00:08 bgoodri

Do your versions match? This definitely used to work on OS X/rstudio, at least it did around 2.17/18.

On Aug 11, 2020, at 5:28 PM, bgoodri [email protected] wrote:

 This prints for me inside and outside RStudio. I suspect this may be an RStudio / Mac thing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

elbamos avatar Aug 12 '20 00:08 elbamos

No, but the print statements are being executed. It is just a question of whether they show up.

On Tue, Aug 11, 2020 at 8:34 PM elbamos [email protected] wrote:

Do your versions match? This definitely used to work on OS X/rstudio, at least it did around 2.17/18.

On Aug 11, 2020, at 5:28 PM, bgoodri [email protected] wrote:

 This prints for me inside and outside RStudio. I suspect this may be an RStudio / Mac thing.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/828#issuecomment-672396401, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKXDGM2IJY22JA4CH6DSAHPPZANCNFSM4P3TKQRQ .

bgoodri avatar Aug 12 '20 01:08 bgoodri

It may be a Mac thing, but it doesn't seem to be an RStudio thing. The print statement in transformed parameters doesn't show up using R in the terminal either.

jgabry avatar Aug 12 '20 04:08 jgabry

But the ones from the model block do?

On Wed, Aug 12, 2020 at 12:46 AM Jonah Gabry [email protected] wrote:

It may be a Mac thing, but it doesn't seem to be an RStudio thing. The print statement in transformed parameters doesn't show up using R in the terminal either.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/828#issuecomment-672570013, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKTSTKBL6UEDCUBUAYDSAINBFANCNFSM4P3TKQRQ .

bgoodri avatar Aug 12 '20 14:08 bgoodri

Yeah it's just the print statements from transformed data that don't show up.

jgabry avatar Aug 12 '20 16:08 jgabry

That is weird

On Wed, Aug 12, 2020 at 12:02 PM Jonah Gabry [email protected] wrote:

Yeah it's just the print statements from transformed data that don't show up.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/828#issuecomment-672964172, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKRPDKFVSSKACVHMT43SAK4JTANCNFSM4P3TKQRQ .

bgoodri avatar Aug 12 '20 16:08 bgoodri

We have the same issue in CmdStanR right now (https://github.com/stan-dev/cmdstanr/issues/269) but probably not for the same reason?

For CmdStanR the print statements in transformed data aren't printed right now because (quoting from @rok-cesnovar)

The reason for this is that in order to not print the initial Cmdstan metadata dump for all chains, we start printing stdout to the user only after either an error occurs, an init warning is read or the start of warmup/sampling is printed. So not ideal.

For the time being, we might get away with printing everything after the line

refresh = x

which I think is guaranteed to always be the last metadata printed (do have to check though). But that means that we will always print the gradient times for all chains. Hopefully, we can parse that away.

jgabry avatar Aug 12 '20 16:08 jgabry

Is there any way I can be further helpful here? I do want to point out that in prior versions of rstan, this did work properly.

On Aug 12, 2020, at 9:54 AM, Jonah Gabry [email protected] wrote:

 We have the same issue in CmdStanR right now (stan-dev/cmdstanr#269) but probably not for the same reason?

For CmdStanR the print statements in transformed data aren't printed right now because (quoting from @rok-cesnovar)

The reason for this is that in order to not print the initial Cmdstan metadata dump for all chains, we start printing stdout to the user only after either an error occurs, an init warning is read or the start of warmup/sampling is printed. So not ideal.

For the time being, we might get away with printing everything after the line

refresh = x which I think is guaranteed to always be the last metadata printed (do have to check though). But that means that we will always print the gradient times for all chains. Hopefully, we can parse that away.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

elbamos avatar Aug 12 '20 17:08 elbamos

It may be a Mac thing,

Unfortunately not, confirmed on Ubuntu as well.

rok-cesnovar avatar Aug 12 '20 18:08 rok-cesnovar

Thanks for checking @rok-cesnovar.

So to summarize:

  • It works on whatever Linux setup @bgoodri is currently using
  • It doesn't work on Ubuntu
  • It doesn't work on Mac (at least not OS X 10.15.5 which both @elbamos and I are running, although we have different R versions)
  • Don't know about Windows yet

Is there any way I can be further helpful here? I do want to point out that in prior versions of rstan, this did work properly.

@elbamos Not sure what else you can do at the moment, but thanks for offering. Very glad you reported this though! And yeah I definitely think this used to work properly.

jgabry avatar Aug 12 '20 19:08 jgabry

doesn't work for me on ArchLinux+RStudio either (latest R & rstan). it would be nice to fix it, because otherwise debugging transformed data generation becomes very inconvenient

alyst avatar Sep 23 '20 20:09 alyst

@alyst Yeah we definitely want to fix this as it’s essential for debugging, like you say.

@bgoodri Is there anything particularly unique about your Linux setup that could be affecting this? These print statements seem to not work for anyone except you at the moment (regardless of OS) so it seems like there could be something about your setup that we just need to identify.

jgabry avatar Sep 29 '20 17:09 jgabry

I don't think so, but if it is not working for more than one person then we should fix it. I just have no idea why RStan would care what block the print() statement comes from; it just prints what Stan gives it.

On Tue, Sep 29, 2020 at 2:00 PM Jonah Gabry [email protected] wrote:

Yeah we definitely want to fix this as it’s essential for debugging, like you say.

@bgoodri https://github.com/bgoodri Is there anything particularly unique about your Linux setup that could be affecting this? These print statements seem to not work for anyone except you at the moment (regardless of OS) so it seems like there could be something about your setup that we just need to identify.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/828#issuecomment-700883049, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZ2XKWUPN7WVUGUM4MJYELSIIOCDANCNFSM4P3TKQRQ .

bgoodri avatar Sep 29 '20 18:09 bgoodri

Yeah it’s strange. I have no idea why which block the statement is in would matter.

jgabry avatar Sep 29 '20 18:09 jgabry

Seeing this same problem (can't print from transformed quantities block), using code from one of Michael Betancourt's courses. Another student is having the same problem. Moving the same print statement to the generated quantities block worked for me.

I'm on:

RStan 2.21.3 R 4.0.3 MacOS Big Sur 11.2.3

Matthew-MacLeod-gc avatar Mar 18 '21 14:03 Matthew-MacLeod-gc