This function ensures that a suitable Python environment (virtualenv or conda) is available and that 'torch' and 'numpy' or 'tinygrad' are installed within it. Users should run this once before using functions that rely on PyTorch.

setup_py_env(
  method = c("conda", "virtualenv"),
  envname = "FastPCA",
  python_version = "3.10",
  backend = c("pytorch"),
  cuda = FALSE,
  ...
)

Arguments

method

Character string. The method to use for environment creation. Can be "conda" (default) or "virtualenv".

envname

Character string. The name of the Python environment to create/use. Defaults to "FastPCA".

python_version

Character string. The Python version to use (e.g., "3.9"). Defaults to "3.9". It's recommended to stick to well-supported versions.

backend

character string of the backend to use. Either 'torch', 'tinygrad', or 'all'. Defaults to 'all' to install all packages into the environment. Currently only pytorch. Flag is ignored

cuda

boolean for whether to install cuda toolkit to leverage the cuda backend

...

Additional arguments passed to reticulate::virtualenv_create() or reticulate::conda_create().

Value

Invisibly returns TRUE if setup is successful, FALSE otherwise.

Examples

if (FALSE) { # \dontrun{
  #for conda
  FastPCA::setup_py_env(method = "conda")

  #reticulate virtualenv:
  FastPCA::setup_py_env()
} # }