mllg / batchtools

Tools for computation on batch systems
https://mllg.github.io/batchtools/
GNU Lesser General Public License v3.0
172 stars 51 forks source link

SUGGESTION: Robustify example template files #228

Open HenrikBengtsson opened 5 years ago

HenrikBengtsson commented 5 years ago

I'd like to suggest adding a bit of sanity checks to the template files. This will help lower the bar for new comers who are not aware of the various levels of R-to-scheduler orchestration involved.

Issue

In 'inst/templates/slurm-simple.tmpl' we have:

https://github.com/mllg/batchtools/blob/1188e2a71028d386119834a22f3f03ba51ac7b85/inst/templates/slurm-simple.tmpl#L26-L34

Take for instance the line:

#SBATCH --cpus-per-task=<%= resources$ncpus %> 

if resources does not have ncpus set, then resources$ncpus is NULL, and then <%= NULL %> produces an empty string ``. That is, in the rendered job script, we get:

#SBATCH --cpus-per-task=

This in turn will produce a runtime error when Slurm tries to process the job script, e.g.

Error: Fatal error occurred: 101. Command 'sbatch' produced exit code 1. Output: 'sbatch: error: Invalid numeric value "" for cpus-per-task.' 

A few suggestions

Avoid outputting the SBATCH directive if resources$ncpus is missing:

<%= if (!is.null(resources$ncpus)) { %>
#SBATCH --cpus-per-task=<%= resources$ncpus %> 
<%= } %>

or, simply,

<%= sprintf("#SBATCH --cpus-per-task=%s", resources$ncpus) %> 

Alternatively, make ncpus a mandatory field. At the top of the template file, do something like:

<%
if (is.null(resources$ncpus)) stop("Resource parameter 'ncpus' is not set")
%>

Related

The background for this is issue can be found in https://github.com/HenrikBengtsson/future.batchtools/issues/41

cc/ @wlandau-lilly (similar for drake's example templates)