Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d7e93d6
Increment version number to 0.5.1
njtierney Sep 3, 2025
a7e3eb0
NEWS
njtierney Sep 3, 2025
5926510
update snapshot to use R 4.5.1 and greta version 0.5.1
njtierney Sep 3, 2025
5268c4f
update vignette with a non-broken WinBUGS volume 2 PDF link
njtierney Sep 4, 2025
3d163d7
fix some spelling mistakes
njtierney Sep 4, 2025
b4282bb
update snapshots for installation and sitrep
njtierney Sep 4, 2025
5d979c3
CRAN comments
njtierney Sep 4, 2025
c34880c
revdep checks
njtierney Sep 4, 2025
3a0cc89
ignore .keras folder/files
njtierney Sep 9, 2025
af5b809
resolves #794
njtierney Sep 19, 2025
0e8d43f
resolve issue with .keras directory being created
njtierney Sep 19, 2025
27f25f8
fragile test on GH actions
njtierney Sep 19, 2025
2971c03
minor tweaks for CRAN resubmission:
njtierney Jan 28, 2026
38b223f
update codemeta
njtierney Jan 28, 2026
7a9ad60
also trigger purl to evaluate to FALSE when deps aren't met
njtierney Jan 28, 2026
d08c973
adding more specific stops to only use 2 cores when running vignettes
njtierney Jan 29, 2026
fdeb5c1
use parallely::availableCores. Resolves #797
njtierney Jan 30, 2026
0ca5edf
ensure we use 2 cores if none are specified
njtierney Feb 2, 2026
778afc9
add specific note about 2 cores
njtierney Feb 2, 2026
6a57cee
ignore claude
njtierney Feb 4, 2026
2f74868
use only 2 cores by default
njtierney Feb 4, 2026
35f3b28
don't measure the snapshot for the detailed sitrep; it's too complex.
njtierney Feb 4, 2026
60f1022
use 2L for number of cores
njtierney Feb 5, 2026
1fcbb24
fix little bug where conda list of installed pkgs wouldn't appear.
njtierney Feb 5, 2026
d66a4f3
add function for listing python modules installed under greta
njtierney Feb 5, 2026
b89cc26
very minor changes to docs
njtierney Feb 5, 2026
f96247d
update number of chains to be 2; update NEWS.
njtierney Feb 5, 2026
dcbc67f
n_chains for 2
njtierney Feb 6, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LICENSE
^cran-comments\.md$
^revdep$
^.keras$

^logos$
^paper$
Expand Down Expand Up @@ -54,3 +55,4 @@ LICENSE

# flint files
^flint$
^\.claude$
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
id: get-date
shell: bash
run: |
echo "::set-output name=year-week::$(date -u "+%Y-%U")"
echo "::set-output name=date::$(date -u "+%F")"
echo "year-week=$(date -u "+%Y-%U")" >> $GITHUB_OUTPUT
echo "date=$(date -u "+%F")" >> $GITHUB_OUTPUT

- name: Restore R package cache
uses: actions/cache@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ revdep/checks.noindex
revdep/library.noindex

testlog*.md
.claude
12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: greta
Title: Simple and Scalable Statistical Modelling in R
Version: 0.5.0.9000
Title: Simple and 'Scalable' Statistical Modelling in R
Version: 0.5.1
Authors@R: c(
person("Nick", "Golding", , "nick.golding.research@gmail.com", role = "aut",
comment = c(ORCID = "0000-0001-8916-5570")),
Expand All @@ -21,11 +21,11 @@ Authors@R: c(
person("Jian", "Yen", role = "ctb")
)
Description: Write statistical models in R and fit them by MCMC and
optimisation on CPUs and GPUs, using Google 'TensorFlow'. greta lets
optimisation on 'CPUs' and 'GPUs', using Google 'TensorFlow'. 'greta' lets
you write your own model like in BUGS, JAGS and Stan, except that you
write models right in R, it scales well to massive datasets, and it’s
easy to extend and build on. See the website for more information,
including tutorials, examples, package documentation, and the greta
including tutorials, examples, package documentation, and the 'greta'
forum.
License: Apache License 2.0
URL: https://greta-stats.org, https://github.com/greta-dev/greta
Expand All @@ -44,7 +44,7 @@ Imports:
parallelly (>= 1.29.0),
progress (>= 1.2.0),
R6,
reticulate (>= 1.19.0),
reticulate (>= 1.43.0),
rlang,
tensorflow (>= 2.16.0),
tools,
Expand Down Expand Up @@ -84,7 +84,7 @@ Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
SystemRequirements: Python (>= 3.7.0) with header files and shared
library; TensorFlow (>= v2.0.0; https://www.tensorflow.org/); TensorFlow
Probability (v0.8.0; https://www.tensorflow.org/probability/)
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export(greta_create_conda_env)
export(greta_deps_receipt)
export(greta_deps_spec)
export(greta_install_miniconda)
export(greta_list_py_modules)
export(greta_notes_tf_num_error)
export(greta_set_install_logfile)
export(greta_sitrep)
Expand Down Expand Up @@ -285,7 +286,6 @@ importFrom(coda,as.mcmc.list)
importFrom(coda,mcmc)
importFrom(coda,mcmc.list)
importFrom(coda,thin)
importFrom(future,availableCores)
importFrom(future,future)
importFrom(future,nbrOfWorkers)
importFrom(future,plan)
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# greta (development version)
# greta 0.5.1

## Changes

- `log.greta_array()` function warns if user uses the `base` arg, as it was unused, (#597).
- Add warmup information to MCMC print method (#652, resolved by #755).
- Add more options to level of detail in `greta_sitrep()` with "verbosity" argument. There are three levels, "minimal" (default), "detailed", and "quiet". (#612, resolved by #679).
- Use `.batch_size` instead of `batch_size` internally, to avoid rare name clash errors (#634).
- Resolve issues with Tensorflow version in DESCRIPTION (no longer can specify == 2.16.0, must be >= 2.16.0).
- When the number of cores requested exceeds the number of cores detected, then the number of cores detected will be used.
- Ensure that `n_cores` arg defaults to 2 cores. Similarly, `chains` defaults to two chains.
- Minor internal changes for handling versions of python modules.
- Added `greta_list_py_modules()` as a function to show the Python packages installed in a specific TF2 environment.

# greta 0.5.0

Expand Down
27 changes: 13 additions & 14 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -755,16 +755,14 @@ check_cum_op <- function(x, call = rlang::caller_env()) {
}
}


#' @importFrom future availableCores
check_n_cores <- function(n_cores, samplers, plan_is) {
# if the plan is remote, and the user hasn't specificed the number of cores,
# leave it as all of them
# if the plan is remote, and the user hasn't specified the number of cores,
# still only use 2
if (is.null(n_cores) & !plan_is$local) {
return(NULL)
return(2L)
}

n_cores_detected <- future::availableCores()
n_cores_detected <- parallelly::availableCores()
allowed_n_cores <- seq_len(n_cores_detected)

cores_exceed_available <- !is.null(n_cores) && !n_cores %in% allowed_n_cores
Expand All @@ -773,19 +771,20 @@ check_n_cores <- function(n_cores, samplers, plan_is) {

cli::cli_warn(
message = "{n_cores} cores were requested, but only {n_cores_detected} \\
are available."
are available. Setting number of cores to {n_cores_detected}."
)

n_cores <- NULL
return(as.integer(n_cores_detected))
}

# if n_cores isn't user-specified, set it so there's no clash between samplers
n_cores <- n_cores %||% floor(n_cores_detected / samplers)

# make sure there's at least 1
n_cores <- max(n_cores, 1)
# # if n_cores isn't user-specified, set it so there's no clash between samplers
# n_cores <- n_cores %||% floor(n_cores_detected / samplers)
# # make sure there's at least 1
# n_cores <- max(n_cores, 1)

as.integer(n_cores)
# if n_cores isn't specified, make sure it is set to 2 by default
# Resolves #796
n_cores %||% 2L
}

check_positive_integer <- function(x, name = "", call = rlang::caller_env()) {
Expand Down
76 changes: 69 additions & 7 deletions R/greta-sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#' @param verbosity character. How verbose the output of the situation report.
#' Possible options: "minimal" (default), "detailed", and "quiet". "Minimal"
#' provides just information in python version, tensorflow version,
#' tensorflow proability, and whether greta conda environment is available.
#' tensorflow probability, and whether greta conda environment is available.
#' "Quiet" presents no information, but prepares greta to be used. "Detailed"
#' gives information on the version and path for R, greta, python,
#' tensorflow, tensorflow probability, the greta conda environment, and a
#' statement on greta usability.
#' @return Message on greta situation report. See "verbsoity" parameter details
#' @return Message on greta situation report. See "verbosity" parameter details
#' above for more information.
#' @export
#'
Expand Down Expand Up @@ -63,7 +63,8 @@ detailed_sitrep <- function() {
check_if_greta_conda_env_available()
conda_env_path <- greta_conda_env_path()
cli::cli_ul("path: {.path {conda_env_path}}")
conda_modules <- conda_list_env_modules()

conda_modules <- greta_list_py_modules()

tf_in_conda <- nzchar(grep(
"^(tensorflow)(\\s|$)",
Expand Down Expand Up @@ -97,12 +98,75 @@ detailed_sitrep <- function() {
)
}

#' List Python modules installed in greta env
#'
#' @returns matrix/data frame of Python modules that are installed in the greta environment - showing the name, version, build, and install channel.
#'
#' @export
greta_list_py_modules <- function() {
conda_modules <- tryCatch(
expr = {
# This will find conda whether it's on PATH or installed by reticulate
conda_bin <- reticulate::conda_binary()

system2(
conda_bin,
args = c("list", "-n", "greta-env-tf2"),
stdout = TRUE,
stderr = TRUE
)
},
error = function(e) {
cli::cli_ul(
c(
"Encountered an error in running:",
"{.code conda list -n greta-env-tf2}",
"x" = "{.code {e$message}}",
"!" = "conda may not be installed. Try {.code reticulate::install_miniconda()}"
)
)
return(NULL)
}
)

conda_modules
}

conda_modules <- tryCatch(
expr = {
# This will find conda whether it's on PATH or installed by reticulate
conda_bin <- reticulate::conda_binary()

system2(
conda_bin,
args = c("list", "-n", "greta-env-tf2"),
stdout = TRUE,
stderr = TRUE
)
},
error = function(e) {
cli::cli_ul(
c(
"Encountered an error in running:",
"{.code conda list -n greta-env-tf2}",
"x" = "{.code {e$message}}",
"!" = "conda may not be installed. Try {.code reticulate::install_miniconda()}"
)
)
return(NULL)
}
)

quiet_sitrep <- function() {
suppressMessages(check_greta_ready_to_use())
}

conda_list_env_modules <- function() {
system(paste("conda list -n", "greta-env-tf2"), intern = TRUE)
system(
paste("conda list -n", "greta-env-tf2"),
intern = TRUE,
ignore.stderr = TRUE
)
}


Expand Down Expand Up @@ -286,9 +350,7 @@ have_tfp <- function() {
is_tfp_available <- py_module_available("tensorflow_probability")

if (is_tfp_available) {
pkg <- reticulate::import("pkg_resources")
tfp_version <- pkg$get_distribution("tensorflow_probability")$version
is_tfp_available <- utils::compareVersion("0.15.0", tfp_version) <= 0
is_tfp_available <- utils::compareVersion("0.15.0", tfp$`__version__`) <= 0
}

return(is_tfp_available)
Expand Down
2 changes: 1 addition & 1 deletion R/greta_model_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ print.greta_model <- function(x, ...) {
#' @details The plot method produces a visual representation of the defined
#' model. It uses the `DiagrammeR` package, which must be installed
#' first. Here's a key to the plots:
#' \if{html}{\figure{plotlegend.png}{options: width="100\%"}}
#' \if{html}{\figure{plotlegend.png}{options: width=100}}
#' \if{latex}{\figure{plotlegend.pdf}{options: width=7cm}}
#'
#' @return `plot` - a [DiagrammeR::grViz()]
Expand Down
14 changes: 7 additions & 7 deletions R/inference.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ greta_stash$numerical_messages <- c(
#' rest are discarded
#' @param warmup number of samples to spend warming up the mcmc sampler (moving
#' chains toward the highest density area and tuning sampler hyperparameters).
#' @param chains number of MCMC chains to run
#' @param chains number of MCMC chains to run. Default is 2. We recommend using more chains as this helps improve convergence. However the number of chains specified can increase the CPU load, so we have to set a lower default value.
#' @param n_cores the maximum number of CPU cores used by each sampler (see
#' details).
#' details). If NULL (default), it sets them to 2 cores.
#' @param verbose whether to print progress information to the console
#' @param pb_update how regularly to update the progress bar (in iterations).
#' If `pb_update` is less than or equal to `thin`, it will be set
Expand Down Expand Up @@ -94,9 +94,9 @@ greta_stash$numerical_messages <- c(
#' schedulers.
#'
#' If `n_cores = NULL` and mcmc samplers are being run sequentially, each
#' sampler will be allowed to use all CPU cores (possibly to compute multiple
#' chains sequentially). If samplers are being run in parallel with the
#' `future` package, `n_cores` will be set so that `n_cores *
#' sampler will be allowed to use only 2 CPU cores (possibly to compute
#' multiple chains sequentially). If samplers are being run in parallel with
#' the `future` package, `n_cores` will be set so that `n_cores *
#' [future::nbrOfWorkers]` is less than the number
#' of CPU cores.
#'
Expand All @@ -109,7 +109,7 @@ greta_stash$numerical_messages <- c(
#' memory usage.
#'
#' @note to set a seed with MCMC you can use [set.seed()], or
#' [tensorflow::set_random_seed()]. They both given identical results. See
#' [tensorflow::set_random_seed()]. They both give identical results. See
#' examples below.
#'
#' @return `mcmc`, `stashed_samples` & `extra_samples` - a
Expand Down Expand Up @@ -212,7 +212,7 @@ mcmc <- function(
n_samples = 1000,
thin = 1,
warmup = 1000,
chains = 4,
chains = 2,
n_cores = NULL,
verbose = TRUE,
pb_update = 50,
Expand Down
9 changes: 8 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ tf <- tfp <- NULL
.onLoad <- function(libname, pkgname) {
# nolint

# resolve issue with .keras directory
Sys.setenv(
"KERAS_HOME" = normalizePath(
tools::R_user_dir("greta", "cache"),
mustWork = FALSE
)
)

# silence TF's CPU instructions message
Sys.setenv(TF_CPP_MIN_LOG_LEVEL = 2)

Expand Down Expand Up @@ -42,5 +50,4 @@ tf <- tfp <- NULL

# warn if TF version is bad
# check_tf_version("startup")

}
Loading