Skip to content

How to write a template file

When calling submit_slurm_job(mod) the template file supplied through slurmtools options, or the slurm_job_template_path argument is populated and submitted to slurm as a bash job. This setup offers extensive customization options through slurmtools, allowing you to adapt job configurations to suit your specific needs.

Simple template file

Below is a simple template file that can be used to submit NONMEM jobs to slurm with bbi .

slurm-job.tmpl
#!/bin/bash
#SBATCH --job-name="{{job_name}}"
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task={{ncpu}}
#SBATCH --partition={{partition}}
#SBATCH --account={{project_name}}
#{{project_path}}
# submit_slurm_job uses the whisker package to populate template files
# https://github.com/edwindj/whisker
{{#parallel}}
{{bbi_exe_path}} nonmem run local {{model_path}}.mod --parallel --threads={{ncpu}} --config {{bbi_config_path}}
{{/parallel}}
{{^parallel}}
{{bbi_exe_path}} nonmem run local {{model_path}}.mod --config {{bbi_config_path}}
{{/parallel}}

The template file uses the whisker package to fill in variables according to the Mustache templating standard . When submit_slurm_job is called, it reads the template file and injects both the default values provided to the template and any values passed in via the slurm_template_opts argument. Variables in the template file are denoted with double curly brackets, such as {{ injected_variable }}, and these placeholders are replaced with the respective values when submit_slurm_job runs.

Here’s an example of a filled-in template file after calling submit_slurm_job(mod):

1001.sh
#!/bin/bash
#SBATCH --job-name="1001-nonmem-run"
#SBATCH --nodes=1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --partition=cpu2mem4gb
#SBATCH --account=slurmtools
#/cluster-data/user-homes/user/Packages/slurmtools
# submit_slurm_job uses the whisker package to populate template files
# https://github.com/edwindj/whisker
/usr/local/bin/bbi nonmem run local /cluster-data/user-homes/user/Packages/slurmtools/model/nonmem/1001.mod --config /cluster-data/user-homes/user/Packages/slurmtools/model/nonmem/bbi.yaml

Understanding the tempalte file

This template file contains many aspects, the top 6 lines (starting with $SBATCH --<option>) define the slurm options for the job. next, there are two logical blocks:

{{#parallel}}
<parallel code>
{{/parallel}}

This block executes the <parallel code> if parallel == TRUE. The next block:

{{^parallel}}
<not parallel code>
{{/parallel}}

executes is parallel == FALSE.

This logic allows for versatile control flow, enabling you to build more complex template files to fit various job requirements.

Next steps

Let’s add some notifications to our job submission so we can see when it’s started and ended