## ----include = FALSE----------------------------------------------------------

# Force limit to 2 cores for CRAN
Sys.setenv("R_PARALLELLY_AVAILABLE_CORES" = "2")
Sys.setenv("OMP_THREAD_LIMIT" = "2")
Sys.setenv("TF_NUM_INTRAOP_THREADS" = "1")
Sys.setenv("TF_NUM_INTEROP_THREADS" = "1")

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)


## ----setup--------------------------------------------------------------------
library(greta)

## ----first-use, eval = FALSE--------------------------------------------------
# install.packages("greta")
# 
# library(greta)
# x <- normal(0, 1)

## ----sitrep, eval = FALSE-----------------------------------------------------
# greta_sitrep()

## ----smoke-test, eval = FALSE-------------------------------------------------
# x <- normal(0, 1)
# m <- model(x)
# draws <- mcmc(m)
# draws

## ----offline-override, eval = FALSE-------------------------------------------
# # force offline mode: e.g. before greta detects the cache, or on a machine
# # where you copied the cache over
# Sys.setenv(UV_OFFLINE = "1")
# 
# # force uv back online: for example to refresh the environment
# Sys.setenv(UV_OFFLINE = "0")

## ----offline, eval = FALSE----------------------------------------------------
# # point at a specific Python binary
# greta_set_python("path", path = "/opt/python-envs/greta/bin/python")
# 
# # or point at the environment directory and let greta find the binary
# greta_set_python("path", path = "/opt/python-envs/greta")
# 
# # on Windows, an environment directory works the same way; greta looks for
# # Scripts\\python.exe inside it
# greta_set_python("path", path = "C:/python-envs/greta")

## ----offline-conda, eval = FALSE----------------------------------------------
# greta_set_python("conda", name = "greta-env-tf2")

## ----deps-spec, eval = FALSE--------------------------------------------------
# greta_deps_spec(
#   tf_version = "2.15.0",
#   tfp_version = "0.23.0",
#   python_version = "3.10"
# )

## ----deps-table, eval = FALSE-------------------------------------------------
# View(greta_deps_tf_tfp)

## ----set-deps, eval = FALSE---------------------------------------------------
# greta_set_deps(
#   greta_deps_spec(
#     tf_version = "2.14.0",
#     tfp_version = "0.22.1",
#     python_version = "3.10"
#   )
# )
# 
# # clear the stored versions and return to greta's defaults
# greta_remove("deps")

## ----install-deps, eval = FALSE-----------------------------------------------
# install_greta_deps()

## ----use-conda, eval = FALSE--------------------------------------------------
# greta_set_python("conda")

## ----greta-set, eval = FALSE--------------------------------------------------
# # use the managed (uv) environment (the default)
# greta_set_python()
# # use the "greta-env-tf2" conda environment
# greta_set_python("conda")
# # use a specific Python
# greta_set_python("path", path = "/path/to/python")
# # clear the choice; resolve automatically
# greta_reset_python()

## ----reticulate-python, eval = FALSE------------------------------------------
# Sys.setenv(RETICULATE_PYTHON = "/path/to/your/python")
# library(greta)

## ----starting-over, eval = FALSE----------------------------------------------
# # everything at once (the default) -- asks for confirmation once, then
# # removes everything it finds
# greta_remove()
# # the "greta-env-tf2" conda environment
# greta_remove("env")
# # the miniconda installation
# greta_remove("miniconda")
# # reticulate's uv cache
# greta_remove("uv_cache")
# # just the stored Python preference (from greta_set_python())
# greta_remove("preference")
# # just the stored dependency versions (from greta_set_deps())
# greta_remove("deps")

## ----manual-conda, eval = FALSE-----------------------------------------------
# reticulate::install_miniconda()
# reticulate::conda_create(
#   envname = "greta-env-tf2",
#   python_version = "3.11"
# )
# reticulate::conda_install(
#   envname = "greta-env-tf2",
#   packages = c(
#     "tensorflow-probability==0.23.0",
#     "tensorflow==2.15.1"
#   )
# )

