g6tr.compute mirai overview
Iaroslav Domin
2026-05-15
Source:vignettes/mirai-overview.Rmd
mirai-overview.RmdGetting started
This vignette documents the mirai + Slurm workflow
inside g6tr.compute. It is intended for running R code in
the background on compute nodes, while keeping your current session free
to continue work.
The typical flow is:
- Inspect available partitions with
mirai_ls_partitions(). - Start a small pool of daemons with
mirai_start_daemons(). - Check daemon status with
mirai_ls_daemons(). - Launch tasks with
mirai_launch(). - Track results and status with
mirai_ls()and the task folder. - Clean up old tasks with
mirai_rm().
Available partitions
Start by listing partitions and their approximate resource limits:
This returns a tibble with partition, cpu,
memory_gb, and max_nodes (current limit for
that partition). Use this list to pick which partition to run on.
Default and recommended partition to use for modeling is
"c8a-4xlarge", which has cpu = 16 and
around 30 GB of memory.
Start daemons
Daemons are long‑lived mirai workers submitted to Slurm.
They sit idle until you submit work via mirai_launch().
mirai_start_daemons(n = 2)What do n and nodes mean?
-
n= number of daemons (workers) to start. -
nodes= how many nodes to spread those daemons across when calculating CPU/memory per daemon.
Internally, we compute:
daemons_per_node = ceiling(n / nodes).
Then we split the partition resources by
daemons_per_node to determine per‑daemon
cpu_count and mem_gb, unless you override them
directly.
Examples:
-
n = 1, nodes = 1→ one daemon, full node resources. -
n = 2, nodes = 1→ two daemons on one node (half resources each). -
n = 2, nodes = 2→ two daemons on two nodes (full resources each). -
n = 4, nodes = 2→ four daemons across two nodes (two per node).
nodes is validated against max_nodes from
mirai_ls_partitions().
Wait until status shows ready before submitting
jobs.
Launch tasks
Job environment task
Jobs run as separate R processes on compute nodes. They inherit key elements from your current session but are not the same process. In practice:
- The working directory is set to your current
getwd(). - Environment variables are copied from your session.
- The
/pfsshared drive is accessible, but non‑/pfspaths are not. -
.Rprofilein the working directory is executed. - Objects in your environment are not available unless you import them explicitly.
To inspect the environment inside a job:
task_id <- mirai_launch({
print(Sys.info()[["nodename"]])
print(Sys.getenv("SLURM_JOB_ID"))
print(Sys.getenv("SLURM_JOB_PARTITION"))
print(Sys.getenv("SLURM_JOB_NODELIST"))
print(sessionInfo())
print(getwd())
print(Sys.getenv())
return("RETURNING SINGLE STRING")
}, tags = c("env", "debug"))Every mirai_launch() call gets its own task
ID. A shared folder is created under
/pfs/home/<user>/mirai/<task_id>/ and used to
store artifacts for that task. You will typically find:
-
task.logfor stdout/stderr captured from the job. -
status.csvwith periodic status snapshots. -
output.rdscontaining the returned object. -
meta.rdscontaining task metadata (includingstatus_interval). -
status.doneas a sentinel when the task completes.
For convenience, you can access these artifacts by task id:
mirai_log(task_id)
mirai_status(task_id)
mirai_output(task_id)-
mirai_status()reads and returns the task status table. -
mirai_output()reads the task output (if it exists). -
mirai_log()reads the task log lines.
If you do not need those local artifacts after success, you can
launch with cleanup = TRUE. In that mode, the local task
folder is removed only after a successful run, while failed tasks keep
their local files for debugging.
mirai_launch({
# Write side effects elsewhere and return nothing important locally.
Sys.sleep(30)
cli::cli_alert_info("Uploading outputs to shared storage")
NULL
}, cleanup = TRUE)You can also provide a custom task_id so you can re-use
the same task folder between runs:
task_id_pi <- mirai_launch({
Sys.sleep(60)
3.14
}, task_id = "pi")You can add one or more tags at launch time and filter tasks by tag later:
mirai_launch({
Sys.sleep(60)
"uploaded"
}, task_id = "drive-upload", tags = c("drive", "export"))
mirai_ls(tags = "drive")
mirai_ls(tags = c("drive", "export"))Only one running task per task_id is allowed. If another
task with the same task_id is already running,
mirai_launch() will error. Once a task finishes, reusing
the task_id is allowed and the task folder is cleaned
before the new run starts.
To list existing tasks, use
mirai_ls()You can also add output if available with:
mirai_ls() |>
mirai_output()If you need to remove a task folder manually, use
mirai_rm():
If you see an error like:
Error in `mirai_rm()`:
! Task "pi" appears locked at /pfs/home/<user>/mirai/pi.lock.
✖ Mirai daemons are still running. To be safe, stop daemons first with `mirai_stop_daemons()`, then re-run `mirai_rm("pi")`.
ℹ If the lock is stale, re-run `mirai_rm("pi", force = TRUE)`.
To be safe, stop daemons first, then remove the task:
Another simple tasks
The simplest use case is to run a small block and return the result:
task_id_simple <- mirai_launch({
res <- hclust(dist(USArrests), "ave")
print(res)
res
})Check task status with:
mirai_ls()When the task finishes, you can pull the output:
Longer job
Let’s also run a longer job:
task_id_long <- mirai_launch({
for(i in 1:10) {
Sys.sleep(5)
cli::cli_alert_success("Done {i}!!")
}
"DONE ALL!"
})
mirai_ls()
mirai_status(task_id_long)
mirai_log(task_id_long)
mirai_output(task_id_long)Libraries and g6tr::g6tr_project_continue()
When project_continue = TRUE (default for known g6tr
projects), g6tr::g6tr_project_continue() runs automatically
inside the job. This usually attaches packages declared in your project
DESCRIPTION and sets up the project environment.
Importing objects
To transfer objects from your session into a job, use
import_objects. This copies the selected objects into the
job environment.
set.seed(1)
data <- data.frame(
x = rnorm(100),
y = rnorm(100)
)
for (n_centers in 3:10) {
mirai_launch(
{
Sys.sleep(20)
res <- kmeans(data, centers = n_centers); print(res) },
import_objects = c(data, n_centers),
task_id = paste0("kmeans-", n_centers, "-centers")
)
}
mirai_ls() |>
dplyr::filter(stringr::str_detect(task_id, "^kmeans-")) |>
mirai_output()If you are sending large objects (e.g., 100+ MB) to many jobs,
consider saving them once to an .RData file and using
import_path instead.
data <- data.frame(
x = rnorm(1e7),
y = rnorm(1e7)
)
save(data, file = "input.RData")
for (n_centers in 3:5) {
mirai_launch(
{ res <- kmeans(data, centers = n_centers); print(res) },
import_objects = c(n_centers),
import_path = "input.RData",
task_id = mirai_task_name("kmeans-big")
)
}
mirai_ls()Cleanup old tasks with mirai_rm()
Task folders can accumulate over time. Use mirai_ls()
with dplyr::filter() to choose tasks, then pass the result
to mirai_rm().
# Remove all completed tasks
mirai_ls() |>
dplyr::filter(state %in% c("success", "error")) |>
mirai_rm()
# Remove error tasks
mirai_ls() |>
dplyr::filter(state == "error") |>
mirai_rm()
# Remove tasks older than 1 day
mirai_ls() |>
dplyr::filter(age_min >= 24 * 60) |>
mirai_rm()
# Remove everything listed by mirai_ls()
mirai_ls() |>
mirai_rm()
# Force-delete selected tasks even if they still appear locked/running
mirai_ls() |>
dplyr::filter(state %in% c("running", "stale")) |>
mirai_rm(force = TRUE)Resource requirements
mirai_start_daemons() calculates per‑daemon CPU and
memory from mirai_ls_partitions() and the density
implied by n and nodes:
daemons_per_node = ceiling(n / nodes)cpu_count = floor(partition_cpu / daemons_per_node)mem_gb = partition_mem / daemons_per_node
You can always override the calculated values by passing
cpu_count and mem_gb directly to
mirai_start_daemons().
This gives you control over whether to pack more daemons per node or spread them across nodes.
Datalake
Tasks can read/write to/from Datalake.
task_id_datalake <- mirai_launch({
library(g6tr.dl)
print(dl_ls(project = "g6tr.compute"))
dl_write(mtcars, "data/mtcars", project = "g6tr.compute")
dl_read("data/mtcars", project = "g6tr.compute")
})
mirai_status(task_id_datalake)
mirai_log(task_id_datalake)
mirai_output(task_id_datalake)
g6tr.dl::dl_ls(project = "g6tr.compute")Google Drive
Google Drive stores credentials in your home directory and jobs can access them. Test with:
task_id_drive <- mirai_launch({
print(googledrive::drive_ls())
})
mirai_log(task_id_drive)Known issues
Most issues stem from differences between the job environment and your interactive session. Common examples:
Missing renv libraries
You might need to run g6tr::renv_install_missing() so
packages are available from the project renv library on
/pfs.
Missing .so libraries
Quick fix approach:
-
Find where the library is located on the server. In terminal run
ldconfig - p | grep <library name>. For example:ldconfig -p | grep libtbb.so.2 #> libtbb.so.2 (libc6,x86-64) => /lib/x86_64-linux-gnu/libtbb.so.2 Copy the missing
.sointo/pfs(replace<username>):
cp /lib/x86_64-linux-gnu/libtbb.so.2 /pfs/home/<username>/lib/
- Prepend the folder in your task:
mirai_launch({
Sys.setenv("LD_LIBRARY_PATH" = paste0("/pfs/home/<username>/lib:", Sys.getenv("LD_LIBRARY_PATH")))
# run your code here
})Long-term approach: update
bootstrap/compute.sh in
https://github.com/g6t/workbench-config and sync files to
S3:
S3_BUCKET="workbench-slurm-cluster"
S3_PREFIX="bootstrap"
aws s3 sync bootstrap/ \
s3://${S3_BUCKET}/${S3_PREFIX}/ \
--delete