From 2b92c62a9c07c433967b3b1496896eb8b38b0dec Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 15:34:02 +1000 Subject: [PATCH 01/16] * 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 --- DESCRIPTION | 1 + NAMESPACE | 8 +-- NEWS.md | 3 + R/greta_create_conda_env.R | 5 -- R/greta_install_miniconda.R | 4 -- R/greta_install_python_deps.R | 5 -- R/greta_stash.R | 47 +--------------- R/install_greta_deps.R | 51 ++++++++++++++++- R/reinstallers.R | 29 ++++++++-- R/utils.R | 95 +++++++++++++++++++++++++++++++- man/destroy_greta_deps.Rd | 19 +++++++ man/greta_deps_tf_tfp.Rd | 5 +- man/greta_set_install_logfile.Rd | 20 +++++++ man/stash-notes.Rd | 32 ++--------- 14 files changed, 222 insertions(+), 102 deletions(-) create mode 100644 man/destroy_greta_deps.Rd create mode 100644 man/greta_set_install_logfile.Rd diff --git a/DESCRIPTION b/DESCRIPTION index dfa32fa8..44e73a1c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -46,6 +46,7 @@ Imports: reticulate (>= 1.19.0), rlang, tensorflow (>= 2.8.0), + whisker, yesno Suggests: bayesplot, diff --git a/NAMESPACE b/NAMESPACE index 8bd50e9f..85a8191c 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) 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/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..1a81765f 100644 --- a/R/greta_stash.R +++ b/R/greta_stash.R @@ -10,59 +10,18 @@ greta_stash$conda_create_notes <- greta_note_msg greta_stash$conda_install_notes <- 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..7c6b1389 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -25,6 +25,8 @@ #' the R session. If the session is not interactive, or is not in RStudio, #' it will not restart. You can also override this with `restart = TRUE`. #' +#' TODO If you would like to write a logfile of installation ... +#' #' @note This will automatically install Miniconda (a minimal version of the #' Anaconda scientific software management system), create a 'conda' #' environment for greta named 'greta-env-tf2' with required python and python @@ -84,12 +86,53 @@ 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_info( + text = c( + "To see install notes or errors, specify the environment variable \\ + {.envvar GRETA_INSTALLATION_LOG}, with:\n", + "{.code Sys.setenv('GRETA_INSTALLATION_LOG'='path/to/logfile.html')}\n", + "Or set using {.fun greta_set_install_logfile}, e.g.,:\n", + "{.code greta_set_install_logfile('path/to/logfile.html')}"), + wrap = TRUE + ) + cli::cli_alert_warning( + text = c( + "If you want to retrieve the logfile, you will need to \\ + {.strong not restart R} and instead run:", + "" + ) + ) + } + + cli::cli_alert_success("Installation of {.pkg greta} dependencies \\ + is complete!", + wrap = TRUE) restart_or_not(restart) @@ -259,7 +302,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 +324,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 {latest_version}}", "i" = "Valid versions of TF, TFP, and Python are in \\ {.code greta_deps_tf_tfp}", "i" = "Inspect with:", diff --git a/R/reinstallers.R b/R/reinstallers.R index f7d13af9..366a28b3 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,17 @@ 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(){ + remove_greta_env() + remove_miniconda() +} diff --git a/R/utils.R b/R/utils.R index f47cc101..026ce68b 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,95 @@ outside_version_range <- function(provided, range) { outside_range <- above_range || below_range outside_range } + +#' 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 +#' `greta_install_deps()`. +#' @export +greta_set_install_logfile <- function(path){ + Sys.setenv("GRETA_INSTALLATION_LOG"=path) +} + +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/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..2ece933e 100644 --- a/man/greta_deps_tf_tfp.Rd +++ b/man/greta_deps_tf_tfp.Rd @@ -7,7 +7,7 @@ \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} @@ -26,4 +26,7 @@ machines. It was constructed from \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_set_install_logfile.Rd b/man/greta_set_install_logfile.Rd new file mode 100644 index 00000000..e8efd596 --- /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/utils.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{greta_install_deps()}. +} +\description{ +To help debug greta installation, you can save all installation output +to a single logfile. +} 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() } } From c602235f16a1774973338949c0a1be0fb2992cb7 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 15:59:06 +1000 Subject: [PATCH 02/16] update snapshots --- R/install_greta_deps.R | 2 +- tests/testthat/_snaps/greta_python_deps.md | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/R/install_greta_deps.R b/R/install_greta_deps.R index 7c6b1389..bedb839d 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -325,7 +325,7 @@ check_greta_deps_range <- function(python_deps, "The version {.val {version_provided}} was not in \\ {.val {greta_deps_tf_tfp[[deps]]}}", "i" = "The nearest valid version that is supported by \\ - {.pkg greta} is: {.val {latest_version}}", + {.pkg greta} is: {.val {closest_value}}", "i" = "Valid versions of TF, TFP, and Python are in \\ {.code greta_deps_tf_tfp}", "i" = "Inspect with:", diff --git a/tests/testthat/_snaps/greta_python_deps.md b/tests/testthat/_snaps/greta_python_deps.md index abe40306..6b078a01 100644 --- a/tests/testthat/_snaps/greta_python_deps.md +++ b/tests/testthat/_snaps/greta_python_deps.md @@ -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)` From 31d5f14d433a205a239a0e731ef2a225fae6d58d Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 17:40:41 +1000 Subject: [PATCH 03/16] update documentation on installation logs --- DESCRIPTION | 1 + NAMESPACE | 1 + R/greta_stash.R | 7 ++- R/install_greta_deps.R | 48 ++++++++------- R/reinstallers.R | 4 ++ R/utils.R | 91 ---------------------------- R/write-logfiles.R | 100 +++++++++++++++++++++++++++++++ man/greta_set_install_logfile.Rd | 2 +- man/install_greta_deps.Rd | 27 ++++++--- man/write_greta_install_log.Rd | 18 ++++++ 10 files changed, 175 insertions(+), 124 deletions(-) create mode 100644 R/write-logfiles.R create mode 100644 man/write_greta_install_log.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 44e73a1c..23be7270 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -131,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 85a8191c..ae38e342 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -264,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/R/greta_stash.R b/R/greta_stash.R index 1a81765f..ac3585f3 100644 --- a/R/greta_stash.R +++ b/R/greta_stash.R @@ -1,13 +1,18 @@ 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 messages. diff --git a/R/install_greta_deps.R b/R/install_greta_deps.R index bedb839d..aa9a5870 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 @@ -25,8 +36,6 @@ #' the R session. If the session is not interactive, or is not in RStudio, #' it will not restart. You can also override this with `restart = TRUE`. #' -#' TODO If you would like to write a logfile of installation ... -#' #' @note This will automatically install Miniconda (a minimal version of the #' Anaconda scientific software management system), create a 'conda' #' environment for greta named 'greta-env-tf2' with required python and python @@ -112,21 +121,14 @@ install_greta_deps <- function(python_deps = greta_python_deps(), } if (no_logfile) { - cli::cli_alert_info( - text = c( - "To see install notes or errors, specify the environment variable \\ - {.envvar GRETA_INSTALLATION_LOG}, with:\n", - "{.code Sys.setenv('GRETA_INSTALLATION_LOG'='path/to/logfile.html')}\n", - "Or set using {.fun greta_set_install_logfile}, e.g.,:\n", - "{.code greta_set_install_logfile('path/to/logfile.html')}"), - wrap = TRUE - ) cli::cli_alert_warning( text = c( - "If you want to retrieve the logfile, you will need to \\ - {.strong not restart R} and instead run:", - "" - ) + "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 ) } diff --git a/R/reinstallers.R b/R/reinstallers.R index 366a28b3..100395f0 100644 --- a/R/reinstallers.R +++ b/R/reinstallers.R @@ -97,6 +97,10 @@ reinstall_greta_deps <- function(python_deps = greta_python_deps(), #' @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 026ce68b..0eaee9da 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1254,94 +1254,3 @@ outside_version_range <- function(provided, range) { outside_range } -#' 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 -#' `greta_install_deps()`. -#' @export -greta_set_install_logfile <- function(path){ - Sys.setenv("GRETA_INSTALLATION_LOG"=path) -} - -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/R/write-logfiles.R b/R/write-logfiles.R new file mode 100644 index 00000000..e34816e1 --- /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 +#' `greta_install_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 +#' [greta_install_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/man/greta_set_install_logfile.Rd b/man/greta_set_install_logfile.Rd index e8efd596..649245e7 100644 --- a/man/greta_set_install_logfile.Rd +++ b/man/greta_set_install_logfile.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R +% 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} 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/write_greta_install_log.Rd b/man/write_greta_install_log.Rd new file mode 100644 index 00000000..21f7f7cb --- /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[=greta_install_deps]{greta_install_deps()}}, and before restarting R. +} From 5a347b53838c9019708d773aa3010618f7669637 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 17:49:11 +1000 Subject: [PATCH 04/16] type --- R/write-logfiles.R | 4 ++-- man/greta_set_install_logfile.Rd | 2 +- man/write_greta_install_log.Rd | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/write-logfiles.R b/R/write-logfiles.R index e34816e1..1ffc5a65 100644 --- a/R/write-logfiles.R +++ b/R/write-logfiles.R @@ -7,7 +7,7 @@ #' can benefit from the html rendering. #' #' @return nothing - sets an environment variable for use with -#' `greta_install_deps()`. +#' [install_greta_deps()]. #' @export greta_set_install_logfile <- function(path){ Sys.setenv("GRETA_INSTALLATION_LOG"=path) @@ -16,7 +16,7 @@ greta_set_install_logfile <- function(path){ #' Write greta dependency installation log file #' #' This can only be run after installation has happened with -#' [greta_install_deps()], and before restarting R. +#' [install_greta_deps()], and before restarting R. #' #' @param path a path with an HTML (.html) extension. #' diff --git a/man/greta_set_install_logfile.Rd b/man/greta_set_install_logfile.Rd index 649245e7..2d33b31e 100644 --- a/man/greta_set_install_logfile.Rd +++ b/man/greta_set_install_logfile.Rd @@ -12,7 +12,7 @@ can benefit from the html rendering.} } \value{ nothing - sets an environment variable for use with -\code{greta_install_deps()}. +\code{\link[=install_greta_deps]{install_greta_deps()}}. } \description{ To help debug greta installation, you can save all installation output diff --git a/man/write_greta_install_log.Rd b/man/write_greta_install_log.Rd index 21f7f7cb..da711602 100644 --- a/man/write_greta_install_log.Rd +++ b/man/write_greta_install_log.Rd @@ -14,5 +14,5 @@ nothing - writes to file } \description{ This can only be run after installation has happened with -\code{\link[=greta_install_deps]{greta_install_deps()}}, and before restarting R. +\code{\link[=install_greta_deps]{install_greta_deps()}}, and before restarting R. } From f335abc1b3b18fd0a27bdfdde572363e98065435 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 18:35:16 +1000 Subject: [PATCH 05/16] ensure package is loaded to load data? --- .github/workflows/R-CMD-check.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index fc958f85..16e402b9 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) + install_greta_deps(timeout = 50) - name: Situation Report on greta install run: greta::greta_sitrep() From 37447cc2844a0fae0e1b1eaf3da124420cb340d6 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 18:42:29 +1000 Subject: [PATCH 06/16] try not having lazydata --- .github/workflows/R-CMD-check.yaml | 4 +--- DESCRIPTION | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 16e402b9..fc958f85 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -81,9 +81,7 @@ jobs: run: remotes::install_local(dependencies = TRUE, force = TRUE) - name: Install greta deps - run: | - library(greta) - install_greta_deps(timeout = 50) + run: greta::install_greta_deps(timeout = 50) - name: Situation Report on greta install run: greta::greta_sitrep() diff --git a/DESCRIPTION b/DESCRIPTION index 23be7270..7a2755cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -134,4 +134,4 @@ Collate: 'write-logfiles.R' 'zzz.R' 'internals.R' -LazyData: true +LazyData: false From 61875f33647efefd0a89869d377a38d3d113c4a1 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 22:41:52 +1000 Subject: [PATCH 07/16] update gh action --- .github/workflows/R-CMD-check.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index fc958f85..38efc70c 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -78,7 +78,9 @@ jobs: done < <(Rscript -e "writeLines(remotes::system_requirements('$ID-$VERSION_ID'))") - name: Install package + deps - run: remotes::install_local(dependencies = TRUE, force = TRUE) + run: | + remotes::install_local(dependencies = TRUE, force = TRUE) + library(greta) - name: Install greta deps run: greta::install_greta_deps(timeout = 50) From 4e9e40b9cd8de6229266a4ddff358b662c89d6fa Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 22:43:10 +1000 Subject: [PATCH 08/16] turn back on LazyData --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7a2755cd..23be7270 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -134,4 +134,4 @@ Collate: 'write-logfiles.R' 'zzz.R' 'internals.R' -LazyData: false +LazyData: true From f5379b2a107b5c9c97a2c1469b2bc557e125d1e2 Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 22:57:36 +1000 Subject: [PATCH 09/16] run library(greta) before installing deps on GH actions --- .github/workflows/R-CMD-check.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 38efc70c..6e4ad56a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -78,12 +78,13 @@ jobs: done < <(Rscript -e "writeLines(remotes::system_requirements('$ID-$VERSION_ID'))") - name: Install package + deps - run: | - remotes::install_local(dependencies = TRUE, force = TRUE) - library(greta) + 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() From c275ea56f395b55cb94c3d58c18b5ac179e1c67f Mon Sep 17 00:00:00 2001 From: njtierney Date: Thu, 8 Aug 2024 23:00:20 +1000 Subject: [PATCH 10/16] Touch up the text used when greta cannot be loaded --- R/checkers.R | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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 ) From d24b2072bf00b7e73eaa81c8b0aa005181f708e1 Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 00:24:14 +1000 Subject: [PATCH 11/16] update failure to load msg --- tests/testthat/_snaps/misc.md | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) 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 From 91daa699ce8a1f167e7716bab7b9bbee04eb858f Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 07:22:51 +1000 Subject: [PATCH 12/16] * update python deps test to run valid test for all known OSs. * Add skip components in tests to not run on CRAN * update globalVariables * don't skip_on_ci() - see if these tests fail on current GH CI --- R/package.R | 13 +++++++++++-- tests/testthat/_snaps/greta_python_deps.md | 4 ++-- tests/testthat/test-greta_python_deps.R | 6 ++++-- tests/testthat/test_distributions.R | 4 ++-- tests/testthat/test_future.R | 2 +- 5 files changed, 20 insertions(+), 9 deletions(-) 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/tests/testthat/_snaps/greta_python_deps.md b/tests/testthat/_snaps/greta_python_deps.md index 6b078a01..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 --- diff --git a/tests/testthat/test-greta_python_deps.R b/tests/testthat/test-greta_python_deps.R index 85b6a2d6..c9c82fa8 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,7 @@ test_that("greta python range detection works correctly",{ test_that("greta_python_deps fails appropriately", { + skip_if_not(check_tf_version()) # default expect_snapshot(greta_python_deps()) # some correct ranges @@ -39,8 +41,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_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..54c78284 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_ci() m <- model(normal(0, 1)) From 1fca91ab332e44e16fc057c96a631dd42a09c23a Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 08:00:05 +1000 Subject: [PATCH 13/16] skip a specific future test on windows CI --- tests/testthat/test_future.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_future.R b/tests/testthat/test_future.R index 54c78284..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)) From c44f75b866cd381d826ba547596c4b8367d2e21b Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 08:00:37 +1000 Subject: [PATCH 14/16] Ensure suggested versions are just one value --- R/install_greta_deps.R | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/R/install_greta_deps.R b/R/install_greta_deps.R index aa9a5870..ac7a7ec2 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -227,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) @@ -379,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 |> @@ -462,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 \\ From 1e2f5fcd524da3eff8fb56e5af0a76031f96eea4 Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 08:27:04 +1000 Subject: [PATCH 15/16] skip certain snapshot tests on certain OSs as there are minor differences that aren't really that interesting --- .github/workflows/R-CMD-check.yaml | 1 - tests/testthat/test-greta_python_deps.R | 2 ++ tests/testthat/test-print_calculate.R | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 6e4ad56a..c222df86 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -80,7 +80,6 @@ jobs: - name: Install package + deps run: remotes::install_local(dependencies = TRUE, force = TRUE) - - name: Install greta deps run: | library(greta) diff --git a/tests/testthat/test-greta_python_deps.R b/tests/testthat/test-greta_python_deps.R index c9c82fa8..d7968bc4 100644 --- a/tests/testthat/test-greta_python_deps.R +++ b/tests/testthat/test-greta_python_deps.R @@ -32,6 +32,8 @@ 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 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) From 855e8e668d2d0c01c8bd35cfcad3aaad3f45ec06 Mon Sep 17 00:00:00 2001 From: njtierney Date: Fri, 9 Aug 2024 08:31:25 +1000 Subject: [PATCH 16/16] fix typos, update spelling WORDLIST --- R/data-deps-tf-tfp.R | 4 ++-- R/install_greta_deps.R | 2 +- inst/WORDLIST | 8 +++++--- man/greta_deps_tf_tfp.Rd | 4 ++-- man/greta_python_deps.Rd | 2 +- 5 files changed, 11 insertions(+), 9 deletions(-) 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/install_greta_deps.R b/R/install_greta_deps.R index ac7a7ec2..fa4e1c5a 100644 --- a/R/install_greta_deps.R +++ b/R/install_greta_deps.R @@ -205,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 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/greta_deps_tf_tfp.Rd b/man/greta_deps_tf_tfp.Rd index 2ece933e..1d93feb5 100644 --- a/man/greta_deps_tf_tfp.Rd +++ b/man/greta_deps_tf_tfp.Rd @@ -3,7 +3,7 @@ \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}}{ @@ -22,7 +22,7 @@ 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}. } 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