-
-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rstan
fails to read cmdstanr
output .csv files
#1133
Comments
I can reproduce the issue - outputs from CmdStan 2.34.1 are read fine, outputs from 2.35.0 cause problems. Although I get a different error message (maybe because of using R 4.3.2)
I'll also note that the problem is made worse by the code at: rstan/rstan/rstan/R/stan_csv.R Line 220 in 9b8d8fe
save_warmup is not all 0 or all 1, n_kept never gets assigned.
|
Thanks. I think this might be fixed by #1131. Or at least the |
Ah good point. Perhaps we should revert #1131 and figure out a more general approach? @bgoodri @andrjohns we probably need to decide whether we want to keep supporting this functionality in RStan. If there continue to be changes in the CSV files created by CmdStan I don't think RStan can keep up with releases in order to make sure |
The approach I took for |
Note that using cmdstanr with brms relies on read_stan_csv. We probably
should add a test with fixed CSVs from s couple CmdStan versions and it
should be OK....
Dne st 31. 7. 2024 19:37 uživatel Andrew Johnson ***@***.***>
napsal:
… The approach I took for cmdstanr for compatibility with both was to convert
any true/false to 0/1
<https://github.com/stan-dev/cmdstanr/blob/0e3a99a52bc5ad15d9e386e9993c10ad6905818b/R/csv.R#L843>,
so that the parsing logic for the rest stayed the same
—
Reply to this email directly, view it on GitHub
<#1133 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACILKU3PJQLPI4IAEB7ONHDZPEOFFAVCNFSM6AAAAABKVJVGVGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENRRGAZDMNZXGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
It doesn't look like that's the case anymore (which makes sense, otherwise there would have been a ton of bug reports in |
Yeah that would have been a mess! |
I was getting the Is there a magical version I can use where I won't get either of these errors? Or is there a way I need to modify the input data to make it work? I got the code+data combination I'm attempting from someone else and it was working at one point. I'm not sure what package version were used then. :-/ |
Sorry for the hassle! I'm honestly not sure. Originally Is this for a model fit with cmdstanr? Here's some code from @andrjohns to produce a named list of arrays of posterior samples, similar to what rstan would do: That will hopefully allow you to avoid |
@bgoodri In the next RStan release |
@katrinabrock in addition to my previous comment, another option could be to run an older version of cmdstan. I think it might just be as of 2.35.0 that this is an issue, so you could try installing e.g. 2.34.0. |
Thanks for the quick response! switching cmdstanr to version 2.34.0 did not appear to resolve the issue. |
Yeah changing the cmdstanr version would only work if the csv files were being produced by cmdstanr. It’s weird if this is only using rstan because read_stan_csv() shouldn’t be necessary to use at all in that case. So yeah, quite strange! |
ok! I did some more digging and discovered a couple mistakes I made in my initial debugging: 1) I initially thought the script I was working on was calling rstan::stan when it was in fact calling rethinking::stan (https://github.com/rmcelreath/rethinking/blob/master/R/cmdstan_support.r#L104). 2) I switched my cmdstan versions, but forgot that cmdstan version mismatch will not automatically trigger recompilation of the model. Therefore, I was still running my code with models produced with 2.35.0 so of course this did not do anything to resolve the issue. With this in mind, here is my advice to others (@santikka ) to workaround this issue: WorkaroundsWorkarounds specific to rethinking packageFor those hitting this issue from using the To resolve this, either
OR switch to OR use the general solution below General workaroundUse cmdstan Steps: Step 2) (every time run your legacy code) Activate the older version of cmdstan like Step 3) (one time per model) Recompile any models that you compiled with an incompatible version of
Note: With Option B or C, once you've done all this recompiling once for each model with version Real SolutionRe-write your code to use only cmdstanr since it's better supported than rstan and much better supported than a hybrid. |
Thanks so much for the detailed report! Hopefully this is useful to anyone else running into the same problem. |
Summary:
rstan::read_stan_csv()
no longer works for for .csv files produced bycmdstanr
Description:
It seems that
rstan
expects thesave_warmup
field to be an integer value, butcmdstanr
instead writes this as a logical value (e.g.,false
) to the conversion to integer fails inrstan:::parse_stancsv_comments()
resulting in anNA
value forsave_warmup
. This used to work with earlier versions ofcmdstanr
/CmdStan
.Reproducible Steps:
Created on 2024-07-10 with reprex v2.1.1
RStan Version:
2.32.6
R Version:
R version 4.4.0 (2024-04-24 ucrt)
Operating System:
Windows 11 Pro 23H2
The text was updated successfully, but these errors were encountered: