Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combine log files into a single file #683

Merged
merged 16 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Imports:
reticulate (>= 1.19.0),
rlang,
tensorflow (>= 2.8.0),
whisker,
yesno
Suggests:
bayesplot,
Expand Down Expand Up @@ -130,6 +131,7 @@ Collate:
'checkers.R'
'test_if_forked_cluster.R'
'testthat-helpers.R'
'write-logfiles.R'
'zzz.R'
'internals.R'
LazyData: true
9 changes: 3 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export(colMeans)
export(colSums)
export(cov2cor)
export(cpu_only)
export(destroy_greta_deps)
export(diag)
export(dirichlet)
export(dirichlet_multinomial)
Expand All @@ -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)
Expand Down Expand Up @@ -268,6 +264,7 @@ export(uniform)
export(variable)
export(weibull)
export(wishart)
export(write_greta_install_log)
export(zeros)
import(methods)
importFrom(R6,R6Class)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 8 additions & 9 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down
4 changes: 2 additions & 2 deletions R/data-deps-tf-tfp.R
Original file line number Diff line number Diff line change
@@ -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
#' <https://www.tensorflow.org/install/source>,
#' <https://www.tensorflow.org/install/source> and
#' <https://www.tensorflow.org/install/source_windows>, and by inspecting
#' <https://github.com/tensorflow/probability/releases>.
#'
Expand Down
5 changes: 0 additions & 5 deletions R/greta_create_conda_env.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")

}
4 changes: 0 additions & 4 deletions R/greta_install_miniconda.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")
}
5 changes: 0 additions & 5 deletions R/greta_install_python_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()}")

}
54 changes: 9 additions & 45 deletions R/greta_stash.R
Original file line number Diff line number Diff line change
@@ -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)
}
80 changes: 63 additions & 17 deletions R/install_greta_deps.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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:",
Expand All @@ -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:",
Expand Down Expand Up @@ -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 |>
Expand Down Expand Up @@ -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 \\
Expand Down
13 changes: 11 additions & 2 deletions R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Loading
Loading