Skip to content

Commit 17263e0

Browse files
committed
Merge branch 'master' into min-cmdstan-2-35
2 parents f7f4a10 + f34e00f commit 17263e0

22 files changed

Lines changed: 339 additions & 74 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* text=auto eol=lf
2+
*.rda binary

.github/workflows/R-CMD-check-wsl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ jobs:
8181

8282
- name: Upload check results
8383
if: failure()
84-
uses: actions/upload-artifact@v6
84+
uses: actions/upload-artifact@v7
8585
with:
8686
name: wsl-backend-results
8787
path: check

.github/workflows/R-CMD-check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ jobs:
145145

146146
- name: Upload check results
147147
if: failure()
148-
uses: actions/upload-artifact@v6
148+
uses: actions/upload-artifact@v7
149149
with:
150150
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
151151
path: check

.github/workflows/Test-coverage.yaml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ on:
1010

1111
name: Test coverage
1212

13-
permissions: read-all
13+
permissions:
14+
contents: read
15+
id-token: write
1416

1517
jobs:
1618
test-coverage:
@@ -69,8 +71,6 @@ jobs:
6971
print(cov)
7072
covr::to_cobertura(cov)
7173
shell: Rscript {0}
72-
env:
73-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
7474

7575
- name: Test coverage (Windows)
7676
if: runner.os == 'Windows'
@@ -86,8 +86,6 @@ jobs:
8686
print(cov)
8787
covr::to_cobertura(cov)
8888
shell: Rscript {0}
89-
env:
90-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
9189

9290
- uses: codecov/codecov-action@v5
9391
with:
@@ -96,7 +94,7 @@ jobs:
9694
files: ./cobertura.xml
9795
plugins: noop
9896
disable_search: true
99-
token: ${{ secrets.CODECOV_TOKEN }}
97+
use_oidc: true
10098

10199
- name: Show testthat output
102100
if: always()
@@ -107,7 +105,7 @@ jobs:
107105

108106
- name: Upload test results
109107
if: failure()
110-
uses: actions/upload-artifact@v6
108+
uses: actions/upload-artifact@v7
111109
with:
112110
name: coverage-test-failures
113111
path: ${{ runner.temp }}/package

LICENSE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
YEAR: 2019
22
COPYRIGHT HOLDER: Stan Developers and their Assignees
3+
ORGANIZATION: Stan Development Team (stan-dev)

NEWS.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* Removed deprecated items (replacements in parentheses):
99
- `read_sample_csv()` (`read_cmdstan_csv()`)
1010
- `write_stan_tempfile()` (`write_stan_file()`)
11-
- `model_params` element of `fit$metadata()` list (`variables` element)
1211
- `jacobian_adjustment` argument to `fit$log_prob()` and similar methods (`jacobian` argument)
1312
- `output_samples` argument to `model$variational()` (`draws` argument)
1413
- `hessian` argument to `fit$init_model_methods()` (`hessian` method always compiled now)

R/csv.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ read_cmdstan_csv <- function(files,
328328
model_param_dims <- variable_dims(metadata$variables)
329329
metadata$stan_variable_sizes <- model_param_dims
330330
metadata$stan_variables <- names(model_param_dims)
331-
331+
metadata$model_params <- metadata$variables # for backwards compatibility
332332
if (metadata$method == "sample") {
333333
if (is.null(format)) {
334334
format <- "draws_array"

R/fit.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ lp_approx <- function() {
768768
#' The `$print()` method returns the fitted model object itself (invisibly),
769769
#' which is the standard behavior for print methods in \R.
770770
#'
771+
#' @references
772+
#' * Vehtari, A., Gelman, A., Simpson, D., Carpenter, B., and Buerkner, P.-C.
773+
#' (2021). Rank-normalization, folding, and localization: An improved R-hat
774+
#' for assessing convergence of MCMC (with discussion).
775+
#' *Bayesian Analysis*, 16(2), 667-718. doi:10.1214/20-BA1221.
776+
#' * Vehtari, A. (2021). Comparison of MCMC effective sample size estimators.
777+
#' https://avehtari.github.io/rhat_ess/ess_comparison.html
778+
#' (for ESS diagnostics such as `ess_bulk` and `ess_tail`).
779+
#'
771780
#' @seealso [`CmdStanMCMC`], [`CmdStanMLE`], [`CmdStanLaplace`], [`CmdStanVB`], [`CmdStanGQ`]
772781
#'
773782
#' @examples
@@ -1524,6 +1533,19 @@ CmdStanMCMC <- R6::R6Class(
15241533
#' @return The object returned by [loo::loo.array()] or
15251534
#' [loo::loo_moment_match.default()].
15261535
#'
1536+
#' @references
1537+
#' * Vehtari, A., Gelman, A., and Gabry, J. (2017). Practical Bayesian model
1538+
#' evaluation using leave-one-out cross-validation and WAIC.
1539+
#' *Statistics and Computing*, 27(5), 1413-1432.
1540+
#' doi:10.1007/s11222-016-9696-4.
1541+
#' * Vehtari, A., Simpson, D., Gelman, A., Yao, Y., and Gabry, J. (2024).
1542+
#' Pareto smoothed importance sampling.
1543+
#' *Journal of Machine Learning Research*, 25(72), 1-58.
1544+
#' * Paananen, T., Piironen, J., Buerkner, P.-C., and Vehtari, A. (2021).
1545+
#' Implicitly adaptive importance sampling.
1546+
#' *Statistics and Computing*, 31, 16. doi:10.1007/s11222-020-09982-2
1547+
#' (for `moment_match = TRUE`).
1548+
#'
15271549
#' @seealso The \pkg{loo} package website with
15281550
#' [documentation](https://mc-stan.org/loo/reference/index.html) and
15291551
#' [vignettes](https://mc-stan.org/loo/articles/).

R/model.R

Lines changed: 70 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,19 @@ CmdStanModel$set("public", name = "format", value = format)
10971097
#'
10981098
#' @return A [`CmdStanMCMC`] object.
10991099
#'
1100-
#' @template seealso-docs
1100+
#' @references
1101+
#' * Hoffman, M. D., and Gelman, A. (2014). The No-U-Turn sampler:
1102+
#' adaptively setting path lengths in Hamiltonian Monte Carlo.
1103+
#' *Journal of Machine Learning Research*, 15(47), 1593-1623.
1104+
#' * Betancourt, M. (2017). A conceptual introduction to Hamiltonian Monte Carlo.
1105+
#' arXiv:1701.02434. Appendix A describes Stan's dynamic HMC/NUTS implementation.
1106+
#' * Stan Development Team. Stan Reference Manual (Algorithms section):
1107+
#' https://mc-stan.org/docs/reference-manual/
1108+
#' * Stan Development Team. Stan documentation:
1109+
#' https://mc-stan.org/users/documentation/
1110+
#' * Stan Development Team. CmdStan User's Guide:
1111+
#' https://mc-stan.org/docs/cmdstan-guide/
1112+
#'
11011113
#' @inherit cmdstan_model examples
11021114
#'
11031115
sample <- function(data = NULL,
@@ -1247,7 +1259,19 @@ CmdStanModel$set("public", name = "sample", value = sample)
12471259
#'
12481260
#' @return A [`CmdStanMCMC`] object.
12491261
#'
1250-
#' @template seealso-docs
1262+
#' @references
1263+
#' * Hoffman, M. D., and Gelman, A. (2014). The No-U-Turn sampler:
1264+
#' adaptively setting path lengths in Hamiltonian Monte Carlo.
1265+
#' *Journal of Machine Learning Research*, 15(47), 1593-1623.
1266+
#' * Betancourt, M. (2017). A conceptual introduction to Hamiltonian Monte Carlo.
1267+
#' arXiv:1701.02434. Appendix A describes Stan's dynamic HMC/NUTS implementation.
1268+
#' * Stan Development Team. Stan Reference Manual (Algorithms section):
1269+
#' https://mc-stan.org/docs/reference-manual/
1270+
#' * Stan Development Team. Stan documentation:
1271+
#' https://mc-stan.org/users/documentation/
1272+
#' * Stan Development Team. CmdStan User's Guide:
1273+
#' https://mc-stan.org/docs/cmdstan-guide/
1274+
#'
12511275
#' @seealso The Stan Math Library's documentation
12521276
#' ([mc-stan.org/math](https://mc-stan.org/math/)) for more
12531277
#' details on MPI support in Stan.
@@ -1407,7 +1431,14 @@ CmdStanModel$set("public", name = "sample_mpi", value = sample_mpi)
14071431
#'
14081432
#' @return A [`CmdStanMLE`] object.
14091433
#'
1410-
#' @template seealso-docs
1434+
#' @references
1435+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, optimization):
1436+
#' https://mc-stan.org/docs/reference-manual/
1437+
#' * Stan Development Team. Stan documentation:
1438+
#' https://mc-stan.org/users/documentation/
1439+
#' * Stan Development Team. CmdStan User's Guide:
1440+
#' https://mc-stan.org/docs/cmdstan-guide/
1441+
#'
14111442
#' @inherit cmdstan_model examples
14121443
#'
14131444
optimize <- function(data = NULL,
@@ -1529,7 +1560,14 @@ CmdStanModel$set("public", name = "optimize", value = optimize)
15291560
#'
15301561
#' @return A [`CmdStanLaplace`] object.
15311562
#'
1532-
#' @template seealso-docs
1563+
#' @references
1564+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, Laplace approximation):
1565+
#' https://mc-stan.org/docs/reference-manual/
1566+
#' * Stan Development Team. Stan documentation:
1567+
#' https://mc-stan.org/users/documentation/
1568+
#' * Stan Development Team. CmdStan User's Guide:
1569+
#' https://mc-stan.org/docs/cmdstan-guide/
1570+
#'
15331571
#' @examples
15341572
#' \dontrun{
15351573
#' file <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
@@ -1694,7 +1732,17 @@ CmdStanModel$set("public", name = "laplace", value = laplace)
16941732
#'
16951733
#' @return A [`CmdStanVB`] object.
16961734
#'
1697-
#' @template seealso-docs
1735+
#' @references
1736+
#' * Kucukelbir, A., Tran, D., Ranganath, R., Gelman, A., and Blei, D. M.
1737+
#' (2017). Automatic differentiation variational inference.
1738+
#' *Journal of Machine Learning Research*, 18(14), 1-45.
1739+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, variational inference):
1740+
#' https://mc-stan.org/docs/reference-manual/
1741+
#' * Stan Development Team. Stan documentation:
1742+
#' https://mc-stan.org/users/documentation/
1743+
#' * Stan Development Team. CmdStan User's Guide:
1744+
#' https://mc-stan.org/docs/cmdstan-guide/
1745+
#'
16981746
#' @inherit cmdstan_model examples
16991747
#'
17001748
variational <- function(data = NULL,
@@ -1834,7 +1882,17 @@ CmdStanModel$set("public", name = "variational", value = variational)
18341882
#' pathfinder runs in multi-pathfinder.
18351883
#' @return A [`CmdStanPathfinder`] object.
18361884
#'
1837-
#' @template seealso-docs
1885+
#' @references
1886+
#' * Zhang, L., Carpenter, B., Gelman, A., and Vehtari, A. (2022).
1887+
#' Pathfinder: parallel quasi-Newton variational inference.
1888+
#' *Journal of Machine Learning Research*, 23(306), 1-49.
1889+
#' * Stan Development Team. Stan Reference Manual (Algorithms section, Pathfinder):
1890+
#' https://mc-stan.org/docs/reference-manual/
1891+
#' * Stan Development Team. Stan documentation:
1892+
#' https://mc-stan.org/users/documentation/
1893+
#' * Stan Development Team. CmdStan User's Guide:
1894+
#' https://mc-stan.org/docs/cmdstan-guide/
1895+
#'
18381896
#' @inherit cmdstan_model examples
18391897
#'
18401898
pathfinder <- function(data = NULL,
@@ -2001,12 +2059,16 @@ generate_quantities <- function(fitted_params,
20012059
sig_figs = NULL,
20022060
parallel_chains = getOption("mc.cores", 1),
20032061
threads_per_chain = NULL,
2004-
opencl_ids = NULL) {
2062+
opencl_ids = NULL,
2063+
show_messages = TRUE,
2064+
show_exceptions = TRUE) {
20052065
fitted_params_files <- process_fitted_params(fitted_params)
20062066
procs <- CmdStanGQProcs$new(
20072067
num_procs = length(fitted_params_files),
20082068
parallel_procs = checkmate::assert_integerish(parallel_chains, lower = 1, null.ok = TRUE),
2009-
threads_per_proc = assert_valid_threads(threads_per_chain, self$cpp_options(), multiple_chains = TRUE)
2069+
threads_per_proc = assert_valid_threads(threads_per_chain, self$cpp_options(), multiple_chains = TRUE),
2070+
show_stderr_messages = show_exceptions,
2071+
show_stdout_messages = show_messages
20102072
)
20112073
model_variables <- NULL
20122074
if (is_variables_method_supported(self)) {

R/utils.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,32 @@ compile_functions <- function(env, verbose = FALSE, global = FALSE) {
955955
prep_fun_cpp(funs[ind], fun_end, env$hpp_code)
956956
})
957957

958+
reserved_names <- unique(
959+
unlist(
960+
lapply(stan_funs, function(stan_fun) {
961+
regmatches(
962+
stan_fun,
963+
gregexpr("(?<=_stan_)[[:alnum:]_]+", stan_fun, perl = TRUE)
964+
)[[1]]
965+
}),
966+
use.names = FALSE
967+
)
968+
)
969+
970+
if (length(reserved_names) > 0) {
971+
stop(
972+
paste0(
973+
"expose_functions() can't expose this Stan function because the function ",
974+
"name and/or one or more argument names use a reserved keyword ",
975+
"(typically in the C++ toolchain used to compile Stan). Please rename ",
976+
"the function/arguments in your Stan functions block and try again. ",
977+
"Conflicting names: ",
978+
paste(reserved_names, collapse = ", ")
979+
),
980+
call. = FALSE
981+
)
982+
}
983+
958984
env$fun_names <- sapply(seq_len(length(funs) - 1), function(ind) {
959985
get_function_name(funs[ind], funs[ind + 1], env$hpp_code)
960986
})

0 commit comments

Comments
 (0)