Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (development version)


* 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)
- `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.9.0

Expand Down
17 changes: 1 addition & 16 deletions R/csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,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 @@ -474,20 +473,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 @@ -329,28 +329,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 @@ -361,13 +361,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 @@ -386,7 +381,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 @@ -398,11 +392,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 @@ -432,11 +422,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 @@ -459,19 +445,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
Loading