Skip to content

Commit 7361062

Browse files
fix: set slurm walltime & memory usage (#116)
* feat: set slurm walltime & memory usage * docs: walltime & memory * test: update test_use_template() with new walltime & memory keys
1 parent 9d4da18 commit 7361062

5 files changed

Lines changed: 17 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- Fixes for `ccbr_tools install`: (#98, @kelly-sovacool)
44
- Correct installation method for `spacesavers2`.
55
- Change symlink permissions so group members can edit them.
6+
- Allow nextflow pipelines to specify walltime & memory usage for the slurm submission template. (#116, @kelly-sovacool)
67

78
## Tools 0.4.3
89

src/ccbr_tools/pipeline/nextflow.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def run(
3636
debug=False,
3737
hpc=get_hpc(),
3838
hpc_modules="nextflow",
39+
hpc_walltime="1-00:00:00",
40+
hpc_memory="1G",
3941
):
4042
"""
4143
Runs a Nextflow workflow with support for local or SLURM (HPC) execution modes.
@@ -49,6 +51,8 @@ def run(
4951
debug (bool, optional): If True, prints commands without executing them. Defaults to False.
5052
hpc (object, optional): HPC environment object, used for SLURM execution and module loading. Defaults to result of `~ccbr_tools.pipeline.hpc.get_hpc()`.
5153
hpc_modules (str, optional): Name(s) of modules to load for Nextflow execution on HPC. Defaults to "nextflow".
54+
hpc_walltime (str, optional): Walltime for SLURM job submission. Defaults to "1-00:00:00".
55+
hpc_memory (str, optional): Memory allocation for SLURM job submission. Defaults to "1G".
5256
5357
Behavior:
5458
- Constructs the Nextflow command with appropriate arguments and profiles.
@@ -116,7 +120,10 @@ def run(
116120
if mode == "slurm":
117121
slurm_filename = "submit_slurm.sh"
118122
use_template(
119-
"submit_slurm.sh",
123+
slurm_filename,
124+
output_filepath=slurm_filename,
125+
MEMORY=hpc_memory,
126+
WALLTIME=hpc_walltime,
120127
PIPELINE=pipeline_name,
121128
MODULES=hpc_modules,
122129
ENV_VARS="\n".join(

src/ccbr_tools/templates/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def use_template(template_name, output_filepath=None, **kwargs: str):
6868
IOError: If there is an error writing the output file.
6969
7070
Examples:
71-
>>> use_template("submit_slurm.sh", output_filepath="./submit_slurm.sh", PIPELINE="CCBR_nxf", MODULES="ccbrpipeliner nextflow", ENV_VARS="", RUN_COMMAND="nextflow run main.nf -stub")
71+
>>> use_template("submit_slurm.sh", output_filepath="./submit_slurm.sh", MEMORY='1G', WALLTIME="1-00:00:00", PIPELINE="CCBR_nxf", MODULES="ccbrpipeliner nextflow", ENV_VARS="", RUN_COMMAND="nextflow run main.nf -stub")
7272
"""
7373
template_str = read_template(template_name)
7474
if not output_filepath:

src/ccbr_tools/templates/submit_slurm.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
#SBATCH --cpus-per-task=1
3-
#SBATCH --mem=1g
4-
#SBATCH --time=1-00:00:00
3+
#SBATCH --mem={MEMORY}
4+
#SBATCH --time={WALLTIME}
55
#SBATCH --parsable
66
#SBATCH -J "{PIPELINE}"
77
#SBATCH --mail-type=BEGIN,END,FAIL

tests/test_templates.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def test_use_template():
2323
use_template(
2424
"submit_slurm.sh",
2525
output_filepath=out_filepath,
26+
WALLTIME="4-00:00:00",
27+
MEMORY="1G",
2628
PIPELINE="CCBR_nxf",
2729
MODULES="ccbrpipeliner nextflow",
2830
ENV_VARS="export HELLO=WORLD",
@@ -32,6 +34,7 @@ def test_use_template():
3234
template_str = outfile.read()
3335
assertions = [
3436
'#SBATCH -J "CCBR_nxf"' in template_str,
37+
"#SBATCH --time=4-00:00:00" in template_str,
3538
"module load ccbrpipeliner nextflow" in template_str,
3639
"export HELLO=WORLD" in template_str,
3740
"nextflow run main.nf -stub" in template_str,
@@ -44,6 +47,8 @@ def generate_slurm_template():
4447
use_template(
4548
"submit_slurm.sh",
4649
output_filepath="tests/data/templates/submit_slurm.sh",
50+
WALLTIME="1-00:00:00",
51+
MEMORY="1G",
4752
PIPELINE="CCBR_nxf",
4853
MODULES=hpc.modules["nxf"],
4954
ENV_VARS=hpc.env_vars,

0 commit comments

Comments
 (0)