Skip to content

Commit

Permalink
Merge pull request #343 from stan-dev/various_minor_fixes
Browse files Browse the repository at this point in the history
Minor fixes and version 0.2.0
  • Loading branch information
jgabry authored Nov 12, 2020
2 parents baed002 + 18cda03 commit 8a69115
Show file tree
Hide file tree
Showing 65 changed files with 1,680 additions and 1,566 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: cmdstanr
Title: R Interface to 'CmdStan'
Version: 0.1.3
Date: 2020-08-21
Version: 0.2.0
Date: 2020-11-12
Authors@R:
c(person(given = "Jonah", family = "Gabry", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
8 changes: 5 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Items for next tagged release
# cmdstanr 0.2.0

### Bug fixes

Expand All @@ -20,10 +20,12 @@ in fitting methods. (#281, #294)

* Fix issue where names of generated files could clash. (#326, #328)

* Fix missing `include_paths` in `$syntax_check()`. (#335)
* Fix missing `include_paths` in `$syntax_check()`. (#335, @mike-lawrence)

### New features

* CSV reading is now faster by using `data.table::fread()`. (#318)

* `install_cmdstan()` gains argument `version` for specifying which version of
CmdStan to install. (#300, #308)

Expand All @@ -35,7 +37,7 @@ specifying custom chain IDs. (#319)

* Added support for the `sig_figs` argument in CmdStan versions 2.25 and above. (#327)

* CSV reading is now faster by using `data.table::fread()`. (#318)
* Added checks if the user has the necessary permissions in the RTools and temporary folders. (#343)

# cmdstanr 0.1.3

Expand Down
10 changes: 9 additions & 1 deletion R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,16 @@ build_status_ok <- function(process_log, quiet = FALSE) {
}

install_mingw32_make <- function(quiet = FALSE) {
rtools_usr_bin <- file.path(Sys.getenv("RTOOLS40_HOME"), "usr", "bin")
if (!checkmate::test_directory(rtools_usr_bin, access = "w")) {
warning("No write permissions in the RTools folder. This might prevent installing mingw32-make.",
" Consider changing permissions or reinstalling RTools in a different folder.", call. = FALSE)
}
if (!quiet) message("Installing mingw32-make and writing RTools path to ~/.Renviron ...")
processx::run(
"pacman",
args = c("-Syu", "mingw-w64-x86_64-make","--noconfirm"),
wd = file.path(Sys.getenv("RTOOLS40_HOME"), "usr", "bin"),
wd = rtools_usr_bin,
error_on_status = TRUE
)
write('PATH="${RTOOLS40_HOME}\\usr\\bin;${RTOOLS40_HOME}\\mingw64\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)
Expand Down Expand Up @@ -595,6 +600,9 @@ check_cmdstan_toolchain <- function(fix = FALSE, quiet = FALSE) {
check_unix_make()
check_unix_cpp_compiler()
}
if (!checkmate::test_directory(dirname(tempdir()), access = "w")) {
stop("No write permissions to the temporary folder! Please change the permissions or location of the temporary folder.", call. = FALSE)
}
if (!quiet) {
message("The CmdStan toolchain is setup properly!")
}
Expand Down
13 changes: 7 additions & 6 deletions R/model.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ CmdStanModel <- R6::R6Class(
private$stan_file_ <- absolute_path(stan_file)

args <- list(...)
check_stanc_options(args$stanc_options)
private$precompile_cpp_options_ <- args$cpp_options %||% list()
private$precompile_stanc_options_ <- args$stanc_options %||% list()
private$precompile_include_paths_ <- args$include_paths
Expand Down Expand Up @@ -366,6 +367,7 @@ compile_method <- function(quiet = TRUE,
if (length(stanc_options) == 0 && !is.null(private$precompile_stanc_options_)) {
stanc_options <- private$precompile_stanc_options_
}
check_stanc_options(stanc_options)
if (is.null(include_paths) && !is.null(private$precompile_include_paths_)) {
include_paths <- private$precompile_include_paths_
}
Expand Down Expand Up @@ -465,19 +467,18 @@ compile_method <- function(quiet = TRUE,
if (is.null(stanc_options[["name"]])) {
stanc_options[["name"]] <- model_name
}
stanc_built_options = c()
stanc_built_options <- c()
for (i in seq_len(length(stanc_options))) {
option_name <- names(stanc_options)[i]
if (isTRUE(as.logical(stanc_options[[i]]))) {
stanc_built_options = c(stanc_built_options, paste0("--", option_name))
stanc_built_options <- c(stanc_built_options, paste0("--", option_name))
} else if (is.null(option_name) || !nzchar(option_name)) {
stanc_built_options <- c(stanc_built_options, paste0("--", stanc_options[[i]]))
} else {
stanc_built_options = c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
stanc_built_options <- c(stanc_built_options, paste0("--", option_name, "=", "'", stanc_options[[i]], "'"))
}
}
stancflags_val <- paste0("STANCFLAGS += ", stancflags_val, paste0(stanc_built_options, collapse = " "))
if (cmdstan_version() < "2.24") {
prepare_precompiled(cpp_options, quiet)
}
run_log <- processx::run(
command = make_cmd(),
args = c(tmp_exe,
Expand Down
76 changes: 18 additions & 58 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,64 +208,22 @@ cpp_options_to_compile_flags <- function(cpp_options) {
paste0(cpp_built_options, collapse = " ")
}

prepare_precompiled <- function(cpp_options = list(), quiet = FALSE) {
flags <- NULL
if (!is.null(cpp_options$stan_threads)) {
flags <- c(flags, "threads")
}
if (!is.null(cpp_options$stan_mpi)) {
flags <- c(flags, "mpi")
}
if (!is.null(cpp_options$stan_opencl)) {
flags <- c(flags, "opencl")
}
if (is.null(flags)) {
flags <- "noflags"
} else {
flags <- paste0(flags, collapse = "_")
}
main_path_w_flags <- file.path(cmdstan_path(), "src", "cmdstan", paste0("main_", flags, ".o"))
main_path_o <- file.path(cmdstan_path(), "src", "cmdstan", "main.o")
model_header_path_w_flags <- file.path(cmdstan_path(), "stan", "src", "stan", "model", paste0("model_header_", flags, ".hpp.gch"))
model_header_path_gch <- file.path(cmdstan_path(), "stan", "src", "stan", "model", "model_header.hpp.gch")
if (file.exists(model_header_path_gch)) {
model_header_gch_used <- TRUE
} else {
model_header_gch_used <- FALSE
}
if (!file.exists(main_path_w_flags)) {
message(
"Compiling the main object file and precompiled headers (may take up to a few minutes). ",
"This is only necessary the first time a model is compiled after installation or when ",
"threading, MPI or OpenCL are used for the first time."
)
clean_compile_helper_files()
run_log <- processx::run(
command = make_cmd(),
args = c(cpp_options_to_compile_flags(cpp_options),
main_path_o),
wd = cmdstan_path(),
echo_cmd = !quiet,
echo = !quiet,
spinner = quiet,
stderr_line_callback = function(x,p) { if (!quiet) message(x) },
error_on_status = TRUE
)
file.copy(main_path_o, main_path_w_flags)
if (model_header_gch_used) {
run_log <- processx::run(
command = make_cmd(),
args = c(cpp_options_to_compile_flags(cpp_options),
file.path("stan", "src", "stan", "model", "model_header.hpp.gch")),
wd = cmdstan_path(),
echo_cmd = !quiet,
echo = !quiet,
spinner = quiet,
stderr_line_callback = function(x,p) { if (!quiet) message(x) },
error_on_status = TRUE
)
file.copy(model_header_path_gch, model_header_path_w_flags)
check_stanc_options <- function(stanc_options) {
i <- 1
names <- names(stanc_options)
for (s in stanc_options){
if (!is.null(names[i]) && nzchar(names[i])) {
name <- names[i]
} else {
name <- s
}
if (startsWith(name, "--")) {
stop("No leading hyphens allowed in stanc options (", name, "). ",
"Use options without leading hyphens, like for example ",
"`stanc_options = list('allow-undefined')`",
call. = FALSE)
}
i <- i + 1
}
}

Expand All @@ -288,7 +246,8 @@ num_threads <- function() {
#' @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().")
stop("Please use the 'threads_per_chain' argument in the $sample() method instead of set_num_threads().",
call. = FALSE)
}

check_divergences <- function(data_csv) {
Expand Down Expand Up @@ -381,3 +340,4 @@ variable_dims <- function(variable_names = NULL) {
}
dims
}

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOpt
or you can install the latest development version from GitHub:

```r
# install.packages("devtools")
devtools::install_github("stan-dev/cmdstanr")
# install.packages("remotes")
remotes::install_github("stan-dev/cmdstanr")
```

### Contributing
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8a69115

Please sign in to comment.