From 2dff5f1a6c9e70b2c70b9300717af0c9679f836a Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 12:20:55 -0700 Subject: [PATCH 1/9] remove deprecated arguments and functions closes #409 --- NAMESPACE | 4 -- NEWS.md | 21 +++++- R/csv.R | 17 +---- R/example.R | 13 ---- R/fit.R | 19 +----- R/model.R | 101 ++-------------------------- R/path.R | 19 ++---- R/utils.R | 26 ------- man/cmdstan_default_install_path.Rd | 5 +- man/cmdstan_default_path.Rd | 4 +- man/fit-method-grad_log_prob.Rd | 8 +-- man/fit-method-hessian.Rd | 4 +- man/fit-method-log_prob.Rd | 4 +- man/model-method-compile.Rd | 7 +- man/model-method-sample.Rd | 13 +--- man/model-method-sample_mpi.Rd | 5 +- man/model-method-variational.Rd | 8 +-- man/read_sample_csv.Rd | 16 ----- man/stan_threads.Rd | 22 ------ man/write_stan_tempfile.Rd | 23 ------- tests/testthat/test-example.R | 4 -- tests/testthat/test-model-compile.R | 1 - 22 files changed, 46 insertions(+), 298 deletions(-) delete mode 100644 man/read_sample_csv.Rd delete mode 100644 man/stan_threads.Rd delete mode 100644 man/write_stan_tempfile.Rd diff --git a/NAMESPACE b/NAMESPACE index b157025d1..26b27b5d6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -36,17 +36,13 @@ export(cmdstanr_example) export(draws_to_csv) export(eng_cmdstan) export(install_cmdstan) -export(num_threads) export(print_example_program) export(read_cmdstan_csv) -export(read_sample_csv) export(rebuild_cmdstan) export(register_knitr_engine) export(set_cmdstan_path) -export(set_num_threads) export(write_stan_file) export(write_stan_json) -export(write_stan_tempfile) import(R6) importFrom(posterior,as_draws) importFrom(stats,aggregate) diff --git a/NEWS.md b/NEWS.md index 1690e2824..d2906ea0b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,25 @@ # cmdstanr 0.8.1.9000 -Items for next release go here +* Removed deprecated items (replacements in parentheses): + - `read_sample_csv()` (`read_cmdstan_csv()`) + - `write_stan_tempfile()` (`write_stan_file()`) + - `model_params` element of `fit$metadata()` list (`variables` element) + - `jacobian_adjustment` argument to `fit$log_prob()` and similar methods (`jacobian` argument) + - `output_samples` argument to `model$variational()` (`draws` argument) + - several arguments to `model$compile()`: + - `threads` (`cpp_options = list(stan_threads = TRUE)`) + - `compile_hessian_method` (always compiled) + - several arguments to `model$sample()`: + - `cores` and `num_cores` (`parallel_chains`) + - `num_chains` (`chains`) + - `num_warmup` (`iter_warmup`) + - `num_samples` (`iter_sampling`) + - `validate_csv` (`diagnostics`) + - `save_extra_diagnostics` (`save_latent_dynamics`) + - `max_depth` (`max_treedepth`) + - `stepsize` (`step_size`) + + # cmdstanr 0.8.1 diff --git a/R/csv.R b/R/csv.R index 4e585fa6d..55b2a09be 100644 --- a/R/csv.R +++ b/R/csv.R @@ -321,8 +321,7 @@ read_cmdstan_csv <- function(files, model_param_dims <- variable_dims(metadata$variables) metadata$stan_variable_sizes <- model_param_dims metadata$stan_variables <- names(model_param_dims) - # $model_params is deprecated, remove for release 1.0 - metadata$model_params <- metadata$variables + if (metadata$method == "sample") { if (is.null(format)) { format <- "draws_array" @@ -467,20 +466,6 @@ read_cmdstan_csv <- function(files, } } -#' Read CmdStan CSV files from sampling into \R -#' -#' Deprecated. Use [read_cmdstan_csv()] instead. -#' @keywords internal -#' @export -#' @param files,variables,sampler_diagnostics Deprecated. Use -#' [read_cmdstan_csv()] instead. -#' -read_sample_csv <- function(files, - variables = NULL, - sampler_diagnostics = NULL) { - warning("read_sample_csv() is deprecated. Please use read_cmdstan_csv().") - read_cmdstan_csv(files, variables, sampler_diagnostics) -} #' @rdname read_cmdstan_csv #' @export diff --git a/R/example.R b/R/example.R index 5bb98ae3e..085ac7910 100644 --- a/R/example.R +++ b/R/example.R @@ -185,16 +185,3 @@ write_stan_file <- function(code, } file } - - -#' Write Stan code to a temporary file -#' -#' This function is deprecated. Please use [write_stan_file()] instead. -#' @keywords internal -#' @export -#' @inheritParams write_stan_file -write_stan_tempfile <- function(code, dir = tempdir()) { - warning("write_stan_tempfile() is deprecated. Please use write_stan_file() instead.", - call. = FALSE) - write_stan_file(code, dir) -} diff --git a/R/fit.R b/R/fit.R index cb093d9b9..620d99af2 100644 --- a/R/fit.R +++ b/R/fit.R @@ -371,7 +371,6 @@ CmdStanFit$set("public", name = "init_model_methods", value = init_model_methods #' @param unconstrained_variables (numeric) A vector of unconstrained parameters. #' @param jacobian (logical) Whether to include the log-density adjustments from #' un/constraining variables. -#' @param jacobian_adjustment Deprecated. Please use `jacobian` instead. #' #' @examples #' \dontrun{ @@ -383,11 +382,7 @@ CmdStanFit$set("public", name = "init_model_methods", value = init_model_methods #' [unconstrain_variables()], [unconstrain_draws()], [variable_skeleton()], #' [hessian()] #' -log_prob <- function(unconstrained_variables, jacobian = TRUE, jacobian_adjustment = NULL) { - if (!is.null(jacobian_adjustment)) { - warning("'jacobian_adjustment' is deprecated. Please use 'jacobian' instead.", call. = FALSE) - jacobian <- jacobian_adjustment - } +log_prob <- function(unconstrained_variables, jacobian = TRUE) { self$init_model_methods() if (length(unconstrained_variables) != private$model_methods_env_$num_upars_) { stop("Model has ", private$model_methods_env_$num_upars_, " unconstrained parameter(s), but ", @@ -417,11 +412,7 @@ CmdStanFit$set("public", name = "log_prob", value = log_prob) #' [unconstrain_variables()], [unconstrain_draws()], [variable_skeleton()], #' [hessian()] #' -grad_log_prob <- function(unconstrained_variables, jacobian = TRUE, jacobian_adjustment = NULL) { - if (!is.null(jacobian_adjustment)) { - warning("'jacobian_adjustment' is deprecated. Please use 'jacobian' instead.", call. = FALSE) - jacobian <- jacobian_adjustment - } +grad_log_prob <- function(unconstrained_variables, jacobian = TRUE) { self$init_model_methods() if (length(unconstrained_variables) != private$model_methods_env_$num_upars_) { stop("Model has ", private$model_methods_env_$num_upars_, " unconstrained parameter(s), but ", @@ -452,11 +443,7 @@ CmdStanFit$set("public", name = "grad_log_prob", value = grad_log_prob) #' [unconstrain_variables()], [unconstrain_draws()], [variable_skeleton()], #' [hessian()] #' -hessian <- function(unconstrained_variables, jacobian = TRUE, jacobian_adjustment = NULL) { - if (!is.null(jacobian_adjustment)) { - warning("'jacobian_adjustment' is deprecated. Please use 'jacobian' instead.", call. = FALSE) - jacobian <- jacobian_adjustment - } +hessian <- function(unconstrained_variables, jacobian = TRUE) { self$init_model_methods() if (length(unconstrained_variables) != private$model_methods_env_$num_upars_) { stop("Model has ", private$model_methods_env_$num_upars_, " unconstrained parameter(s), but ", diff --git a/R/model.R b/R/model.R index e11603fd8..e119ded19 100644 --- a/R/model.R +++ b/R/model.R @@ -423,9 +423,6 @@ CmdStanModel <- R6::R6Class( #' @param dry_run (logical) If `TRUE`, the code will do all checks before compilation, #' but skip the actual C++ compilation. Used to speedup tests. #' -#' @param threads Deprecated and will be removed in a future release. Please -#' turn on threading via `cpp_options = list(stan_threads = TRUE)` instead. -#' #' @return The `$compile()` method is called for its side effect of creating the #' executable and adding its path to the [`CmdStanModel`] object, but it also #' returns the [`CmdStanModel`] object invisibly. @@ -474,10 +471,7 @@ compile <- function(quiet = TRUE, force_recompile = getOption("cmdstanr_force_recompile", default = FALSE), compile_model_methods = FALSE, compile_standalone = FALSE, - dry_run = FALSE, - #deprecated - compile_hessian_method = FALSE, - threads = FALSE) { + dry_run = FALSE) { if (length(self$stan_file()) == 0) { stop("'$compile()' cannot be used because the 'CmdStanModel' was not created with a Stan file.", call. = FALSE) @@ -507,17 +501,6 @@ compile <- function(quiet = TRUE, } } - # temporary deprecation warnings - if (isTRUE(threads)) { - warning("'threads' is deprecated. Please use 'cpp_options = list(stan_threads = TRUE)' instead.") - cpp_options[["stan_threads"]] <- TRUE - } - - # temporary deprecation warnings - if (isTRUE(compile_hessian_method)) { - warning("'compile_hessian_method' is deprecated. The hessian method is compiled with all models.") - } - if (length(self$exe_file()) == 0) { if (is.null(dir)) { exe_base <- self$stan_file() @@ -1113,8 +1096,6 @@ CmdStanModel$set("public", name = "format", value = format) #' #' @template model-common-args #' @template model-sample-args -#' @param cores,num_cores,num_chains,num_warmup,num_samples,save_extra_diagnostics,max_depth,stepsize,validate_csv -#' Deprecated and will be removed in a future release. #' #' @return A [`CmdStanMCMC`] object. #' @@ -1153,60 +1134,7 @@ sample <- function(data = NULL, show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), save_metric = NULL, - save_cmdstan_config = NULL, - # deprecated - cores = NULL, - num_cores = NULL, - num_chains = NULL, - num_warmup = NULL, - num_samples = NULL, - validate_csv = NULL, - save_extra_diagnostics = NULL, - max_depth = NULL, - stepsize = NULL) { - # temporary deprecation warnings - if (!is.null(cores)) { - warning("'cores' is deprecated. Please use 'parallel_chains' instead.") - parallel_chains <- cores - } - if (!is.null(num_cores)) { - warning("'num_cores' is deprecated. Please use 'parallel_chains' instead.") - parallel_chains <- num_cores - } - if (!is.null(num_chains)) { - warning("'num_chains' is deprecated. Please use 'chains' instead.") - chains <- num_chains - } - if (!is.null(num_warmup)) { - warning("'num_warmup' is deprecated. Please use 'iter_warmup' instead.") - iter_warmup <- num_warmup - } - if (!is.null(num_samples)) { - warning("'num_samples' is deprecated. Please use 'iter_sampling' instead.") - iter_sampling <- num_samples - } - if (!is.null(max_depth)) { - warning("'max_depth' is deprecated. Please use 'max_treedepth' instead.") - max_treedepth <- max_depth - } - if (!is.null(stepsize)) { - warning("'stepsize' is deprecated. Please use 'step_size' instead.") - step_size <- stepsize - } - if (!is.null(save_extra_diagnostics)) { - warning("'save_extra_diagnostics' is deprecated. Please use 'save_latent_dynamics' instead.") - save_latent_dynamics <- save_extra_diagnostics - } - if (!is.null(validate_csv)) { - warning("'validate_csv' is deprecated. Please use 'diagnostics' instead.") - if (is.logical(validate_csv)) { - if (validate_csv) { - diagnostics <- c("divergences", "treedepth", "ebfmi") - } else { - diagnostics <- NULL - } - } - } + save_cmdstan_config = NULL) { if (cmdstan_version() >= "2.27.0" && cmdstan_version() < "2.36.0" && !fixed_param) { if (self$has_stan_file() && file.exists(self$stan_file())) { @@ -1318,7 +1246,6 @@ CmdStanModel$set("public", name = "sample", value = sample) #' processes. For example, `mpi_args = list("n" = 4)` launches the executable #' as `mpiexec -n 4 model_executable`, followed by CmdStan arguments for the #' model executable. -#' @param validate_csv Deprecated. Use `diagnostics` instead. #' #' @return A [`CmdStanMCMC`] object. #' @@ -1364,20 +1291,7 @@ sample_mpi <- function(data = NULL, show_messages = TRUE, show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), - save_cmdstan_config = NULL, - # deprecated - validate_csv = TRUE) { - - if (!is.null(validate_csv)) { - warning("'validate_csv' is deprecated. Please use 'diagnostics' instead.") - if (is.logical(validate_csv)) { - if (validate_csv) { - diagnostics <- c("divergences", "treedepth", "ebfmi") - } else { - diagnostics <- NULL - } - } - } + save_cmdstan_config = NULL) { if (fixed_param) { chains <- 1 @@ -1767,10 +1681,8 @@ CmdStanModel$set("public", name = "laplace", value = laplace) #' @param tol_rel_obj (positive real) Convergence tolerance on the relative norm #' of the objective. #' @param eval_elbo (positive integer) Evaluate ELBO every Nth iteration. -#' @param output_samples (positive integer) Use `draws` argument instead. -#' `output_samples` will be deprecated in the future. -#' @param draws (positive integer) Number of approximate posterior -#' samples to draw and save. +#' @param draws (positive integer) Number of approximate posterior samples to +#' draw and save. #' #' @return A [`CmdStanVB`] object. #' @@ -1796,7 +1708,6 @@ variational <- function(data = NULL, adapt_iter = NULL, tol_rel_obj = NULL, eval_elbo = NULL, - output_samples = NULL, draws = NULL, show_messages = TRUE, show_exceptions = TRUE, @@ -1821,7 +1732,7 @@ variational <- function(data = NULL, adapt_iter = adapt_iter, tol_rel_obj = tol_rel_obj, eval_elbo = eval_elbo, - output_samples = draws %||% output_samples + output_samples = draws ) args <- CmdStanArgs$new( method_args = variational_args, diff --git a/R/path.R b/R/path.R index 15bbeae69..8b7d6fe65 100644 --- a/R/path.R +++ b/R/path.R @@ -39,7 +39,7 @@ #' set_cmdstan_path <- function(path = NULL) { if (is.null(path)) { - path <- cmdstan_default_path() %||% cmdstan_default_path(old = TRUE) + path <- cmdstan_default_path() } if (dir.exists(path)) { path <- absolute_path(path) @@ -105,20 +105,14 @@ stop_no_path <- function() { #' Path to where [install_cmdstan()] with default settings installs CmdStan. #' #' @keywords internal -#' @param old Should the old default path (.cmdstanr) be used instead of the new -#' one (.cmdstan)? Defaults to `FALSE` and may be removed in a future release. #' @param wsl Return the directory for WSL installations? #' @return The installation path. #' @export -cmdstan_default_install_path <- function(old = FALSE, wsl = FALSE) { +cmdstan_default_install_path <- function(wsl = FALSE) { if (wsl) { file.path(paste0(wsl_dir_prefix(wsl = TRUE), wsl_home_dir()), ".cmdstan") } else { - if (old) { - file.path(.home_path(), ".cmdstanr") - } else { - file.path(.home_path(), ".cmdstan") - } + file.path(.home_path(), ".cmdstan") } } @@ -134,23 +128,22 @@ cmdstan_default_install_path <- function(old = FALSE, wsl = FALSE) { #' #' @export #' @keywords internal -#' @param old See [cmdstan_default_install_path()]. #' @param dir Path to a custom install folder with CmdStan installations. #' @return Path to the CmdStan installation with the most recent release #' version, or `NULL` if no installation found. #' -cmdstan_default_path <- function(old = FALSE, dir = NULL) { +cmdstan_default_path <- function(dir = NULL) { if (!is.null(dir)) { installs_path <- dir } else { - installs_path <- cmdstan_default_install_path(old) + installs_path <- cmdstan_default_install_path() } wsl_installed <- wsl_installed() if (!isTRUE(wsl_installed)) { wsl_installs_path <- NULL wsl_path_exists <- FALSE } else { - wsl_installs_path <- cmdstan_default_install_path(old, wsl = TRUE) + wsl_installs_path <- cmdstan_default_install_path(wsl = TRUE) wsl_path_linux <- gsub(wsl_dir_prefix(wsl = TRUE), "", wsl_installs_path, fixed=TRUE) wsl_path_exists <- isTRUE(.wsl_check_exists(wsl_path_linux)) diff --git a/R/utils.R b/R/utils.R index 4fde81492..d2cf10f5e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -252,32 +252,6 @@ generate_file_names <- new_names } -# threading helpers (deprecated) ------------------------------------------ - - -#' Set or get the number of threads used to execute Stan models -#' -#' DEPRECATED. Please use the `threads_per_chain` argument when fitting the model. -#' @keywords internal -#' @name stan_threads -NULL - -#' @rdname stan_threads -#' @export -#' @return The value of the environment variable `STAN_NUM_THREADS`. -num_threads <- function() { - warning("'num_threads()' is deprecated. Please use the 'metadata()' method of the fit object to obtain the number of threads used.") - as.integer(Sys.getenv("STAN_NUM_THREADS")) -} - -#' @rdname stan_threads -#' @export -#' @param num_threads (positive integer) The number of threads to set. -set_num_threads <- function(num_threads) { - stop("Please use the 'threads_per_chain' argument in the $sample() method instead of set_num_threads().", - call. = FALSE) -} - # hmc diagnostics ------------------------------------------------------ check_divergences <- function(post_warmup_sampler_diagnostics) { diff --git a/man/cmdstan_default_install_path.Rd b/man/cmdstan_default_install_path.Rd index 07ddb8377..b5ebd9b73 100644 --- a/man/cmdstan_default_install_path.Rd +++ b/man/cmdstan_default_install_path.Rd @@ -4,12 +4,9 @@ \alias{cmdstan_default_install_path} \title{cmdstan_default_install_path} \usage{ -cmdstan_default_install_path(old = FALSE, wsl = FALSE) +cmdstan_default_install_path(wsl = FALSE) } \arguments{ -\item{old}{Should the old default path (.cmdstanr) be used instead of the new -one (.cmdstan)? Defaults to \code{FALSE} and may be removed in a future release.} - \item{wsl}{Return the directory for WSL installations?} } \value{ diff --git a/man/cmdstan_default_path.Rd b/man/cmdstan_default_path.Rd index 36aab208c..2d4ffe9b0 100644 --- a/man/cmdstan_default_path.Rd +++ b/man/cmdstan_default_path.Rd @@ -4,11 +4,9 @@ \alias{cmdstan_default_path} \title{cmdstan_default_path} \usage{ -cmdstan_default_path(old = FALSE, dir = NULL) +cmdstan_default_path(dir = NULL) } \arguments{ -\item{old}{See \code{\link[=cmdstan_default_install_path]{cmdstan_default_install_path()}}.} - \item{dir}{Path to a custom install folder with CmdStan installations.} } \value{ diff --git a/man/fit-method-grad_log_prob.Rd b/man/fit-method-grad_log_prob.Rd index 5012d79c6..f240c4bbc 100644 --- a/man/fit-method-grad_log_prob.Rd +++ b/man/fit-method-grad_log_prob.Rd @@ -6,19 +6,13 @@ \title{Calculate the log-probability and the gradient w.r.t. each input for a given vector of unconstrained parameters} \usage{ -grad_log_prob( - unconstrained_variables, - jacobian = TRUE, - jacobian_adjustment = NULL -) +grad_log_prob(unconstrained_variables, jacobian = TRUE) } \arguments{ \item{unconstrained_variables}{(numeric) A vector of unconstrained parameters.} \item{jacobian}{(logical) Whether to include the log-density adjustments from un/constraining variables.} - -\item{jacobian_adjustment}{Deprecated. Please use \code{jacobian} instead.} } \description{ The \verb{$grad_log_prob()} method provides access to the Stan diff --git a/man/fit-method-hessian.Rd b/man/fit-method-hessian.Rd index 8076a8898..f4f1ec555 100644 --- a/man/fit-method-hessian.Rd +++ b/man/fit-method-hessian.Rd @@ -6,15 +6,13 @@ \title{Calculate the log-probability , the gradient w.r.t. each input, and the hessian for a given vector of unconstrained parameters} \usage{ -hessian(unconstrained_variables, jacobian = TRUE, jacobian_adjustment = NULL) +hessian(unconstrained_variables, jacobian = TRUE) } \arguments{ \item{unconstrained_variables}{(numeric) A vector of unconstrained parameters.} \item{jacobian}{(logical) Whether to include the log-density adjustments from un/constraining variables.} - -\item{jacobian_adjustment}{Deprecated. Please use \code{jacobian} instead.} } \description{ The \verb{$hessian()} method provides access to the Stan model's diff --git a/man/fit-method-log_prob.Rd b/man/fit-method-log_prob.Rd index 456fb82cb..a3652eacc 100644 --- a/man/fit-method-log_prob.Rd +++ b/man/fit-method-log_prob.Rd @@ -5,15 +5,13 @@ \alias{log_prob} \title{Calculate the log-probability given a provided vector of unconstrained parameters.} \usage{ -log_prob(unconstrained_variables, jacobian = TRUE, jacobian_adjustment = NULL) +log_prob(unconstrained_variables, jacobian = TRUE) } \arguments{ \item{unconstrained_variables}{(numeric) A vector of unconstrained parameters.} \item{jacobian}{(logical) Whether to include the log-density adjustments from un/constraining variables.} - -\item{jacobian_adjustment}{Deprecated. Please use \code{jacobian} instead.} } \description{ The \verb{$log_prob()} method provides access to the Stan model's diff --git a/man/model-method-compile.Rd b/man/model-method-compile.Rd index c92f27048..60a68db52 100644 --- a/man/model-method-compile.Rd +++ b/man/model-method-compile.Rd @@ -16,9 +16,7 @@ compile( force_recompile = getOption("cmdstanr_force_recompile", default = FALSE), compile_model_methods = FALSE, compile_standalone = FALSE, - dry_run = FALSE, - compile_hessian_method = FALSE, - threads = FALSE + dry_run = FALSE ) } \arguments{ @@ -75,9 +73,6 @@ but skip the actual C++ compilation. Used to speedup tests.} \item{compile_hessian_method}{(logical) Should the (experimental) \code{hessian()} method be be compiled with the model methods?} - -\item{threads}{Deprecated and will be removed in a future release. Please -turn on threading via \code{cpp_options = list(stan_threads = TRUE)} instead.} } \value{ The \verb{$compile()} method is called for its side effect of creating the diff --git a/man/model-method-sample.Rd b/man/model-method-sample.Rd index 2558e6301..72fba0480 100644 --- a/man/model-method-sample.Rd +++ b/man/model-method-sample.Rd @@ -38,16 +38,7 @@ sample( show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), save_metric = NULL, - save_cmdstan_config = NULL, - cores = NULL, - num_cores = NULL, - num_chains = NULL, - num_warmup = NULL, - num_samples = NULL, - validate_csv = NULL, - save_extra_diagnostics = NULL, - max_depth = NULL, - stepsize = NULL + save_cmdstan_config = NULL ) } \arguments{ @@ -302,8 +293,6 @@ is \code{TRUE}. This option is only available in CmdStan 2.34.0 and later.} with argument \code{"output save_config=1"} to save a json file which contains the argument tree and extra information (equivalent to the output CSV file header). This option is only available in CmdStan 2.34.0 and later.} - -\item{cores, num_cores, num_chains, num_warmup, num_samples, save_extra_diagnostics, max_depth, stepsize, validate_csv}{Deprecated and will be removed in a future release.} } \value{ A \code{\link{CmdStanMCMC}} object. diff --git a/man/model-method-sample_mpi.Rd b/man/model-method-sample_mpi.Rd index 282183a82..b33464f44 100644 --- a/man/model-method-sample_mpi.Rd +++ b/man/model-method-sample_mpi.Rd @@ -36,8 +36,7 @@ sample_mpi( show_messages = TRUE, show_exceptions = TRUE, diagnostics = c("divergences", "treedepth", "ebfmi"), - save_cmdstan_config = NULL, - validate_csv = TRUE + save_cmdstan_config = NULL ) } \arguments{ @@ -275,8 +274,6 @@ using the \code{\link[=fit-method-summary]{$summary()}} method.} with argument \code{"output save_config=1"} to save a json file which contains the argument tree and extra information (equivalent to the output CSV file header). This option is only available in CmdStan 2.34.0 and later.} - -\item{validate_csv}{Deprecated. Use \code{diagnostics} instead.} } \value{ A \code{\link{CmdStanMCMC}} object. diff --git a/man/model-method-variational.Rd b/man/model-method-variational.Rd index 5deafe841..4313dcec0 100644 --- a/man/model-method-variational.Rd +++ b/man/model-method-variational.Rd @@ -25,7 +25,6 @@ variational( adapt_iter = NULL, tol_rel_obj = NULL, eval_elbo = NULL, - output_samples = NULL, draws = NULL, show_messages = TRUE, show_exceptions = TRUE, @@ -180,11 +179,8 @@ of the objective.} \item{eval_elbo}{(positive integer) Evaluate ELBO every Nth iteration.} -\item{output_samples}{(positive integer) Use \code{draws} argument instead. -\code{output_samples} will be deprecated in the future.} - -\item{draws}{(positive integer) Number of approximate posterior -samples to draw and save.} +\item{draws}{(positive integer) Number of approximate posterior samples to +draw and save.} \item{show_messages}{(logical) When \code{TRUE} (the default), prints all output during the execution process, such as iteration numbers and elapsed times. diff --git a/man/read_sample_csv.Rd b/man/read_sample_csv.Rd deleted file mode 100644 index 4c7661ae7..000000000 --- a/man/read_sample_csv.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/csv.R -\name{read_sample_csv} -\alias{read_sample_csv} -\title{Read CmdStan CSV files from sampling into \R} -\usage{ -read_sample_csv(files, variables = NULL, sampler_diagnostics = NULL) -} -\arguments{ -\item{files, variables, sampler_diagnostics}{Deprecated. Use -\code{\link[=read_cmdstan_csv]{read_cmdstan_csv()}} instead.} -} -\description{ -Deprecated. Use \code{\link[=read_cmdstan_csv]{read_cmdstan_csv()}} instead. -} -\keyword{internal} diff --git a/man/stan_threads.Rd b/man/stan_threads.Rd deleted file mode 100644 index e8cf8470d..000000000 --- a/man/stan_threads.Rd +++ /dev/null @@ -1,22 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{stan_threads} -\alias{stan_threads} -\alias{num_threads} -\alias{set_num_threads} -\title{Set or get the number of threads used to execute Stan models} -\usage{ -num_threads() - -set_num_threads(num_threads) -} -\arguments{ -\item{num_threads}{(positive integer) The number of threads to set.} -} -\value{ -The value of the environment variable \code{STAN_NUM_THREADS}. -} -\description{ -DEPRECATED. Please use the \code{threads_per_chain} argument when fitting the model. -} -\keyword{internal} diff --git a/man/write_stan_tempfile.Rd b/man/write_stan_tempfile.Rd deleted file mode 100644 index e663302fe..000000000 --- a/man/write_stan_tempfile.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/example.R -\name{write_stan_tempfile} -\alias{write_stan_tempfile} -\title{Write Stan code to a temporary file} -\usage{ -write_stan_tempfile(code, dir = tempdir()) -} -\arguments{ -\item{code}{(character vector) The Stan code to write to the file. This can -be a character vector of length one (a string) containing the entire Stan -program or a character vector with each element containing one line of the -Stan program.} - -\item{dir}{(string) An optional path to the directory where the file will be -written. If omitted, a global option \code{cmdstanr_write_stan_file_dir} is -used. If the global options is not set, \link[base:tempfile]{temporary directory} -is used.} -} -\description{ -This function is deprecated. Please use \code{\link[=write_stan_file]{write_stan_file()}} instead. -} -\keyword{internal} diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R index 8d14d5d0e..a2db74dee 100644 --- a/tests/testthat/test-example.R +++ b/tests/testthat/test-example.R @@ -100,10 +100,6 @@ test_that("write_stan_file by default creates the same file for the same Stan mo try(file.remove(f1, f2, f4), silent = TRUE) }) -test_that("write_stan_tempfile is deprecated", { - expect_warning(write_stan_tempfile(stan_program), "deprecated") -}) - test_that("cmdstanr_write_stan_file_dir option works", { base_dir <- tempdir() test_dir <- file.path(base_dir, "option_test") diff --git a/tests/testthat/test-model-compile.R b/tests/testthat/test-model-compile.R index 9517aeabf..9f61b3323 100644 --- a/tests/testthat/test-model-compile.R +++ b/tests/testthat/test-model-compile.R @@ -157,7 +157,6 @@ test_that("switching threads on and off works without rebuild", { after_mtime <- file.mtime(main_path_o) expect_equal(before_mtime, after_mtime) - expect_warning(mod$compile(threads = TRUE, dry_run = TRUE), "deprecated") cmdstan_make_local(cpp_options = backup, append = FALSE) }) From 87f4d88bc409edefbd7e7fcc8f456bf817896944 Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 14:18:09 -0700 Subject: [PATCH 2/9] try to get more info about build failure --- .github/workflows/R-CMD-check.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c2df6e461..0346a0d4c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -58,9 +58,12 @@ jobs: - uses: r-lib/actions/setup-pandoc@v2.11.1 - uses: r-lib/actions/setup-r-dependencies@v2.11.1 + env: + PAK_BUILD_VERBOSE: 1 with: cache: "always" extra-packages: any::rcmdcheck, local::. + verbose: true - name: Install POCL on Ubuntu Runners if: ${{ matrix.config.os == 'ubuntu-latest' }} From ecf12bb77ecc8c85ebf8b6c24fa38b67343d7eb7 Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 14:25:10 -0700 Subject: [PATCH 3/9] Update R-CMD-check.yaml --- .github/workflows/R-CMD-check.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0346a0d4c..981c842af 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -60,6 +60,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2.11.1 env: PAK_BUILD_VERBOSE: 1 + PKGDEPENDS_DEBUG: 1 with: cache: "always" extra-packages: any::rcmdcheck, local::. From 53b3ef2ec9db7d1ed9282282d3d2dd5a09a85715 Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 14:31:48 -0700 Subject: [PATCH 4/9] try building manually to see if I can get info on the build failure --- .github/workflows/R-CMD-check.yaml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 981c842af..1b9d833d1 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -58,13 +58,12 @@ jobs: - uses: r-lib/actions/setup-pandoc@v2.11.1 - uses: r-lib/actions/setup-r-dependencies@v2.11.1 - env: - PAK_BUILD_VERBOSE: 1 - PKGDEPENDS_DEBUG: 1 with: cache: "always" - extra-packages: any::rcmdcheck, local::. - verbose: true + extra-packages: any::rcmdcheck # Note: local::. is removed temporarily + + - name: Manually build package for debugging + run: R CMD INSTALL --no-clean-on-error --verbose . - name: Install POCL on Ubuntu Runners if: ${{ matrix.config.os == 'ubuntu-latest' }} From 3ab41b8441212ba2aebf496537214faafacf9e4c Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 14:37:25 -0700 Subject: [PATCH 5/9] fix build error --- .github/workflows/R-CMD-check.yaml | 5 +---- R/zzz.R | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 1b9d833d1..c2df6e461 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -60,10 +60,7 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2.11.1 with: cache: "always" - extra-packages: any::rcmdcheck # Note: local::. is removed temporarily - - - name: Manually build package for debugging - run: R CMD INSTALL --no-clean-on-error --verbose . + extra-packages: any::rcmdcheck, local::. - name: Install POCL on Ubuntu Runners if: ${{ matrix.config.os == 'ubuntu-latest' }} diff --git a/R/zzz.R b/R/zzz.R index 860eb8944..6f80b5ca2 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -65,7 +65,7 @@ cmdstanr_initialize <- function() { } } else { # environment variable not found - path <- cmdstan_default_path() %||% cmdstan_default_path(old = TRUE) + path <- cmdstan_default_path() if (!is.null(path)) { suppressMessages(set_cmdstan_path(path)) } From 9a318ea3c76c3a25fb99107b368e72c740e7975c Mon Sep 17 00:00:00 2001 From: jgabry Date: Wed, 12 Feb 2025 16:27:11 -0700 Subject: [PATCH 6/9] output_samples -> draws in failing tests --- tests/testthat/test-csv.R | 2 +- tests/testthat/test-fit-shared.R | 2 +- tests/testthat/test-fit-vb.R | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/testthat/test-csv.R b/tests/testthat/test-csv.R index 6dc331fee..6c3c31f0f 100644 --- a/tests/testthat/test-csv.R +++ b/tests/testthat/test-csv.R @@ -6,7 +6,7 @@ fit_bernoulli_variational <- testing_fit("bernoulli", method = "variational", se fit_bernoulli_laplace <- testing_fit("bernoulli", method = "laplace", seed = 123) fit_logistic_optimize <- testing_fit("logistic", method = "optimize", seed = 123) fit_logistic_variational <- testing_fit("logistic", method = "variational", seed = 123) -fit_logistic_variational_short <- testing_fit("logistic", method = "variational", output_samples = 100, seed = 123) +fit_logistic_variational_short <- testing_fit("logistic", method = "variational", draws = 100, seed = 123) fit_logistic_laplace <- testing_fit("logistic", method = "laplace", seed = 123) fit_bernoulli_diag_e_no_samples <- testing_fit("bernoulli", method = "sample", diff --git a/tests/testthat/test-fit-shared.R b/tests/testthat/test-fit-shared.R index 0f98e64ac..2b07abb87 100644 --- a/tests/testthat/test-fit-shared.R +++ b/tests/testthat/test-fit-shared.R @@ -437,7 +437,7 @@ test_that("draws are returned for model with spaces", { ) expect_equal(dim(fit_sample$draws()), c(1000, 1, 3)) utils::capture.output( - fit <- mod$variational(seed = 123, output_samples = 1000) + fit <- mod$variational(seed = 123, draws = 1000) ) expect_equal(dim(fit$draws()), c(1000, 4)) utils::capture.output( diff --git a/tests/testthat/test-fit-vb.R b/tests/testthat/test-fit-vb.R index 0e8a4dd9d..e701e951a 100644 --- a/tests/testthat/test-fit-vb.R +++ b/tests/testthat/test-fit-vb.R @@ -90,7 +90,7 @@ test_that("time is reported after vb", { seed = 123, elbo_samples = 1000, iter = 2000, - output_samples = 50 + draws = 50 ), "Finished in" ) From 0fad801004c70ad1cf880b4abea455f46047eb3d Mon Sep 17 00:00:00 2001 From: jgabry Date: Thu, 13 Feb 2025 13:56:43 -0700 Subject: [PATCH 7/9] get rid of 'compile_hessian_method' --- R/model.R | 7 +------ R/utils.R | 2 +- man/model-method-compile.Rd | 3 --- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/R/model.R b/R/model.R index e119ded19..e63c24e54 100644 --- a/R/model.R +++ b/R/model.R @@ -413,8 +413,6 @@ CmdStanModel <- R6::R6Class( #' @param compile_model_methods (logical) Compile additional model methods #' (`log_prob()`, `grad_log_prob()`, `constrain_variables()`, #' `unconstrain_variables()`). -#' @param compile_hessian_method (logical) Should the (experimental) `hessian()` method be -#' be compiled with the model methods? #' @param compile_standalone (logical) Should functions in the Stan model be #' compiled for use in R? If `TRUE` the functions will be available via the #' `functions` field in the compiled model object. This can also be done after @@ -595,7 +593,6 @@ compile <- function(quiet = TRUE, call. = FALSE) compile_model_methods <- FALSE compile_standalone <- FALSE - compile_hessian_method <- FALSE } temp_stan_file <- tempfile(pattern = "model-", fileext = paste0(".", tools::file_ext(self$stan_file()))) @@ -728,9 +725,7 @@ compile <- function(quiet = TRUE, if(!dry_run) { if (compile_model_methods) { - expose_model_methods(env = private$model_methods_env_, - verbose = !quiet, - hessian = compile_hessian_method) + expose_model_methods(env = private$model_methods_env_, verbose = !quiet) } } invisible(self) diff --git a/R/utils.R b/R/utils.R index d2cf10f5e..e2bd04eb0 100644 --- a/R/utils.R +++ b/R/utils.R @@ -787,7 +787,7 @@ rcpp_source_stan <- function(code, env, verbose = FALSE, ...) { invisible(NULL) } -expose_model_methods <- function(env, verbose = FALSE, hessian = FALSE) { +expose_model_methods <- function(env, verbose = FALSE) { if (rlang::is_interactive()) { message("Compiling additional model methods...") } diff --git a/man/model-method-compile.Rd b/man/model-method-compile.Rd index 60a68db52..461a2e635 100644 --- a/man/model-method-compile.Rd +++ b/man/model-method-compile.Rd @@ -70,9 +70,6 @@ compilation using the \item{dry_run}{(logical) If \code{TRUE}, the code will do all checks before compilation, but skip the actual C++ compilation. Used to speedup tests.} - -\item{compile_hessian_method}{(logical) Should the (experimental) \code{hessian()} method be -be compiled with the model methods?} } \value{ The \verb{$compile()} method is called for its side effect of creating the From a1f88a074f797c1f489ed9ebea21ab00cc552461 Mon Sep 17 00:00:00 2001 From: jgabry Date: Fri, 14 Feb 2025 10:02:50 -0700 Subject: [PATCH 8/9] fix text failures due to hessian --- NEWS.md | 1 + R/fit.R | 26 ++++++++++++-------------- man/fit-method-hessian.Rd | 2 +- man/fit-method-init_model_methods.Rd | 20 ++++++++++++-------- 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/NEWS.md b/NEWS.md index d2906ea0b..089c75ac1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,7 @@ - `model_params` element of `fit$metadata()` list (`variables` element) - `jacobian_adjustment` argument to `fit$log_prob()` and similar methods (`jacobian` argument) - `output_samples` argument to `model$variational()` (`draws` argument) + - `hessian` argument to `fit$init_model_methods()` (`hessian` method always compiled now) - several arguments to `model$compile()`: - `threads` (`cpp_options = list(stan_threads = TRUE)`) - `compile_hessian_method` (always compiled) diff --git a/R/fit.R b/R/fit.R index 51b05b8fd..76a0e9722 100644 --- a/R/fit.R +++ b/R/fit.R @@ -314,28 +314,31 @@ CmdStanFit$set("public", name = "init", value = init) #' @aliases init_model_methods #' #' @description The `$init_model_methods()` method compiles and initializes the -#' `log_prob`, `grad_log_prob`, `constrain_variables`, `unconstrain_variables` -#' and `unconstrain_draws` functions. These are then available as methods of -#' the fitted model object. This requires the additional `Rcpp` package, -#' which are not required for fitting models using +#' `log_prob`, `grad_log_prob`, `hessian`, `constrain_variables`, +#' `unconstrain_variables` and `unconstrain_draws` functions. These are then +#' available as methods of the fitted model object. This requires the +#' additional `Rcpp` package, which are not required for fitting models using #' CmdStanR. #' -#' Note: there may be many compiler warnings emitted during compilation but +#' Notes: +#' * There may be many compiler warnings emitted during compilation but #' these can be ignored so long as they are warnings and not errors. +#' * The hessian method relies on higher-order autodiff, which is still +#' experimental. Please report any compilation errors that you encounter. #' #' @param seed (integer) The random seed to use when initializing the model. #' @param verbose (logical) Whether to show verbose logging during compilation. -#' @param hessian (logical) Whether to expose the (experimental) hessian method. #' #' @examples #' \dontrun{ #' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE) +#' # fit_mcmc$init_model_methods() #' } #' @seealso [log_prob()], [grad_log_prob()], [constrain_variables()], #' [unconstrain_variables()], [unconstrain_draws()], [variable_skeleton()], #' [hessian()] #' -init_model_methods <- function(seed = 1, verbose = FALSE, hessian = FALSE) { +init_model_methods <- function(seed = 1, verbose = FALSE) { if (os_is_wsl()) { stop("Additional model methods are not currently available with ", "WSL CmdStan and will not be compiled", @@ -346,13 +349,8 @@ init_model_methods <- function(seed = 1, verbose = FALSE, hessian = FALSE) { stop("Model methods cannot be used with a pre-compiled Stan executable, ", "the model must be compiled again", call. = FALSE) } - if (hessian) { - message("The hessian method relies on higher-order autodiff ", - "which is still experimental. Please report any compilation ", - "errors that you encounter") - } if (is.null(private$model_methods_env_$model_ptr)) { - expose_model_methods(private$model_methods_env_, verbose, hessian) + expose_model_methods(private$model_methods_env_, verbose) } if (!("model_ptr_" %in% ls(private$model_methods_env_))) { initialize_model_pointer(private$model_methods_env_, self$data_file(), seed) @@ -435,7 +433,7 @@ CmdStanFit$set("public", name = "grad_log_prob", value = grad_log_prob) #' @examples #' \dontrun{ #' fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE) -#' # fit_mcmc$init_model_methods(hessian = TRUE) +#' # fit_mcmc$init_model_methods() #' # fit_mcmc$hessian(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2)) #' } #' diff --git a/man/fit-method-hessian.Rd b/man/fit-method-hessian.Rd index f4f1ec555..8dfbf03ab 100644 --- a/man/fit-method-hessian.Rd +++ b/man/fit-method-hessian.Rd @@ -21,7 +21,7 @@ The \verb{$hessian()} method provides access to the Stan model's \examples{ \dontrun{ fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE) -# fit_mcmc$init_model_methods(hessian = TRUE) +# fit_mcmc$init_model_methods() # fit_mcmc$hessian(unconstrained_variables = c(0.5, 1.2, 1.1, 2.2)) } diff --git a/man/fit-method-init_model_methods.Rd b/man/fit-method-init_model_methods.Rd index 64fa8a763..e368bb46c 100644 --- a/man/fit-method-init_model_methods.Rd +++ b/man/fit-method-init_model_methods.Rd @@ -6,29 +6,33 @@ \title{Compile additional methods for accessing the model log-probability function and parameter constraining and unconstraining.} \usage{ -init_model_methods(seed = 1, verbose = FALSE, hessian = FALSE) +init_model_methods(seed = 1, verbose = FALSE) } \arguments{ \item{seed}{(integer) The random seed to use when initializing the model.} \item{verbose}{(logical) Whether to show verbose logging during compilation.} - -\item{hessian}{(logical) Whether to expose the (experimental) hessian method.} } \description{ The \verb{$init_model_methods()} method compiles and initializes the -\code{log_prob}, \code{grad_log_prob}, \code{constrain_variables}, \code{unconstrain_variables} -and \code{unconstrain_draws} functions. These are then available as methods of -the fitted model object. This requires the additional \code{Rcpp} package, -which are not required for fitting models using +\code{log_prob}, \code{grad_log_prob}, \code{hessian}, \code{constrain_variables}, +\code{unconstrain_variables} and \code{unconstrain_draws} functions. These are then +available as methods of the fitted model object. This requires the +additional \code{Rcpp} package, which are not required for fitting models using CmdStanR. -Note: there may be many compiler warnings emitted during compilation but +Notes: +\itemize{ +\item There may be many compiler warnings emitted during compilation but these can be ignored so long as they are warnings and not errors. +\item The hessian method relies on higher-order autodiff, which is still +experimental. Please report any compilation errors that you encounter. +} } \examples{ \dontrun{ fit_mcmc <- cmdstanr_example("logistic", method = "sample", force_recompile = TRUE) +# fit_mcmc$init_model_methods() } } \seealso{ From c5991be763d27380c79423a2274d2499f1806de7 Mon Sep 17 00:00:00 2001 From: jgabry Date: Mon, 3 Mar 2025 14:31:09 -0700 Subject: [PATCH 9/9] remove outdated comment on hessian method --- R/fit.R | 5 +---- man/fit-method-init_model_methods.Rd | 7 +------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/R/fit.R b/R/fit.R index 76a0e9722..cf435a000 100644 --- a/R/fit.R +++ b/R/fit.R @@ -320,11 +320,8 @@ CmdStanFit$set("public", name = "init", value = init) #' additional `Rcpp` package, which are not required for fitting models using #' CmdStanR. #' -#' Notes: -#' * There may be many compiler warnings emitted during compilation but +#' Note: there may be many compiler warnings emitted during compilation but #' these can be ignored so long as they are warnings and not errors. -#' * The hessian method relies on higher-order autodiff, which is still -#' experimental. Please report any compilation errors that you encounter. #' #' @param seed (integer) The random seed to use when initializing the model. #' @param verbose (logical) Whether to show verbose logging during compilation. diff --git a/man/fit-method-init_model_methods.Rd b/man/fit-method-init_model_methods.Rd index e368bb46c..9e3861022 100644 --- a/man/fit-method-init_model_methods.Rd +++ b/man/fit-method-init_model_methods.Rd @@ -21,13 +21,8 @@ available as methods of the fitted model object. This requires the additional \code{Rcpp} package, which are not required for fitting models using CmdStanR. -Notes: -\itemize{ -\item There may be many compiler warnings emitted during compilation but +Note: there may be many compiler warnings emitted during compilation but these can be ignored so long as they are warnings and not errors. -\item The hessian method relies on higher-order autodiff, which is still -experimental. Please report any compilation errors that you encounter. -} } \examples{ \dontrun{