Skip to content

wrong args for environment subassignment #285

@myushen

Description

@myushen

Hi,

I had the following error when trying to use MulticoreParam with R targets pipeline. Debugging doesn't reproduce the error. I later figured out it was OOM as it needed more than 2GB to process the data on HPC, while my local R session used to debug had more than 20GB memory allocations.

It would be ideal the print the more meaningful error message.

# _targets.R
library(targets)
library(crew)
library(crew.cluster)
library(BiocParallel)

controller_default <- crew_controller_slurm(
  name                           = "slurm_default",
  workers                        = 4,
  seconds_idle                   = 30,
  slurm_memory_gigabytes_per_cpu = 2,
  slurm_cpus_per_task            = 4
)

tar_option_set(
  controller = controller_default,
  resources  = tar_resources(
    crew = tar_resources_crew(controller = "slurm_default")
  )
)

process_chunks <- function() {
  
  cores <- as.numeric(Sys.getenv("SLURM_CPUS_PER_TASK", unset = 1)) - 1L
  if (nzchar(Sys.getenv("_R_CHECK_LIMIT_CORES_")))
    cores <- min(cores, 2L)
  
  bp <- MulticoreParam(workers = cores, progressbar = TRUE)
  
  bplapply(
    seq_len(cores + 1L),   
    FUN = function(i) {
      message(sprintf("[bpworker PID %d] task %d: allocating ~4 GB",
                      Sys.getpid(), i))
      n <- as.integer(2000 * 1024^2 / 8)   
      x <- rnorm(n)                         
      y <- rnorm(n)                          
      sum(x * y)
    },
    BPPARAM = bp
  )
}

# ── pipeline ──────────────────────────────────────────────────────────────────
list(
  tar_target(
    oom_bp,
    process_chunks()   # crew worker (2 GB) + forked bplapply children → OOM
  )
)

> library(targets)
> tar_make(store = "~", script = "~/_targets.R")
+ oom_bp dispatchedoom_bp errorederrored pipeline [50.9s, 0 completed, 0 skipped]           
Warning messages:
1: script_lines was deprecated on 2024-10-09 (version 0.3.2.9005). Alternative: options_cluster argument. 
2: slurm_memory_gigabytes_per_cpu was deprecated on 2024-10-09 (version 0.3.2.9005). Alternative: options_cluster argument. 
3: slurm_cpus_per_task was deprecated on 2024-10-09 (version 0.3.2.9005). Alternative: options_cluster argument. 
4: 1 targets produced warnings. Run targets::tar_meta(fields = warnings, complete_only = TRUE) for the messages. 
Error:
! Error in tar_make():
  wrong args for environment subassignment
  See https://books.ropensci.org/targets/debugging.html

Debug:

> tar_workspace(oom_bp, store = "~", script = "~/_targets.R")
Warning messages:
1: In readLines(script) : incomplete final line found on '~/_targets.R'
2: slurm_memory_gigabytes_per_cpu was deprecated on 2024-10-09 (version 0.3.2.9005). Alternative: options_cluster argument. 
3: slurm_cpus_per_task was deprecated on 2024-10-09 (version 0.3.2.9005). Alternative: options_cluster argument. 

> process_chunks()
  |                                                                                                                               |   0%
[bpworker PID 1690242] task 4: allocating ~4 GB
  |================                                                                                                               |  12%
[bpworker PID 1690239] task 1: allocating ~4 GB
  |================================                                                                                               |  25%
[bpworker PID 1690240] task 2: allocating ~4 GB
  |================================================                                                                               |  38%
[bpworker PID 1690245] task 7: allocating ~4 GB
  |================================================================                                                               |  50%
[bpworker PID 1690241] task 3: allocating ~4 GB
  |===============================================================================                                                |  62%
[bpworker PID 1690244] task 6: allocating ~4 GB
  |===============================================================================================                                |  75%
[bpworker PID 1690243] task 5: allocating ~4 GB
  |===============================================================================================================                |  88%
[bpworker PID 1690270] task 8: allocating ~4 GB
  |===============================================================================================================================| 100%

[[1]]
[1] 4439.251

[[2]]
[1] 14078.1

[[3]]
[1] -2978.421

[[4]]
[1] -35503.84

[[5]]
[1] -7880.825

[[6]]
[1] -3674.885

[[7]]
[1] 9433.41

[[8]]
[1] -9041.888

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions