Skip to content
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

Most recent commit breaks CmdStanR models with 1 chain #386

Closed
jgabry opened this issue Dec 13, 2024 · 6 comments
Closed

Most recent commit breaks CmdStanR models with 1 chain #386

jgabry opened this issue Dec 13, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@jgabry
Copy link
Member

jgabry commented Dec 13, 2024

@paul-buerkner I think this commit 79d4521 is causing problems for CmdStanR models with 1 chain. The reason is that with that commit a list of a single data frame now gets passed to posterior::: as_array_matrix_list because is_matrix_list_like is TRUE. This results in an error because of these lines in as_array_matrix_list:

x <- x[[1]]
dim(x) <- c(dim(x), 1)
dimnames(x) <- tmp

If the list has two data frames there's no error, which is why it only affects runs of a single chain.

This can be demonstrated without CmdStanR with a toy example. Here I first check the CRAN version (no error), then the latest posterior on GitHub (error), then install from posterior on GitHub from the commit before the latest commit (no error):

remotes::install_cran("posterior")
test <- list(
  data.frame(x = rnorm(100), y = rnorm(100))
)
posterior::as_draws_array(test) # no error

# need to restart R
remotes::install_github("stan-dev/posterior") # includes latest commit
test <- list(
  data.frame(x = rnorm(100), y = rnorm(100))
)
posterior::as_draws_array(test) # error

# need to restart R
remotes::install_github("stan-dev/posterior", ref = "d0f8b76") # this commit is from the PR before your latest commit
test <- list(
  data.frame(x = rnorm(100), y = rnorm(100))
)
posterior::as_draws_array(test) # no error 

When a CmdStanR model has a single chain this error happens when as_draws_array() is called on the list of a single data frame that is created when reading in the single CSV file.

@jgabry
Copy link
Member Author

jgabry commented Dec 13, 2024

I believe this is the source of the error in stan-dev/cmdstanr#1050. It took me a while (longer than it should have!) to notice that the example from @tillahoffmann was using the latest commit of posterior.

@jgabry jgabry added the bug Something isn't working label Dec 13, 2024
@jgabry
Copy link
Member Author

jgabry commented Dec 13, 2024

@tillahoffmann also confirmed in stan-dev/cmdstanr#1050 (comment) that he can replicate this posterior behavior, so I'm pretty sure this is the issue causing the errors in CmdStanR.

@jgabry
Copy link
Member Author

jgabry commented Dec 17, 2024

Another instance of a user running into this: https://discourse.mc-stan.org/t/error-in-dim-x-c-dim-x-1/37661

@paul-buerkner
Copy link
Collaborator

Thank you for finding this error. I am sorry I didn't respond earlier. I didn't get email notifications from github. Do you have a suggestion for how to fix this without having to revert to the commit? I would like to keep this feature if we can make it work safely with cmdStanR

@jgabry
Copy link
Member Author

jgabry commented Dec 17, 2024

For now @paul-buerkner and I decided to revert the commit, and we will add this feature back in without breaking CmdStanR. In order to do that it might be sufficient to just avoid applying this to lists of data frames, but will have to double check if that's enough.

@jgabry
Copy link
Member Author

jgabry commented Dec 17, 2024

Closing now that #387 is merged

@jgabry jgabry closed this as completed Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants