Skip to content

Commit c6f6658

Browse files
authored
feat: Set tmpspace with help of gres="tmpspace:10G" syntax (#444)
Set tmpspace with help of gres="tmpspace:10G" syntax This is probably useful for only a few clusters [1], so the regex for the tmpspace is limited to tmpspace only. [1] at least on "UMC utrecht HPC" system <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * GRES specifications now accept optional size unit postfixes (T, G, M) appended to numeric values, e.g., gpu:10G or tmpspace:10M. Validation and error text updated to reflect the new accepted format. * **Tests** * Added unit test coverage verifying GRES entries with size unit postfixes (e.g., tmpspace:10G). <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent c4e3ec3 commit c6f6658

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

snakemake_executor_plugin_slurm/utils.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,9 @@ def set_gres_string(job: JobExecutorInterface) -> str:
251251
based on the resources requested in the job.
252252
"""
253253
# generic resources (GRES) arguments can be of type
254-
# "string:int" or "string:string:int"
255-
gres_re = re.compile(r"^[a-zA-Z0-9_]+(:[a-zA-Z0-9_\.]+)?:\d+$")
254+
# "string:int" or "string:string:int" with optional postfix 'T' or 'G' or 'M'
255+
gres_re = re.compile(r"^[a-zA-Z0-9_]+(:[a-zA-Z0-9_\.]+)?:\d+[TGM]?$")
256+
256257
# gpu model arguments can be of type "string"
257258
# The model string may contain a dot for variants, see
258259
# https://github.com/snakemake/snakemake-executor-plugin-slurm/issues/387
@@ -288,14 +289,16 @@ def set_gres_string(job: JobExecutorInterface) -> str:
288289
"GRES format should not be a nested string (start "
289290
"and end with ticks or quotation marks). "
290291
"Expected format: "
291-
"'<name>:<number>' or '<name>:<type>:<number>' "
292+
"'<name>:<number>' or '<name>:<type>:<number>' with an optional "
293+
"'T' 'M' or 'G' postfix "
292294
"(e.g., 'gpu:1' or 'gpu:tesla:2')"
293295
)
294296
else:
295297
raise WorkflowError(
296298
f"Invalid GRES format: {gres}. Expected format: "
297-
"'<name>:<number>' or '<name>:<type>:<number>' "
298-
"(e.g., 'gpu:1' or 'gpu:tesla:2')"
299+
"'<name>:<number>' or '<name>:<type>:<number>' with an optional "
300+
"'T' 'M' or 'G' postfix "
301+
"(e.g., 'gpu:1' or 'gpu:tesla:2') "
299302
)
300303
return f" --gres={job.resources.gres}"
301304

tests/tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,20 @@ def test_gpu_model_without_gpu(self, mock_job):
368368
):
369369
set_gres_string(job)
370370

371+
def test_tmpspace_gres_10G(self, mock_job):
372+
"""Test with valid GRES format (simple)."""
373+
job = mock_job(gres="tmpspace:10G")
374+
375+
# Patch subprocess.Popen to capture the sbatch command
376+
with patch("subprocess.Popen") as mock_popen:
377+
# Configure the mock to return successful submission
378+
process_mock = MagicMock()
379+
process_mock.communicate.return_value = ("123", "")
380+
process_mock.returncode = 0
381+
mock_popen.return_value = process_mock
382+
383+
assert set_gres_string(job) == " --gres=tmpspace:10G"
384+
371385
def test_both_gres_and_gpu_set(self, mock_job):
372386
"""Test error case when both GRES and GPU are specified."""
373387
job = mock_job(gres="gpu:1", gpu="2")

0 commit comments

Comments
 (0)