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

save_object() for variational fit loses return code #780

Closed
ksvanhorn opened this issue Jun 27, 2023 · 3 comments · Fixed by #798
Closed

save_object() for variational fit loses return code #780

ksvanhorn opened this issue Jun 27, 2023 · 3 comments · Fixed by #798
Labels
bug Something isn't working

Comments

@ksvanhorn
Copy link

ksvanhorn commented Jun 27, 2023

Describe the bug
After running a variational estimation, saving the fit with save_object(), and reading it back with readRDS(), return_codes() returns NA instead of the return code from estimation.

To Reproduce

    file <- file.path(cmdstanr::cmdstan_path(), "examples/bernoulli/bernoulli.stan")
    mod <- cmdstanr::cmdstan_model(file)
    stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
    fit_vb <- mod$variational(data = stan_data, seed = 123)
    fit_vb$return_codes() # returns 0 as expected
    fit_vb$save_object('~/Tmp/vbexample.rds')
    fit_vb1 <- readRDS('~/Tmp/vbexample.rds')
    fit_vb1$return_codes() # returns NA

Expected behavior
The call fit_vb1$return_codes() should also return 0.

Operating system
Mac OS Ventura 13.4

CmdStanR version number
0.5.3.

Additional context
R version 4.2.2.

@ksvanhorn ksvanhorn added the bug Something isn't working label Jun 27, 2023
@jgabry
Copy link
Member

jgabry commented Jun 29, 2023 via email

@jgabry
Copy link
Member

jgabry commented Jul 27, 2023

Following up on this, it's an issue not only for variational but also for sampling (and presumably all fitting methods). The problem is that fit$return_codes() calls fit$runset$procs$return_codes(). And that function tries to query the processes:

      for (id in private$proc_ids_) {
        ret <- c(ret, self$get_proc(id)$get_exit_status())
      }

Presumably the solution to this is to store the return codes instead of trying to get the exit status every time the return codes are asked for.

@jgabry
Copy link
Member

jgabry commented Jul 27, 2023

@ksvanhorn I have a PR open that fixes this: #798

Would you mind trying it out and making sure it resolves the issue you were having?

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

Successfully merging a pull request may close this issue.

2 participants