Skip to content

Remove deprecated arguments and functions #1061

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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)
22 changes: 21 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# cmdstanr 0.8.1.9000

Items for next release go here
* Removed deprecated items (replacements in parentheses):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a list of the user-facing stuff that's being removed. I guess it's listed under cmdstanr 0.8.1.9000 since that's the placeholder we use for the next release, but it's really for version 1.0

- `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)
- `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)
- 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)
}
40 changes: 11 additions & 29 deletions R/fit.R
Original file line number Diff line number Diff line change
Expand Up @@ -314,28 +314,28 @@ 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
#' these can be ignored so long as they are warnings and not errors.
#'
#' @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",
Expand All @@ -346,13 +346,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)
Expand All @@ -371,7 +366,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 +377,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 +407,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 All @@ -444,19 +430,15 @@ 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))
#' }
#'
#' @seealso [log_prob()], [grad_log_prob()], [constrain_variables()],
#' [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
108 changes: 7 additions & 101 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -423,9 +421,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 +469,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 +499,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 @@ -612,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())))
Expand Down Expand Up @@ -745,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)
Expand Down Expand Up @@ -1113,8 +1091,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 +1129,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 +1241,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 +1286,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 @@ -1774,10 +1683,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 @@ -1803,7 +1710,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 @@ -1828,7 +1734,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
Loading
Loading