mlr-org / mlr-org/batchtools

SUGGESTION: Robustify example template files

Open
#228 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
184
Forks
53
Avg merge
7d 2h
Merged PRs (30d)
1

Description

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)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the referenced block in inst/templates/slurm-simple.tmpl, lines 26-34, and inspect how missing resources$ncpus is rendered. Decide whether the affected templates should omit invalid SBATCH directives or reject missing resources, then verify that a missing ncpus value no longer produces a malformed job script.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
hpc
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.