Skip to content

Commit cda0874

Browse files
authored
Merge pull request #166 from VOD555/slurm
Support Slurm in gromacs.qsub
2 parents d96c34f + 2dc8dda commit cda0874

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

gromacs/qsub.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def __repr__(self):
293293
QueuingSystem('Sun Gridengine', 'sge', '#$', array_variable='SGE_TASK_ID', array_option='-t %d-%d'),
294294
QueuingSystem('PBS', 'pbs', '#PBS', array_variable='PBS_ARRAY_INDEX', array_option='-J %d-%d'),
295295
QueuingSystem('LoadLeveler', 'll', '#@'), # no idea how to do arrays in LL
296+
QueuingSystem('Slurm', 'slu', '#SBATCH'), # will add array settings
296297
]
297298

298299
def detect_queuing_system(scriptfile):
@@ -365,19 +366,35 @@ def write_script(template):
365366
submitscript = os.path.join(dirname, prefix + os.path.basename(template))
366367
logger.info("Setting up queuing system script {submitscript!r}...".format(**vars()))
367368
# These substitution rules are documented for the user in the module doc string
368-
cbook.edit_txt(template,
369-
[('^ *DEFFNM=','(?<==)(.*)', deffnm),
370-
('^#.*(-N|job_name)', '((?<=-N\s)|(?<=job_name\s))\s*\w+', jobname),
371-
('^#.*(-A|account_no)', '((?<=-A\s)|(?<=account_no\s))\s*\w+', budget),
372-
('^#.*(-l walltime|wall_clock_limit)', '(?<==)(\d+:\d+:\d+)', walltime),
373-
('^ *WALL_HOURS=', '(?<==)(.*)', wall_hours),
374-
('^ *STARTDIR=', '(?<==)(.*)', startdir),
375-
('^ *NPME=', '(?<==)(.*)', npme),
376-
('^ *MDRUN_OPTS=', '(?<==)("")', mdrun_opts), # only replace literal ""
377-
('^# JOB_ARRAY_PLACEHOLDER', '^.*$', jobarray_string),
378-
],
379-
newname=submitscript)
380-
ext = os.path.splitext(submitscript)[1]
369+
qsystem = detect_queuing_system(template)
370+
if qsystem is not None and (qsystem.name == 'Slurm'):
371+
cbook.edit_txt(template,
372+
[('^ *DEFFNM=','(?<==)(.*)', deffnm),
373+
('^#.*(-J)', '((?<=-J\s))\s*\w+', jobname),
374+
('^#.*(-A|account_no)', '((?<=-A\s)|(?<=account_no\s))\s*\w+', budget),
375+
('^#.*(-t)', '(?<=-t\s)(\d+:\d+:\d+)', walltime),
376+
('^ *WALL_HOURS=', '(?<==)(.*)', wall_hours),
377+
('^ *STARTDIR=', '(?<==)(.*)', startdir),
378+
('^ *NPME=', '(?<==)(.*)', npme),
379+
('^ *MDRUN_OPTS=', '(?<==)("")', mdrun_opts), # only replace literal ""
380+
('^# JOB_ARRAY_PLACEHOLDER', '^.*$', jobarray_string),
381+
],
382+
newname=submitscript)
383+
ext = os.path.splitext(submitscript)[1]
384+
else:
385+
cbook.edit_txt(template,
386+
[('^ *DEFFNM=','(?<==)(.*)', deffnm),
387+
('^#.*(-N|job_name)', '((?<=-N\s)|(?<=job_name\s))\s*\w+', jobname),
388+
('^#.*(-A|account_no)', '((?<=-A\s)|(?<=account_no\s))\s*\w+', budget),
389+
('^#.*(-l walltime|wall_clock_limit)', '(?<==)(\d+:\d+:\d+)', walltime),
390+
('^ *WALL_HOURS=', '(?<==)(.*)', wall_hours),
391+
('^ *STARTDIR=', '(?<==)(.*)', startdir),
392+
('^ *NPME=', '(?<==)(.*)', npme),
393+
('^ *MDRUN_OPTS=', '(?<==)("")', mdrun_opts), # only replace literal ""
394+
('^# JOB_ARRAY_PLACEHOLDER', '^.*$', jobarray_string),
395+
],
396+
newname=submitscript)
397+
ext = os.path.splitext(submitscript)[1]
381398
if ext in ('.sh', '.csh', '.bash'):
382399
os.chmod(submitscript, 0o755)
383400
return submitscript
@@ -430,4 +447,3 @@ def write_script(template):
430447

431448
# must use config.get_templates() because we need to access the file for detecting
432449
return [write_script(template) for template in config.get_templates(templates)]
433-

gromacs/tests/test_qsub.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import gromacs.qsub
55

6-
def test_queuing_systems(known=("Sun Gridengine", "PBS", "LoadLeveler")):
6+
def test_queuing_systems(known=("Sun Gridengine", "PBS", "LoadLeveler", 'Slurm')):
77
assert len(gromacs.qsub.queuing_systems) == len(known)
88
for qs in gromacs.qsub.queuing_systems:
99
assert qs.name in known
@@ -18,7 +18,8 @@ def test_queuing_systems(known=("Sun Gridengine", "PBS", "LoadLeveler")):
1818
@pytest.mark.parametrize("scriptfile,name", [
1919
("foo.sge", "Sun Gridengine"),
2020
("foo.pbs", "PBS"),
21-
("foo.ll", "LoadLeveler")])
21+
("foo.ll", "LoadLeveler"),
22+
("foo.slu", "Slurm")])
2223
def test_detect_queuing_system(scriptfile, name):
2324
qs = gromacs.qsub.detect_queuing_system(scriptfile)
2425
assert qs.name == name

0 commit comments

Comments
 (0)