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

Error when running loo with moment_match = TRUE on rstan model from previous session #183

Open
jonathanicholas opened this issue Aug 1, 2021 · 3 comments

Comments

@jonathanicholas
Copy link

jonathanicholas commented Aug 1, 2021

Hi,

I'm trying to run loo with moment matching on an rstan model fit in a previous session. The stanfit object was saved using:

fit <- stan(...)
saveRDS(fit,...)

And then loaded and loo (from https://github.com/stan-dev/rstan/blob/develop/rstan/rstan/R/loo.R) was run with:

fit <- loadRDS(...)
loo(fit, moment_match = TRUE)

which throws the following error:

Error in .local(object, ...) : 
  the model object is not created or not valid
Calls: loo ... apply -> FUN -> <Anonymous> -> <Anonymous> -> .local
Execution halted

Fitting and loading are both happening on the same system (university HPC cluster). I have no problems loading the stanfit object and then running other functions on this system (running extract(fit) for example) or loading the stanfit object on my local system (Mac OS 11.2.1). This also works fine if the model is fit and then loo is run within the same session (i.e. not from a .rds file).

HPC Cluster specs:

cat /etc/*-release

Cluster Manager v9.1
slave
NAME="Red Hat Enterprise Linux"
VERSION="8.2 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.2"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.2 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.2:GA"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.2"
Red Hat Enterprise Linux release 8.2 (Ootpa)
Red Hat Enterprise Linux release 8.2 (Ootpa)

R environment specs:

R version 4.1.0 (2021-05-18) -- "Camp Pontanezen"
rstan (version 2.21.2)

Thanks for your help and developing such an awesome package! If this is an rstan and not a loo problem I'm happy to move the issue there.

@jonaudet
Copy link

jonaudet commented Aug 25, 2021

Hi,
I seem to be having a similar issue (Ubuntu 20.04, R 4.1.1, RStan 2.21.2).
Compiling a model, using it, and then calling loo with moment_match = T is fine. But saving the results to RDS and reading them in a new session fails. Recompiling the model under the same object name as before (assuming the sampling was done using sampling rather than stan) also fails.

This also means that moment matching can't be used on the results of cmdstan. ETA: loo doesn't work directly on cmdstanfit objects, but the moment matching fails after transforming to a stanfit object.

@topipa
Copy link
Collaborator

topipa commented Aug 27, 2021

We are aware of this issue and it is a general problem with rstan that is not directly related to the loo package. There are certain methods that rstan uses for moment matching that don’t work after reloading a model in a new session. Unfortunately there are no straightforward workarounds at the moment, so moment matching for rstan fits needs to be done in the same R session as sampling.

@jonaudet
Copy link

jonaudet commented Aug 27, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants