BioParallel::BatchtoolsParam() - how to pass customized resource variables to batchtool's "slurm-simple" template using BatchtoolsParam()?
1
0
Entering edit mode
@chao-jen-wong-7035
Last seen 16 months ago
USA/Seattle/Fred Hutchinson Cancer Rese…

I want to use "BatchtoolsParam" to parametrize schedule options on slurm backend. When using slurm backend, the template slurm-simpl.tmpl provided by batchtools is used to parametrize sbatch variables. My problem is that I cannot find a way to pass the resources variable to the template;

Here is my code:

library(BiocParallel)

piApprox <- function(n) {
    nums <- matrix(runif(2 * n), ncol = 2)
    d <- sqrt(nums[, 1]^2 + nums[, 2]^2)
    4 * mean(d <= 1)
}

param <- BatchtoolsParam(worker=4, cluster="slurm",
                         jobname="test",
                         stop.on.error=TRUE)
bpstart(param)
result <- bplapply(rep(10e5, 100), piApprox, BPPARAM=param)
bpstop(param)

I got the error message because sbatch variable cpus-per-task is invalid.

Adding 100 jobs ...
Submitting 100 jobs in 4 chunks using cluster functions 'Slurm' ...
Error in batchtools::submitJobs(ids = ids, resources = list(), reg = registry) :
  Fatal error occurred: 101. Command 'sbatch' produced exit code 1. Output: 'sbatch: error: Invalid numeric value "" for cpus-per-task.'

I use the The "slurm" template from batchtools:

a <- batchtoolsTemplate("slurm")
readLines(a)

The slurm template looks like this:

#!/bin/bash

#SBATCH --job-name=<%= job.name %>
#SBATCH --output=<%= log.file %>
#SBATCH --error=<%= log.file %>
#SBATCH --time=<%= ceiling(resources$walltime / 60) %>
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=<%= resources$ncpus %>
#SBATCH --mem-per-cpu=<%= resources$memory %>

I want to set resources$ncpus and resources$partition, but don't know how. If I just modify the template manually, that will do. But I am curious what is the best practice to modify the resources using BatchtoolsParam.

Thank you for your support.

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS/LAPACK: /app/easybuild/software/OpenBLAS/0.2.18-GCC-5.4.0-2.26-LAPACK-3.6.1/lib/libopenblas_prescottp-r0.2.18.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] BatchJobs_1.7        BBmisc_1.11          BiocParallel_1.14.2
[4] BiocInstaller_1.30.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.18      magrittr_1.5      rappdirs_0.3.1    hms_0.4.2
 [5] progress_1.2.0    bit_1.1-14        debugme_1.1.0     R6_2.2.2
 [9] rlang_0.2.1       brew_1.0-6        sendmailR_1.2-1   blob_1.1.1
[13] tools_3.5.1       parallel_3.5.1    checkmate_1.8.5   data.table_1.11.4
[17] DBI_1.0.0         withr_2.1.2       assertthat_0.2.0  base64url_1.4
[21] bit64_0.9-7       digest_0.6.15     crayon_1.3.4      base64enc_0.1-3
[25] fs_1.2.5          batchtools_0.9.10 memoise_1.1.0     RSQLite_2.1.1
[29] stringi_1.2.4     compiler_3.5.1    prettyunits_1.0.2 backports_1.1.2
[33] pkgconfig_2.0.1
biocparallel BatchtoolsParam • 2.2k views
ADD COMMENT
3
Entering edit mode
Mike Smith ★ 6.6k
@mike-smith
Last seen 51 minutes ago
EMBL Heidelberg

I think the appropriate way is to use the resources argument to BatchToolsParam, which takes a named list e.g.

BatchtoolsParam(resources = list(ncpus=4))

You can find a list of the resources you can set via ?batchtools::submitJobs

This is using:

BiocParallel_1.15.12
batchtools_0.9.11
ADD COMMENT
0
Entering edit mode

Mike, thanks for your prompt help. I still run into the problems. It seems like resources is not a valid argument for BatchtoolsParam. Here is my code to include resource as an input argument for the BatchtoolsParam constructor:

param <- BatchtoolsParam(worker=4, cluster="slurm",
                         jobname="test",
                         resources=list(ncpus=1,
                                       walltime=30L * 24L * 60L * 60L,
                                       partition="campus"),
                         stop.on.error=TRUE)

I got error message

Error in BatchtoolsParam(worker = 4, cluster = "slurm", jobname = "test",  :
  unused argument (resources = list(ncpus = 1, walltime = 30 * 24 * 60 * 60, partition = "campus"))

I don't understand why BatchJobParam allows resources argument, but not BatchtoolsParam. Or do I do something wrong here??? 

My session info is the same as above.

ADD REPLY
1
Entering edit mode

I think my example only works for the developmental version of BiocParallel - apologies for that.  I've updated the post with the package versions.

ADD REPLY
0
Entering edit mode

The argument you need is `template`

param <- BatchtoolsParam(workers=5, cluster="sge", template=template)

The template can hold your ncpus information.  There is also an option called `registryargs` where you can pass in the resources you want. 

Please check the vignette,

https://bioconductor.org/packages/devel/bioc/vignettes/BiocParallel/inst/doc/BiocParallel_BatchtoolsParam.pdf

And feel free to reply if you have any more questions. 

ADD REPLY
0
Entering edit mode

Thank you, Mike. But registryargs only takes arguments ‘file.dir’, ‘work.dir’, ‘packages’, ‘namespaces’, ‘source’, ‘load’, and ‘make.default’. It is not for resrouces vaiables. When I set cluster="slurm", BatchtoolsParam uses batchtool's default template(batchtoolsTemplate("slurm")). So here is my code:

FUN <- function(i) system("hostname", intern=TRUE)
param <- BatchtoolsParam(worker=4, cluster="slurm",
                         jobname="test",
                         registryargs=list(ncpus=1,
                                           partition="campus",
                                           file.dir=getwd()),
                         stop.on.error=TRUE)
bplapply(rep(10e5, 10), FUN, BPPARAM=param)

And error for saying that those resource variables for the default templated provided by batchtools are not volid arguements.

> bplapply(rep(10e5, 10), FUN, BPPARAM=param)
Error in (function (file.dir = "registry", work.dir = getwd(), conf.file = findConfFile(),  :
  unused arguments (ncpus = 1, partition = "campus")

Can I make a conclusion here that the release version of BatchtoolsParam does not provide a channel to send resources variable to the template? But the devel version has fixed it?

ADD REPLY
1
Entering edit mode

Obviously some confusion here to straighten out! I think resources=list(ncpus=10L) is the argument you're aiming for. From ?BatchtoolsParam:

resources: 'named list()'
     Arguments passed to the 'resources' argument of
     'batchtools::submitJobs' during evaluation of 'bplapply' and
     similar functions. These name-value pairs are used for
     substitution into the template file.

And yes, the release version (until October 31) doesn't provide a solution; the template would have to use some other means for identifying number of cores. (Hi Chao-Jen!)

ADD REPLY
0
Entering edit mode

Thank Matin. That straighten out my confusion!!!

(Hi Martin!)

ADD REPLY
1
Entering edit mode

The batchtools package replaces BatchJobs for reasons outlined in the 'Migration from...' section of the vignette in batchtools, and so BatchtoolsParam replaces BatchJobsParam. The resources= argument was not included in the initial implementation of BatchtoolsParam (maybe by oversight...), but was added as a 'new feature' (rather than 'bug fix') during the most recent development cycle. As a 'new feature', it is only available in devel. The devel branch becomes the release branch on (all being well) October 31.

It is not possible to port this feature to the release branch because the next release is in just a few days; the release branch is no longer being built.

ADD REPLY

Login before adding your answer.

Traffic: 1123 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6