Example 1 - Using SLURMRESTJob
to Submit Job Locally
A first example to show how the SLURMRESTJob object can be used
The **kwargs
for SLURMRESTJob
can be found listed the SlurmSubmit schema. This consists of all possible the SLURM SBATCH options, of which only a few are of interest in most cases.
Additionally, SlurmJob
has external or extra options. These are options used to specify a given job definition, but that are not SLURM sbatch options.
In this example, a SlurmJob
object in initialized with the following configuration:
name
: the name of the job once submitted to the SLURM scheduler will be slurmjobs_example1job_script
: path to script to be submitted as a job (when using relative paths upon invoking aSlurmJob
object, the paths should be relative to the script's path that invokesSlurmJob
.)env_extra
: a dictionary, where they keys are the environment variable name to be set and the values are the corresponding values to assign to the associated key/environment variable. There are some caveats that allow appending, prepending of replacing a given environment variable if it already exists within the local environment that are discussed belowstandard_out
: path to write stdout to file - notice in the example that it is acceptable to use~
to specify the$HOME
directory path of the current userstandard_error
path to write stderr to file - again the~
is usedtasks
: number of tasks for SLURM to runcpus_per_task
: number of CPUs to assign per task (total CPUs = tasks * cpus_per_task)memory_per_node
: total memory to request for SLURM per node (default number of nodes requested is 1, unless specified otherwise)env_modules
: list of strings with the names of environment modules to be loaded when runningjob_script
(this is equivalent to executingmodule load <module>
for each module before runningjob_script
).
In particular this example runs a Golang
binary, which prints 'Hello World!' unless an environment variable NAME
is defined in the local environment.
🛎️ Important: a job_script
without an extension is assumed to be a compiled binary and is run as such. This allows catena
to extend beyond scripting languages to compiled binaries
🛎️ Important: catena
attempts to be as language-agnostic as possible when it comes to what can be used for defining a Job
object such as SlurmJob
To set/unset environment variables in a bash shell:
// To set the NAME environment variable locally
$ export NAME='my name'
// To unset the NAME environment variable locally
$ unset NAME
Appending, Prepending and Replacing Local Environment Variables: env_extra
The example demonstrates the use of the env_extra
kwarg
in SlurmJob
, using 'Christopher' as the name. You can change this in the script to your own name.
There are a couple caveats with how the values in the env_extra
dict
are treated, where each keys are the name of the environment variables and the values are the corresponding values.
- To prepend your value to an existing value for a given environment variable append your value with
:
- To append your value to an existing value for a given environment variable prepend your value with
:
- To replace an existing value with your value for a given environment variable neither prepend or append your value with
:
📝Note: for (1) and (2) if the variable does not exist in your local environment than it will just set it to that default value.
📝Note: rich
is a great library for nicely printing things to the console. The inspect method
is used here to expose what the class looks like and what it contains once defined.
The code for this example is include in the repo at examples/0_simple_slurm_job/slurm_job1.py
along with example scripts of various languages in examples/scripts
.
Running the Example from the Cloned Repository
See a Jupyter Notebook code sample for this example here if you're not interested in runnning it yourself
📍 Move into the example directory and load anaconda3/2021.05
(or your favourite version, as long as python >= 3.6)
$ cd examples/0_simple_slurm_job/
$ module load anaconda3/2021.05
📍 Execute the code
// to view job object before submitting a job
$ python3 slurm_job1.py
// to view job object before and after submitting a job
$ python3 slurm_job1.py -s
📍 View results of job output
// View results of example
$ cat ~/go_hello_world.out
📝 Note: To run this script and have it submit a job, you should add the -s flag
e.g: python3 slurm_job1.py -s