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

Mike, thanks for your prompt help. I still run into the problems. It seems like
resourcesis not a valid argument forBatchtoolsParam. Here is my code to includeresourceas an input argument for theBatchtoolsParamconstructor:I got error message
I don't understand why
BatchJobParamallowsresourcesargument, but notBatchtoolsParam. Or do I do something wrong here???My session info is the same as above.
I think my example only works for the developmental version of BiocParallel - apologies for that. I've updated the post with the package versions.
The argument you need is `template`
The template can hold your ncpus information. There is also an option called `
registryargs` where you can pass in theresourcesyou 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.
Thank you, Mike. But
registryargsonly takes arguments ‘file.dir’, ‘work.dir’, ‘packages’, ‘namespaces’, ‘source’, ‘load’, and ‘make.default’. It is not forresroucesvaiables. When I setcluster="slurm", BatchtoolsParam uses batchtool's default template(batchtoolsTemplate("slurm")). So here is my code:And error for saying that those resource variables for the default templated provided by batchtools are not volid arguements.
Can I make a conclusion here that the release version of BatchtoolsParam does not provide a channel to send
resourcesvariable to the template? But the devel version has fixed it?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!)
Thank Matin. That straighten out my confusion!!!
(Hi Martin!)
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.