Skip to content

Commit

Permalink
Update function signatures for cmdstanr
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau-lilly committed Jul 22, 2022
1 parent 4ee5367 commit ba3d820
Show file tree
Hide file tree
Showing 38 changed files with 524 additions and 219 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Description: Bayesian data analysis usually incurs long runtimes
both single-fit workflows and multi-rep simulation studies.
For the statistical methodology, please refer to 'Stan' documentation
(Stan Development Team 2020) <https://mc-stan.org/>.
Version: 0.0.4
Version: 0.0.4.9000
License: MIT + file LICENSE
URL: https://docs.ropensci.org/stantargets/, https://github.com/ropensci/stantargets
BugReports: https://github.com/ropensci/stantargets/issues
Expand Down Expand Up @@ -43,7 +43,7 @@ Authors@R: c(
Depends:
R (>= 3.5.0)
Imports:
cmdstanr (>= 0.2.0),
cmdstanr (>= 0.5.0),
digest (>= 0.6.25),
fs (>= 1.5.0),
fst (>= 0.9.2),
Expand All @@ -69,6 +69,6 @@ SystemRequirements: CmdStan >= 2.25.0
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.2.0
VignetteBuilder: knitr
Config/testthat/edition: 3
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# stantargets 0.0.4.9000

* Update the signatures of most user-side functions to accommodate changes from `cmdstanr` 0.2.0 to 0.5.0 (https://github.com/ropensci/targets/discussions/884, @stuvet).

# stantargets 0.0.4

* Support the `repository` argument for `targets` >= 0.11.0.
Expand Down
16 changes: 11 additions & 5 deletions R/tar_stan_gq.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ tar_stan_gq <- function(
variables = NULL,
summaries = list(),
summary_args = list(),
draws = TRUE,
summary = TRUE,
return_draws = TRUE,
return_summary = TRUE,
draws = NULL,
summary = NULL,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
Expand All @@ -115,6 +117,10 @@ tar_stan_gq <- function(
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue")
) {
tar_stan_deprecate(draws, "return_draws")
tar_stan_deprecate(summary, "return_summary")
return_draws <- draws %|||% return_draws
return_summary <- summary %|||% return_summary
envir <- tar_option_get("envir")
compile <- match.arg(compile)
targets::tar_assert_chr(stan_files)
Expand Down Expand Up @@ -259,9 +265,9 @@ tar_stan_gq <- function(
stan_files = stan_files,
sym_stan = sym_stan,
compile = compile,
draws = draws,
summary = summary,
diagnostics = FALSE,
return_draws = return_draws,
return_summary = return_summary,
return_diagnostics = FALSE,
target_file = target_file,
target_lines = target_lines,
target_data = target_data,
Expand Down
52 changes: 34 additions & 18 deletions R/tar_stan_mcmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
#' `fs::path_ext_remove(basename(stan_files))` will be used
#' as target name suffixes. If `stan_files` is a named vector,
#' the suffixed will come from `names(stan_files)`.
#' @param draws Logical, whether to create a target for posterior draws.
#' @param return_draws Logical, whether to create a target for posterior draws.
#' Saves `posterior::as_draws_df(fit$draws())` to a compressed `tibble`.
#' Convenient, but duplicates storage.
#' @param summary Logical, whether to create a target for
#' @param return_summary Logical, whether to create a target for
#' `fit$summary()`.
#' @param diagnostics Logical, whether to create a target for
#' @param return_diagnostics Logical, whether to create a target for
#' `posterior::as_draws_df(fit$sampler_diagnostics())`.
#' Saves `posterior::as_draws_df(fit$draws())` to a compressed `tibble`.
#' Convenient, but duplicates storage.
Expand All @@ -69,6 +69,8 @@
#' targets such as posterior draws. We recommend efficient data frame formats
#' such as `"feather"` or `"aws_parquet"`. For more on storage formats,
#' see the help file of `targets::tar_target()`.
#' @param draws Deprecated on 2022-07-22. Use `return_draws` instead.
#' @param summary Deprecated on 2022-07-22. Use `return_summary` instead.
#' @examples
#' if (Sys.getenv("TAR_LONG_EXAMPLES") == "true") {
#' targets::tar_dir({ # tar_dir() runs code from a temporary directory.
Expand Down Expand Up @@ -112,10 +114,13 @@ tar_stan_mcmc <- function(
init = NULL,
save_latent_dynamics = FALSE,
output_dir = NULL,
output_basename = NULL,
sig_figs = NULL,
chains = 4,
parallel_chains = getOption("mc.cores", 1),
chain_ids = seq_len(chains),
threads_per_chain = NULL,
opencl_ids = NULL,
iter_warmup = NULL,
iter_sampling = NULL,
save_warmup = FALSE,
Expand All @@ -131,16 +136,17 @@ tar_stan_mcmc <- function(
term_buffer = NULL,
window = NULL,
fixed_param = FALSE,
sig_figs = NULL,
validate_csv = TRUE,
show_messages = TRUE,
diagnostics = c("divergences", "treedepth", "ebfmi"),
variables = NULL,
inc_warmup = FALSE,
summaries = list(),
summary_args = list(),
draws = TRUE,
diagnostics = TRUE,
summary = TRUE,
return_draws = TRUE,
return_diagnostics = TRUE,
return_summary = TRUE,
draws = NULL,
summary = NULL,
tidy_eval = targets::tar_option_get("tidy_eval"),
packages = targets::tar_option_get("packages"),
library = targets::tar_option_get("library"),
Expand All @@ -157,6 +163,10 @@ tar_stan_mcmc <- function(
retrieval = targets::tar_option_get("retrieval"),
cue = targets::tar_option_get("cue")
) {
tar_stan_deprecate(draws, "return_draws")
tar_stan_deprecate(summary, "return_summary")
return_draws <- draws %|||% return_draws
return_summary <- summary %|||% return_summary
envir <- tar_option_get("envir")
compile <- match.arg(compile)
targets::tar_assert_chr(stan_files)
Expand Down Expand Up @@ -223,10 +233,13 @@ tar_stan_mcmc <- function(
init = init,
save_latent_dynamics = save_latent_dynamics,
output_dir = output_dir,
output_basename = output_basename,
sig_figs = sig_figs,
chains = chains,
parallel_chains = parallel_chains,
chain_ids = chain_ids,
threads_per_chain = threads_per_chain,
opencl_ids = opencl_ids,
iter_warmup = iter_warmup,
iter_sampling = iter_sampling,
save_warmup = save_warmup,
Expand All @@ -242,9 +255,8 @@ tar_stan_mcmc <- function(
term_buffer = term_buffer,
window = window,
fixed_param = fixed_param,
sig_figs = sig_figs,
validate_csv = validate_csv,
show_messages = show_messages,
diagnostics = diagnostics,
variables = variables,
inc_warmup = inc_warmup
)
Expand Down Expand Up @@ -347,9 +359,9 @@ tar_stan_mcmc <- function(
stan_files = stan_files,
sym_stan = sym_stan,
compile = compile,
draws = draws,
summary = summary,
diagnostics = diagnostics,
return_draws = return_draws,
return_summary = return_summary,
return_diagnostics = return_diagnostics,
target_file = target_file,
target_lines = target_lines,
target_data = target_data,
Expand Down Expand Up @@ -398,10 +410,13 @@ tar_stan_mcmc_run <- function(
init,
save_latent_dynamics,
output_dir,
output_basename,
sig_figs,
chains,
parallel_chains,
chain_ids,
threads_per_chain,
opencl_ids,
iter_warmup,
iter_sampling,
save_warmup,
Expand All @@ -417,9 +432,8 @@ tar_stan_mcmc_run <- function(
term_buffer,
window,
fixed_param,
sig_figs,
validate_csv,
show_messages,
diagnostics,
variables,
inc_warmup
) {
Expand Down Expand Up @@ -458,10 +472,13 @@ tar_stan_mcmc_run <- function(
init = init,
save_latent_dynamics = save_latent_dynamics,
output_dir = output_dir,
output_basename = output_basename,
sig_figs = sig_figs,
chains = chains,
parallel_chains = parallel_chains,
chain_ids = chain_ids,
threads_per_chain = threads_per_chain,
opencl_ids = opencl_ids,
iter_warmup = iter_warmup,
iter_sampling = iter_sampling,
save_warmup = save_warmup,
Expand All @@ -477,9 +494,8 @@ tar_stan_mcmc_run <- function(
term_buffer = term_buffer,
window = window,
fixed_param = fixed_param,
sig_figs = sig_figs,
validate_csv = validate_csv,
show_messages = show_messages
show_messages = show_messages,
diagnostics = diagnostics
)
# Load all the data and return the whole unserialized fit object:
# https://github.com/stan-dev/cmdstanr/blob/d27994f804c493ff3047a2a98d693fa90b83af98/R/fit.R#L16-L18 # nolint
Expand Down
Loading

0 comments on commit ba3d820

Please sign in to comment.