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

"File does not exist" error when running with fixed parameters #68

Closed
ihuff opened this issue Nov 12, 2024 · 1 comment
Closed

"File does not exist" error when running with fixed parameters #68

ihuff opened this issue Nov 12, 2024 · 1 comment
Assignees

Comments

@ihuff
Copy link

ihuff commented Nov 12, 2024

I'm running a prior predictive check and hit a failed assertion when using fixed_param=TRUE with tar_stan_mcmc using targets 1.8.0 and stantargets 0.1.1.900. Reproducible example follows:

targets::tar_dir({
    targets::tar_script({
        library(targets)
        library(stantargets)
        lines <- "data {\n      int <lower = 1> n;\n      vector[n] x;\n      vector[n] y;\n      real true_beta;\n    }\n    parameters {\n      real beta;\n    }\n    model {\n      y ~ normal(x * beta, 1);\n      beta ~ normal(0, 1);\n    }\n    generated quantities {\n      real beta_sim = normal_rng(0, 1);\n      vector[n] y_sim;\n      for (i in 1:n) {\n        y_sim[i] = normal_rng(x[i] * beta, 1);\n      }\n    }"
        writeLines(lines, "x.stan")
        generate_data <- function(n = 10) {
            true_beta <- stats::rnorm(n = 1, mean = 0, sd = 1)
            x <- seq(from = -1, to = 1, length.out = n)
            y <- stats::rnorm(n, x * true_beta, 1)
            list(n = n, x = x, y = y, true_beta = true_beta)
        }
        list(tar_stan_mcmc(example, "x.stan", generate_data(), 
            fixed_param = TRUE, stdout = R.utils::nullfile(), 
            stderr = R.utils::nullfile()))
    })
    targets::tar_make()
})
#> ▶ dispatched target example_data
#> ● completed target example_data [0 seconds, 219 bytes]
#> ▶ dispatched target example_file_x
#> ● completed target example_file_x [0 seconds, 408 bytes]
#> ▶ dispatched target example_mcmc_x
#> ● completed target example_mcmc_x [1.35 minutes, 374.841 kilobytes]
#> ▶ dispatched target example_diagnostics_x
#> ▶ recorded workspace example_diagnostics_x
#> ✖ errored target example_diagnostics_x
#> ✖ errored pipeline [1.354 minutes]
#> 
#> ── General debugging ───────────────────────────────────────────────────────────
#> 
#> ── Debug target example_diagnostics_x ──────────────────────────────────────────
#> 
#> ── How to ──────────────────────────────────────────────────────────────────────
#> 
#> ── Last error message ──────────────────────────────────────────────────────────
#> 
#> ── Last error traceback ────────────────────────────────────────────────────────
#> Error:
#> ! targets::tar_make() error
#>     tar_meta(example_diagnostics_x)$error
#>     tar_workspace(example_diagnostics_x)
#>     • tar_errored()
#>     • tar_meta(fields = any_of("error"), complete_only = TRUE)
#>     • tar_workspace()
#>     • tar_workspaces()
#>     • Debug: https://books.ropensci.org/targets/debugging.html
#>     • Help: https://books.ropensci.org/targets/help.html
#>     Assertion on 'files' failed: File does not exist: 'C:/Users/ihuff/AppData/Local/Temp/Rtmpe0Uv97/x-202411121403-1-96982b.csv'.
#>     tibble::as_tibble(posterior::as_draws_df(example_mcmc_x$sampler_diagnost...
#>     posterior::as_draws_df(example_mcmc_x$sampler_diagnostics())
#>     example_mcmc_x$sampler_diagnostics()
#>     private$read_csv_(variables = "", sampler_diagnostics = NULL,      forma...
#>     read_cmdstan_csv(files = self$output_files(include_failed = FALSE),     ...
#>     assert_file_exists(files, access = "r", extension = "csv")
#>     checkmate::makeAssertion(files, res, .var.name, add)
#>     mstop("Assertion on '%s' failed: %s.", var.name, res, call. = sys.call(-...
#>     stop(simpleError(sprintf(msg, ...), call.))
#>     (function (condition)  {     state$error <- build_message(condition)    ...

Created on 2024-11-12 with reprex v2.1.0

@wlandau
Copy link
Member

wlandau commented Nov 13, 2024

This is a cmdstanr issue, now posted at stan-dev/cmdstanr#1032. If you set fixed_param = FALSE, it probably does not even make sense to return sampler diagnostics, so you can set return_diagnostics = FALSE in tar_stan_mcmc().

@wlandau wlandau closed this as completed Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants