Skip to content

Commit

Permalink
remove deprecated arguments and functions
Browse files Browse the repository at this point in the history
closes #409
  • Loading branch information
jgabry committed Feb 12, 2025
1 parent ce58981 commit 2dff5f1
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 298 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
21 changes: 20 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
17 changes: 1 addition & 16 deletions R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions R/example.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
19 changes: 3 additions & 16 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 ",
Expand Down Expand Up @@ -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 ",
Expand Down Expand Up @@ -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 ",
Expand Down
101 changes: 6 additions & 95 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
#'
Expand All @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 6 additions & 13 deletions R/path.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}

Expand All @@ -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))
Expand Down
Loading

0 comments on commit 2dff5f1

Please sign in to comment.