diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index fc958f85..c222df86 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -81,7 +81,9 @@ jobs: run: remotes::install_local(dependencies = TRUE, force = TRUE) - name: Install greta deps - run: greta::install_greta_deps(timeout = 50) + run: | + library(greta) + greta::install_greta_deps(timeout = 50) - name: Situation Report on greta install run: greta::greta_sitrep() diff --git a/DESCRIPTION b/DESCRIPTION index dfa32fa8..23be7270 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,6 +46,7 @@ Imports: reticulate (>= 1.19.0), rlang, tensorflow (>= 2.8.0), + whisker, yesno Suggests: bayesplot, @@ -130,6 +131,7 @@ Collate: 'checkers.R' 'test_if_forked_cluster.R' 'testthat-helpers.R' + 'write-logfiles.R' 'zzz.R' 'internals.R' LazyData: true diff --git a/NAMESPACE b/NAMESPACE index 8bd50e9f..ae38e342 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -181,6 +181,7 @@ export(colMeans) export(colSums) export(cov2cor) export(cpu_only) +export(destroy_greta_deps) export(diag) export(dirichlet) export(dirichlet_multinomial) @@ -196,14 +197,9 @@ export(gpu_only) export(gradient_descent) export(greta_array) export(greta_deps_receipt) -export(greta_notes_conda_create_error) -export(greta_notes_conda_create_output) -export(greta_notes_conda_install_error) -export(greta_notes_conda_install_output) -export(greta_notes_install_miniconda_error) -export(greta_notes_install_miniconda_output) export(greta_notes_tf_num_error) export(greta_python_deps) +export(greta_set_install_logfile) export(greta_sitrep) export(hmc) export(hypergeometric) @@ -268,6 +264,7 @@ export(uniform) export(variable) export(weibull) export(wishart) +export(write_greta_install_log) export(zeros) import(methods) importFrom(R6,R6Class) diff --git a/NEWS.md b/NEWS.md index 4ef25fe7..bb9040a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -41,6 +41,9 @@ This release provides a few improvements to installation in greta. It should now * Added `greta_deps_receipt()` to list the current main python packages installed. (#668) * Added checking suite to ensure you are using valid versions of TF, TFP, and Python(#666) * Added data `greta_deps_tf_tfp` (#666), which contains valid versions combinations of TF, TFP, and Python. +* remove `greta_nodes_install/conda_*()` options as #493 makes them defunct. +* Added option to write to a single logfile with `greta_set_install_logfile()`, and `write_greta_install_log()`. (#493) +* Added `destroy_greta_deps()` function to remove miniconda and python conda environment ## Minor diff --git a/R/checkers.R b/R/checkers.R index b953b760..5ce306af 100644 --- a/R/checkers.R +++ b/R/checkers.R @@ -56,15 +56,14 @@ check_tf_version <- function(alert = c("none", cli_process_failed() cli_msg <- c( - "We have detected that you do not have the expected python packages \\ - setup.", - "You can set these up by running this R code in the console:", + "x" = "The expected python packages are not available", + "i" = "We recommend installing them (in a fresh R session) with:", "{.code install_greta_deps()}", - "Then, restart R and run:", - "{.code library(greta)}", + "or", + "{.code reinstall_greta_deps()}", "({.strong Note}: Your R session should not have initialised \\ Tensorflow yet.)", - "For more information, see {.code ?install_greta_deps}" + "i" = "For more information, see {.code ?install_greta_deps}" ) # if there was a problem, append the solution @@ -74,9 +73,9 @@ check_tf_version <- function(alert = c("none", switch( alert, - error = stop(error_text, call. = FALSE), - warn = warning(warning_text, call. = FALSE), - message = message(message_text), + error = rlang::abort(error_text), + warn = rlang::warn(warning_text), + message = rlang::inform(message_text), startup = packageStartupMessage(message_text), none = NULL ) diff --git a/R/data-deps-tf-tfp.R b/R/data-deps-tf-tfp.R index 92d52f46..67cf4347 100644 --- a/R/data-deps-tf-tfp.R +++ b/R/data-deps-tf-tfp.R @@ -1,9 +1,9 @@ -#' Suggested TF, TFP, and Python dependencies +#' Suggested valid Python dependencies for greta #' #' This is a dataset that contains suggested valid versions of Tensorflow (TF), #' Tensorflow Probability (TFP), and Python for linux, mac, and windows #' machines. It was constructed from -#' , +#' and #' , and by inspecting #' . #' diff --git a/R/greta_create_conda_env.R b/R/greta_create_conda_env.R index 7e6b697b..6542ada6 100644 --- a/R/greta_create_conda_env.R +++ b/R/greta_create_conda_env.R @@ -31,9 +31,4 @@ greta_create_conda_env <- function(timeout = 5, greta_stash$conda_create_notes <- install_conda_create$output_notes greta_stash$conda_create_error <- install_conda_create$output_error - cli::cli_ul("To see full installation notes run:") - cli::cli_ul("{.code greta_notes_conda_create_output()}") - cli::cli_ul("To see any error messages, run:") - cli::cli_ul("{.code greta_notes_conda_create_error()}") - } diff --git a/R/greta_install_miniconda.R b/R/greta_install_miniconda.R index b6c6b5fc..c90a7dc1 100644 --- a/R/greta_install_miniconda.R +++ b/R/greta_install_miniconda.R @@ -25,8 +25,4 @@ greta_install_miniconda <- function(timeout = 5) { greta_stash$miniconda_notes <- install_miniconda_process$output_notes greta_stash$miniconda_error <- install_miniconda_process$output_error - cli::cli_ul("To see full installation notes run:") - cli::cli_ul("{.code greta_notes_install_miniconda_output()}") - cli::cli_ul("To see any error messages, run:") - cli::cli_ul("{.code greta_notes_install_miniconda_error()}") } diff --git a/R/greta_install_python_deps.R b/R/greta_install_python_deps.R index b214ec74..e8e9c0ba 100644 --- a/R/greta_install_python_deps.R +++ b/R/greta_install_python_deps.R @@ -49,9 +49,4 @@ greta_install_python_deps <- function(timeout = 5, greta_stash$conda_install_notes <- install_python_modules$output_notes greta_stash$conda_install_error <- install_python_modules$output_error - cli::cli_ul("To see full installation notes run:") - cli::cli_ul("{.code greta_notes_conda_install_output()}") - cli::cli_ul("To see any error messages, run:") - cli::cli_ul("{.code greta_notes_conda_install_error()}") - } diff --git a/R/greta_stash.R b/R/greta_stash.R index cb1abc7e..ac3585f3 100644 --- a/R/greta_stash.R +++ b/R/greta_stash.R @@ -1,68 +1,32 @@ greta_note_msg <- cli::format_message( c( "If you are reading this, the {.pkg greta} installation or error notes \\ - have been wiped." + have been wiped. This likely means that installation has not happened, or \\ + it has happened and you've restarted R. See `?install_greta_deps()` for \\ + more information." ) ) greta_stash$install_miniconda_notes <- greta_note_msg +greta_stash$install_miniconda_error <- greta_note_msg greta_stash$conda_create_notes <- greta_note_msg +greta_stash$conda_create_error <- greta_note_msg greta_stash$conda_install_notes <- greta_note_msg +greta_stash$conda_install_error <- greta_note_msg greta_stash$tf_num_error <- greta_note_msg -#' @title Retrieve python installation or error details. +#' @title Retrieve python messages. #' #' @description -#' These functions retrieve installation or error information output by python -#' when running `install_miniconda()`, `conda_create()`, `conda_install()`, or -#' when encountering a TensorFlow numerical problem. +#' These functions retrieve specific python error messages that might +#' come up during greta use. #' #' @rdname stash-notes #' @export #' @examples #' \dontrun{ -#' greta_notes_install_miniconda() -#' greta_notes_conda_create() -#' greta_notes_conda_install() -#' greta_notes_tf_num_error() #' greta_notes_tf_error() #' } -greta_notes_install_miniconda_output <- function() { - cat(greta_stash$miniconda_notes) -} - -#' @name stash-notes -#' @export -greta_notes_install_miniconda_error <- function(){ - cat(greta_stash$miniconda_error) -} - -#' @name stash-notes -#' @export -greta_notes_conda_create_output <- function() { - cat(greta_stash$conda_create_notes) -} - -#' @name stash-notes -#' @export -greta_notes_conda_create_error <- function() { - cat(greta_stash$conda_create_error) -} - -#' @name stash-notes -#' @export -greta_notes_conda_install_output <- function() { - cat(greta_stash$conda_install_notes) -} - -#' @name stash-notes -#' @export -greta_notes_conda_install_error <- function() { - cat(greta_stash$conda_install_error) -} - -#' @name stash-notes -#' @export greta_notes_tf_num_error <- function() { cat(greta_stash$tf_num_error) } diff --git a/R/install_greta_deps.R b/R/install_greta_deps.R index 544f6fab..fa4e1c5a 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -1,14 +1,25 @@ #' Install Python dependencies for greta #' -#' This is a helper function to install Python dependencies needed. This -#' includes the latest version of Tensorflow version (2.13.0 or higher), -#' Tensorflow Probability 0.21.0 (or higher), and the latest version of -#' numpy (1.21.0 or higher). These Python modules will be installed into a -#' virtual or conda environment, named "greta-env-tf2". Note that "virtualenv" -#' is not available on Windows. +#' This is a helper function to install Python dependencies needed. By default +#' these are TF 2.15.0, TFP 0.23.0, and Python 3.10. These Python modules +#' will be installed into a conda environment named "greta-env-tf2". #' -#' @param python_deps object created with `greta_python_deps()` where you -#' specify python, TF, and TFP versions. +#' To see install notes or errors, there isn't an argument to specify, +#' instead you will need to specify and environment variable, +#' `GRETA_INSTALLATION_LOG`, with +#' `Sys.setenv('GRETA_INSTALLATION_LOG'='path/to/logfile.html')`. Or use +#' [greta_set_install_logfile()] to set the path, e.g., +#' `greta_set_install_logfile('path/to/logfile.html')`. You can also skip +#' the restarting of R and use [write_greta_install_log()], which +#' installation notes will indicate how to use if you haven't specified. +#' +#' @param python_deps object created with [greta_python_deps()] where you +#' specify python, TF, and TFP versions. By default these are TF 2.15.0, +#' TFP 0.23.0, and Python 3.10. These versions must be compatible +#' with each other. If they are not, [greta_python_deps()] will error with +#' more information and suggestions. See ?[greta_python_deps()] for more +#' information, and see the data object `greta_deps_tf_tfp` +#' (`?greta_deps_tf_tfp``). #' #' @param timeout maximum time in minutes until the installation for each #' installation component times out and exits. Default is 5 minutes per @@ -84,12 +95,46 @@ install_greta_deps <- function(python_deps = greta_python_deps(), ) } + # TODO + # Issue warning if you already have conda env +/ miniconda + # suggest using `reinstall_greta_deps()` greta_install_python_deps( timeout = timeout, python_deps = python_deps ) - cli_alert_success("Installation of {.pkg greta} dependencies is complete!") + # TODO + # Detect if you have tried to install greta multiple times in the same + # session, and suggest that perhaps they want to use + # `reinstall_greta_deps()` + # perhaps even stopping the session with a "yesno" + + greta_logfile <- Sys.getenv("GRETA_INSTALLATION_LOG") + + logfile_exists <- nzchar(greta_logfile) + + no_logfile <- !logfile_exists + + + if (logfile_exists) { + write_greta_install_log(path = greta_logfile) + } + + if (no_logfile) { + cli::cli_alert_warning( + text = c( + "No logfile specified. If you want to save the logfile to see any \\ + install notes, or potential errors, you will need to \\ + {.strong not restart R}, then run:\n\n", + "{.run write_greta_install_log('greta-logfile.html')}" + ), + wrap = TRUE + ) + } + + cli::cli_alert_success("Installation of {.pkg greta} dependencies \\ + is complete!", + wrap = TRUE) restart_or_not(restart) @@ -160,7 +205,7 @@ restart_or_not <- function(restart){ #' #' @param tf_version Character. Tensorflow (TF) version in format major.minor.patch. Default is "2.15.0". #' @param tfp_version Character.Tensorflow probability (TFP) version major.minor.patch. Default is "0.23.0". -#' @param python_version Character. Ptyhon version in format major.minor.patch. Default is "3.10". +#' @param python_version Character. Python version in format major.minor.patch. Default is "3.10". #' #' @return list of dependencies #' @export @@ -182,10 +227,10 @@ greta_python_deps <- function(tf_version = "2.15.0", class = c("greta_python_deps", "data.frame") ) + # check for envvar to silence these checks check_tfp_tf_semantic(deps_obj) check_greta_tf_range(deps_obj) check_greta_tfp_range(deps_obj) - check_greta_python_range(deps_obj$python_version) check_greta_deps_config(deps_obj) @@ -259,7 +304,8 @@ check_greta_deps_range <- function(python_deps, {version_name} > {.val {latest_version}}", "i" = "See {.url {gh_issue}} for more information", "x" = "The provided version was {.val {version_provided}}", - "i" = "The closest value is: {.val {latest_version}}", + "i" = "The nearest valid version that is supported by \\ + {.pkg greta} is: {.val {latest_version}}", "i" = "Valid versions of TF, TFP, and Python are in \\ {.code greta_deps_tf_tfp}", "i" = "Inspect with:", @@ -280,7 +326,8 @@ check_greta_deps_range <- function(python_deps, supported versions", "The version {.val {version_provided}} was not in \\ {.val {greta_deps_tf_tfp[[deps]]}}", - "The closest value is: {.val {closest_value}}", + "i" = "The nearest valid version that is supported by \\ + {.pkg greta} is: {.val {closest_value}}", "i" = "Valid versions of TF, TFP, and Python are in \\ {.code greta_deps_tf_tfp}", "i" = "Inspect with:", @@ -332,7 +379,6 @@ check_greta_python_range <- function(version_provided, check_greta_deps_config <- function(python_deps, call = rlang::caller_env()){ - # check for envvar to silence these checks check_greta_python_deps(python_deps) python_deps <- python_deps |> @@ -415,9 +461,9 @@ check_greta_deps_config <- function(python_deps, "suggest_py" = py_matches ) - suggested_tfp <- as.character(suggested_match$tfp_version) - suggested_tf <- as.character(suggested_match$tf_version) - suggested_py <- as.character(suggested_match$python_version_max) + suggested_tfp <- as.character(max(suggested_match$tfp_version)) + suggested_tf <- as.character(max(suggested_match$tf_version)) + suggested_py <- as.character(max(suggested_match$python_version_max)) cli::cli_abort( message = c("Provided {.code greta_python_deps} does not match valid \\ diff --git a/R/package.R b/R/package.R index a12fea94..e945bbb8 100644 --- a/R/package.R +++ b/R/package.R @@ -37,5 +37,14 @@ # clear CRAN checks spotting floating global variables #' @importFrom utils globalVariables -utils::globalVariables(c("N"), "greta") - +utils::globalVariables( + c("N", + "greta_deps_tf_tfp", + "greta_logfile", + "os", + "python_version_max", + "python_version_min", + "tf_version", + "tfp_version", + "greta") +) diff --git a/R/reinstallers.R b/R/reinstallers.R index f7d13af9..100395f0 100644 --- a/R/reinstallers.R +++ b/R/reinstallers.R @@ -20,11 +20,13 @@ #' reinstall_miniconda() #' } remove_greta_env <- function(){ - cli::cli_alert_info("removing 'greta-env-tf2' conda environment") + cli::cli_alert_info("removing 'greta-env-tf2' conda environment", + wrap = TRUE) reticulate::conda_remove( envname = "greta-env-tf2" ) - cli::cli_alert_success("greta-env-tf2 environment removed!") + cli::cli_alert_success("greta-env-tf2 environment removed!", + wrap = TRUE) } #' @export @@ -40,14 +42,17 @@ reinstall_greta_env <- function(timeout = 5){ remove_miniconda <- function(){ path_to_miniconda <- reticulate::miniconda_path() if (!file.exists(path_to_miniconda)){ - cli::cli_alert_info("No miniconda files found at {path_to_miniconda}") + cli::cli_alert_info("No miniconda files found at {path_to_miniconda}", + wrap = TRUE) return(invisible()) } if (yesno::yesno("Are you sure you want to delete miniconda from ", path_to_miniconda,"?") ){ - cli::cli_alert_info("removing 'miniconda' installation") + cli::cli_alert_info("removing 'miniconda' installation", + wrap = TRUE) unlink(path_to_miniconda, recursive = TRUE) - cli::cli_alert_success("'miniconda' successfully removed!") + cli::cli_alert_success("'miniconda' successfully removed!", + wrap = TRUE) } else { return(invisible()) } @@ -81,3 +86,21 @@ reinstall_greta_deps <- function(python_deps = greta_python_deps(), restart = restart ) } + +#' Remove greta dependencies and remove miniconda +#' +#' Sometimes when installing greta you might encounter an error and the best +#' thing to do is start from a clean slate. This function does two things: +#' 1. Removes the "greta-tf2-env" with [remove_greta_env()] +#' 2. Removes the miniconda installation with [remove_miniconda()] +#' +#' @return nothing +#' @export +destroy_greta_deps <- function(){ + cli::cli_progress_step( + msg = "You are removing greta env and miniconda", + msg_done = c("You have successfully removed greta env and miniconda") + ) + remove_greta_env() + remove_miniconda() +} diff --git a/R/utils.R b/R/utils.R index f47cc101..0eaee9da 100644 --- a/R/utils.R +++ b/R/utils.R @@ -949,7 +949,8 @@ greta_sitrep <- function(){ if (all(software_version$match)){ check_tf_version("none") - cli::cli_alert_info("{.pkg greta} is ready to use!") + cli::cli_alert_info("{.pkg greta} is ready to use!", + wrap = TRUE) } else { check_tf_version("warn") } @@ -1252,3 +1253,4 @@ outside_version_range <- function(provided, range) { outside_range <- above_range || below_range outside_range } + diff --git a/R/write-logfiles.R b/R/write-logfiles.R new file mode 100644 index 00000000..1ffc5a65 --- /dev/null +++ b/R/write-logfiles.R @@ -0,0 +1,100 @@ +#' Set logfile path when installing greta +#' +#' To help debug greta installation, you can save all installation output +#' to a single logfile. +#' +#' @param path valid path to logfile - should end with `.html` so you +#' can benefit from the html rendering. +#' +#' @return nothing - sets an environment variable for use with +#' [install_greta_deps()]. +#' @export +greta_set_install_logfile <- function(path){ + Sys.setenv("GRETA_INSTALLATION_LOG"=path) +} + +#' Write greta dependency installation log file +#' +#' This can only be run after installation has happened with +#' [install_greta_deps()], and before restarting R. +#' +#' @param path a path with an HTML (.html) extension. +#' +#' @return nothing - writes to file +#' @export +write_greta_install_log <- function(path = greta_logfile) { + + cli::cli_progress_step( + msg = "Writing logfile to {.path {path}}", + msg_done = "Logfile written to {.path {path}}" + ) + + template <- ' +

Greta installation logfile

+

Created: {{sys_date}}

+

Use this logfile to explore potential issues in installation with greta

+

Try searching the text for "error" with Cmd/Ctrl+F

+ +

Miniconda

+ +
+ + Miniconda Installation Notes + + {{miniconda_notes}} +
+ +
+ + Miniconda Installation Errors + + {{miniconda_error}} +
+ +

Conda Environment

+ +
+ + Conda Environment Notes + + {{conda_create_notes}} +
+ +
+ + Conda Environment Errors + + {{conda_create_error}} +
+ +

Python Module Installation

+ +
+ + Python Module Installation Notes + + {{conda_install_notes}} +
+ +
+ + Python Module Installation Errors + + {{conda_install_error}} +
+ ' + + greta_install_data <- list( + sys_date = Sys.time(), + miniconda_notes = greta_stash$miniconda_notes, + miniconda_error = greta_stash$miniconda_error, + conda_create_notes = greta_stash$conda_create_notes, + conda_create_error = greta_stash$conda_create_error, + conda_install_notes = greta_stash$conda_install_notes, + conda_install_error = greta_stash$conda_install_error + ) + + writeLines(whisker::whisker.render(template, greta_install_data), + path) + +} diff --git a/inst/WORDLIST b/inst/WORDLIST index 270f6c64..09d959a5 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -4,7 +4,6 @@ AdagradDAOptimiser CMD CRAN's Codecov -Conda DAGs DiagrammeR GPUs @@ -37,6 +36,7 @@ RStudio RStudio's Scalable TF +TFP Tensorflow Vectorised WinBUGS @@ -55,6 +55,7 @@ colour colours conda cran +deps devtools dlkjcorr doi @@ -78,6 +79,8 @@ initialising joss labelled libxml +linux +logfile maximise mcmc md @@ -88,7 +91,6 @@ modelling multisession nd normalised -numpy optimisation optimisations optimiser @@ -122,12 +124,12 @@ specialised summarise tensorflow tf +tfp tuh unadjusted uncentered uncoached vectorising -virtualenv visualise warmup winbuilder diff --git a/man/destroy_greta_deps.Rd b/man/destroy_greta_deps.Rd new file mode 100644 index 00000000..e7acdbe1 --- /dev/null +++ b/man/destroy_greta_deps.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/reinstallers.R +\name{destroy_greta_deps} +\alias{destroy_greta_deps} +\title{Remove greta dependencies and remove miniconda} +\usage{ +destroy_greta_deps() +} +\value{ +nothing +} +\description{ +Sometimes when installing greta you might encounter an error and the best +thing to do is start from a clean slate. This function does two things: +\enumerate{ +\item Removes the "greta-tf2-env" with \code{\link[=remove_greta_env]{remove_greta_env()}} +\item Removes the miniconda installation with \code{\link[=remove_miniconda]{remove_miniconda()}} +} +} diff --git a/man/greta_deps_tf_tfp.Rd b/man/greta_deps_tf_tfp.Rd index fbcc0bd1..1d93feb5 100644 --- a/man/greta_deps_tf_tfp.Rd +++ b/man/greta_deps_tf_tfp.Rd @@ -3,11 +3,11 @@ \docType{data} \name{greta_deps_tf_tfp} \alias{greta_deps_tf_tfp} -\title{Suggested TF, TFP, and Python dependencies} +\title{Suggested valid Python dependencies for greta} \format{ \subsection{\code{greta_deps_tf_tfp}}{ -A data frame with 71 rows and 5 columns: +A data frame with 63 rows and 5 columns: \describe{ \item{os}{Operating System} \item{tfp_version, tf_version}{numeric versions in format major.minor.patch for TFP and TF} @@ -22,8 +22,11 @@ greta_deps_tf_tfp This is a dataset that contains suggested valid versions of Tensorflow (TF), Tensorflow Probability (TFP), and Python for linux, mac, and windows machines. It was constructed from -\url{https://www.tensorflow.org/install/source}, +\url{https://www.tensorflow.org/install/source} and \url{https://www.tensorflow.org/install/source_windows}, and by inspecting \url{https://github.com/tensorflow/probability/releases}. } +\details{ +We recommend using the default versions provided in \code{greta_python_deps()}. +} \keyword{datasets} diff --git a/man/greta_python_deps.Rd b/man/greta_python_deps.Rd index e3a8d3ef..b914008e 100644 --- a/man/greta_python_deps.Rd +++ b/man/greta_python_deps.Rd @@ -15,7 +15,7 @@ greta_python_deps( \item{tfp_version}{Character.Tensorflow probability (TFP) version major.minor.patch. Default is "0.23.0".} -\item{python_version}{Character. Ptyhon version in format major.minor.patch. Default is "3.10".} +\item{python_version}{Character. Python version in format major.minor.patch. Default is "3.10".} } \value{ list of dependencies diff --git a/man/greta_set_install_logfile.Rd b/man/greta_set_install_logfile.Rd new file mode 100644 index 00000000..2d33b31e --- /dev/null +++ b/man/greta_set_install_logfile.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/write-logfiles.R +\name{greta_set_install_logfile} +\alias{greta_set_install_logfile} +\title{Set logfile path when installing greta} +\usage{ +greta_set_install_logfile(path) +} +\arguments{ +\item{path}{valid path to logfile - should end with \code{.html} so you +can benefit from the html rendering.} +} +\value{ +nothing - sets an environment variable for use with +\code{\link[=install_greta_deps]{install_greta_deps()}}. +} +\description{ +To help debug greta installation, you can save all installation output +to a single logfile. +} diff --git a/man/install_greta_deps.Rd b/man/install_greta_deps.Rd index bd21db6c..0dc3af71 100644 --- a/man/install_greta_deps.Rd +++ b/man/install_greta_deps.Rd @@ -19,8 +19,13 @@ reinstall_greta_deps( ) } \arguments{ -\item{python_deps}{object created with \code{greta_python_deps()} where you -specify python, TF, and TFP versions.} +\item{python_deps}{object created with \code{\link[=greta_python_deps]{greta_python_deps()}} where you +specify python, TF, and TFP versions. By default these are TF 2.15.0, +TFP 0.23.0, and Python 3.10. These versions must be compatible +with each other. If they are not, \code{\link[=greta_python_deps]{greta_python_deps()}} will error with +more information and suggestions. See ?\code{\link[=greta_python_deps]{greta_python_deps()}} for more +information, and see the data object \code{greta_deps_tf_tfp} +(`?greta_deps_tf_tfp``).} \item{timeout}{maximum time in minutes until the installation for each installation component times out and exits. Default is 5 minutes per @@ -34,14 +39,20 @@ only restarts R during interactive sessions, and only in RStudio.} \item{...}{Optional arguments, reserved for future expansion.} } \description{ -This is a helper function to install Python dependencies needed. This -includes the latest version of Tensorflow version (2.13.0 or higher), -Tensorflow Probability 0.21.0 (or higher), and the latest version of -numpy (1.21.0 or higher). These Python modules will be installed into a -virtual or conda environment, named "greta-env-tf2". Note that "virtualenv" -is not available on Windows. +This is a helper function to install Python dependencies needed. By default +these are TF 2.15.0, TFP 0.23.0, and Python 3.10. These Python modules +will be installed into a conda environment named "greta-env-tf2". } \details{ +To see install notes or errors, there isn't an argument to specify, +instead you will need to specify and environment variable, +\code{GRETA_INSTALLATION_LOG}, with +\code{Sys.setenv('GRETA_INSTALLATION_LOG'='path/to/logfile.html')}. Or use +\code{\link[=greta_set_install_logfile]{greta_set_install_logfile()}} to set the path, e.g., +\code{greta_set_install_logfile('path/to/logfile.html')}. You can also skip +the restarting of R and use \code{\link[=write_greta_install_log]{write_greta_install_log()}}, which +installation notes will indicate how to use if you haven't specified. + By default, if using RStudio, it will now ask you if you want to restart the R session. If the session is not interactive, or is not in RStudio, it will not restart. You can also override this with \code{restart = TRUE}. diff --git a/man/stash-notes.Rd b/man/stash-notes.Rd index 748edd10..ad607536 100644 --- a/man/stash-notes.Rd +++ b/man/stash-notes.Rd @@ -1,41 +1,17 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/greta_stash.R -\name{greta_notes_install_miniconda_output} -\alias{greta_notes_install_miniconda_output} -\alias{stash-notes} -\alias{greta_notes_install_miniconda_error} -\alias{greta_notes_conda_create_output} -\alias{greta_notes_conda_create_error} -\alias{greta_notes_conda_install_output} -\alias{greta_notes_conda_install_error} +\name{greta_notes_tf_num_error} \alias{greta_notes_tf_num_error} -\title{Retrieve python installation or error details.} +\title{Retrieve python messages.} \usage{ -greta_notes_install_miniconda_output() - -greta_notes_install_miniconda_error() - -greta_notes_conda_create_output() - -greta_notes_conda_create_error() - -greta_notes_conda_install_output() - -greta_notes_conda_install_error() - greta_notes_tf_num_error() } \description{ -These functions retrieve installation or error information output by python -when running \code{install_miniconda()}, \code{conda_create()}, \code{conda_install()}, or -when encountering a TensorFlow numerical problem. +These functions retrieve specific python error messages that might +come up during greta use. } \examples{ \dontrun{ -greta_notes_install_miniconda() -greta_notes_conda_create() -greta_notes_conda_install() -greta_notes_tf_num_error() greta_notes_tf_error() } } diff --git a/man/write_greta_install_log.Rd b/man/write_greta_install_log.Rd new file mode 100644 index 00000000..da711602 --- /dev/null +++ b/man/write_greta_install_log.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/write-logfiles.R +\name{write_greta_install_log} +\alias{write_greta_install_log} +\title{Write greta dependency installation log file} +\usage{ +write_greta_install_log(path = greta_logfile) +} +\arguments{ +\item{path}{a path with an HTML (.html) extension.} +} +\value{ +nothing - writes to file +} +\description{ +This can only be run after installation has happened with +\code{\link[=install_greta_deps]{install_greta_deps()}}, and before restarting R. +} diff --git a/tests/testthat/_snaps/greta_python_deps.md b/tests/testthat/_snaps/greta_python_deps.md index abe40306..0550c6b3 100644 --- a/tests/testthat/_snaps/greta_python_deps.md +++ b/tests/testthat/_snaps/greta_python_deps.md @@ -93,11 +93,11 @@ --- Code - greta_python_deps(tf_version = "2.13.0", tfp_version = "0.21.0", + greta_python_deps(tf_version = "2.12.0", tfp_version = "0.20.0", python_version = "3.9") Output tf_version tfp_version python_version - 1 2.13.0 0.21.0 3.9 + 1 2.12.0 0.20.0 3.9 --- @@ -109,7 +109,7 @@ ! greta Does not yet support TF > 2.15.0 i See for more information x The provided version was 2.16.1 - i The closest value is: 2.15.0 + i The nearest valid version that is supported by greta is: 2.15.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` @@ -122,7 +122,7 @@ Error in `greta_python_deps()`: ! "TF" version provided does not match supported versions The version 1.9.0 was not in 2.15.0, 2.14.0, 2.14.0, 2.13.0, 2.12.0, 2.11.0, 2.10.0, 2.9.1, 2.8.0, 2.7.0, 2.6.0, 2.6.0, 2.5.0, 2.4.0, 2.4.0, 2.4.0, 2.3.0, 2.3.0, ..., 2.1.0, and 2.0.0 - The closest value is: 2.0.0 + i The nearest valid version that is supported by greta is: 2.0.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` @@ -137,7 +137,7 @@ ! greta Does not yet support TFP > 0.23.0 i See for more information x The provided version was 0.24.0 - i The closest value is: 0.23.0 + i The nearest valid version that is supported by greta is: 0.23.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` @@ -150,7 +150,7 @@ Error in `greta_python_deps()`: ! "TFP" version provided does not match supported versions The version 0.6.0 was not in 0.23.0, 0.22.1, 0.22.0, 0.21.0, 0.20.0, 0.19.0, 0.18.0, 0.17.0, 0.16.0, 0.15.0, 0.14.1, 0.14.0, 0.13.0, 0.12.2, 0.12.1, 0.12.0, 0.11.1, 0.11.0, ..., 0.9.0, and 0.8.0 - The closest value is: 0.8.0 + i The nearest valid version that is supported by greta is: 0.8.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` @@ -255,7 +255,7 @@ ! greta Does not yet support TF > 2.15.0 i See for more information x The provided version was 2.17.0 - i The closest value is: 2.15.0 + i The nearest valid version that is supported by greta is: 2.15.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` @@ -268,7 +268,7 @@ Error in `greta_python_deps()`: ! "TF" version provided does not match supported versions The version 2.9.0 was not in 2.15.0, 2.14.0, 2.14.0, 2.13.0, 2.12.0, 2.11.0, 2.10.0, 2.9.1, 2.8.0, 2.7.0, 2.6.0, 2.6.0, 2.5.0, 2.4.0, 2.4.0, 2.4.0, 2.3.0, 2.3.0, ..., 2.1.0, and 2.0.0 - The closest value is: 2.8.0 + i The nearest valid version that is supported by greta is: 2.8.0 i Valid versions of TF, TFP, and Python are in `greta_deps_tf_tfp` i Inspect with: `View(greta_deps_tf_tfp)` diff --git a/tests/testthat/_snaps/misc.md b/tests/testthat/_snaps/misc.md index 4b6b3d52..ae8b8783 100644 --- a/tests/testthat/_snaps/misc.md +++ b/tests/testthat/_snaps/misc.md @@ -1,35 +1,35 @@ # check_tf_version works - We have detected that you do not have the expected python packages setup. - You can set these up by running this R code in the console: + x The expected python packages are not available + i We recommend installing them (in a fresh R session) with: `install_greta_deps()` - Then, restart R and run: - `library(greta)` + or + `reinstall_greta_deps()` (Note: Your R session should not have initialised Tensorflow yet.) - For more information, see `?install_greta_deps` + i For more information, see `?install_greta_deps` --- - We have detected that you do not have the expected python packages setup. - You can set these up by running this R code in the console: + x The expected python packages are not available + i We recommend installing them (in a fresh R session) with: `install_greta_deps()` - Then, restart R and run: - `library(greta)` + or + `reinstall_greta_deps()` (Note: Your R session should not have initialised Tensorflow yet.) - For more information, see `?install_greta_deps` + i For more information, see `?install_greta_deps` --- Code check_tf_version("message") Message - We have detected that you do not have the expected python packages setup. - You can set these up by running this R code in the console: + x The expected python packages are not available + i We recommend installing them (in a fresh R session) with: `install_greta_deps()` - Then, restart R and run: - `library(greta)` + or + `reinstall_greta_deps()` (Note: Your R session should not have initialised Tensorflow yet.) - For more information, see `?install_greta_deps` + i For more information, see `?install_greta_deps` # define and mcmc error informatively diff --git a/tests/testthat/test-greta_python_deps.R b/tests/testthat/test-greta_python_deps.R index 85b6a2d6..d7968bc4 100644 --- a/tests/testthat/test-greta_python_deps.R +++ b/tests/testthat/test-greta_python_deps.R @@ -1,4 +1,5 @@ test_that("greta python range detection works correctly",{ + skip_if_not(check_tf_version()) # correct ranges expect_snapshot(check_greta_python_range("3.11")) expect_snapshot(check_greta_python_range("3.9")) @@ -30,6 +31,9 @@ test_that("greta python range detection works correctly",{ test_that("greta_python_deps fails appropriately", { + skip_if_not(check_tf_version()) + # skip on windows as there are small differences in version recommendations + skip_on_os(os = "windows") # default expect_snapshot(greta_python_deps()) # some correct ranges @@ -39,8 +43,8 @@ test_that("greta_python_deps fails appropriately", { python_version = "3.9") ) expect_snapshot( - greta_python_deps(tf_version = "2.13.0", - tfp_version = "0.21.0", + greta_python_deps(tf_version = "2.12.0", + tfp_version = "0.20.0", python_version = "3.9") ) # TF above range diff --git a/tests/testthat/test-print_calculate.R b/tests/testthat/test-print_calculate.R index 0a35673b..ab9dc90d 100644 --- a/tests/testthat/test-print_calculate.R +++ b/tests/testthat/test-print_calculate.R @@ -1,5 +1,7 @@ test_that("calculate print method is different for different inputs", { # ensure print method is the new MCMC one + skip_on_cran() + skip_on_os(os = "mac") x <- normal(0,1) m <- model(x) diff --git a/tests/testthat/test_distributions.R b/tests/testthat/test_distributions.R index 9abd1dd5..b1a39ecb 100644 --- a/tests/testthat/test_distributions.R +++ b/tests/testthat/test_distributions.R @@ -697,7 +697,7 @@ test_that("distributions can be sampled from by MCMC", { test_that("uniform distribution errors informatively", { skip_if_not(check_tf_version()) - skip_on_ci() + # skip_on_ci() # bad types expect_snapshot_error( @@ -724,7 +724,7 @@ test_that("uniform distribution errors informatively", { }) test_that("poisson() and binomial() error informatively in glm", { - skip_on_ci() + # skip_on_ci() skip_if_not(check_tf_version()) # if passed as an object diff --git a/tests/testthat/test_future.R b/tests/testthat/test_future.R index a993e6c3..a7203478 100644 --- a/tests/testthat/test_future.R +++ b/tests/testthat/test_future.R @@ -76,7 +76,7 @@ test_that("parallel reporting works", { test_that("mcmc errors for invalid parallel plans", { skip_if_not(check_tf_version()) - skip_on_ci() + skip_on_os(os = "windows") m <- model(normal(0, 1))