Skip to content

Commit

Permalink
Merge 1611cab into 52f60c4
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-janssen committed May 17, 2024
2 parents 52f60c4 + 1611cab commit dd2be9c
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 32 deletions.
3 changes: 2 additions & 1 deletion pysqa/ext/modular.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ def submit_job(
cores=cores,
memory_max=memory_max,
run_time_max=run_time_max,
dependency_list=dependency_list,
command=command,
**kwargs,
)
cluster_module = self._queue_to_cluster_dict[queue]
commands = self._switch_cluster_command(
cluster_module=cluster_module
) + self._list_command_to_be_executed(dependency_list, queue_script_path)
) + self._list_command_to_be_executed(queue_script_path=queue_script_path)
out = self._execute_command(
commands=commands,
working_directory=working_directory,
Expand Down
19 changes: 9 additions & 10 deletions pysqa/utils/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import importlib
import os
import re
from typing import Optional
from typing import Optional, List

import pandas
from jinja2 import Template
Expand Down Expand Up @@ -178,7 +178,7 @@ def submit_job(
)
out = self._execute_command(
commands=self._list_command_to_be_executed(
dependency_list, queue_script_path
queue_script_path=queue_script_path
),
working_directory=working_directory,
split_output=False,
Expand All @@ -188,14 +188,8 @@ def submit_job(
else:
return None

def _list_command_to_be_executed(
self, dependency_list: list[str], queue_script_path: str
) -> list:
return (
self._commands.submit_job_command
+ self._commands.dependencies(dependency_list)
+ [queue_script_path]
)
def _list_command_to_be_executed(self, queue_script_path: str) -> list:
return self._commands.submit_job_command + [queue_script_path]

def enable_reservation(self, process_id: int):
"""
Expand Down Expand Up @@ -354,6 +348,7 @@ def _write_queue_script(
cores: Optional[int] = None,
memory_max: Optional[int] = None,
run_time_max: Optional[int] = None,
dependency_list: Optional[List[int]] = None,
command: Optional[str] = None,
**kwargs,
):
Expand All @@ -380,6 +375,7 @@ def _write_queue_script(
cores=cores,
memory_max=memory_max,
run_time_max=run_time_max,
dependency_list=dependency_list,
command=command,
**kwargs,
)
Expand All @@ -398,6 +394,7 @@ def _job_submission_template(
cores: Optional[int] = None,
memory_max: Optional[int] = None,
run_time_max: Optional[int] = None,
dependency_list: Optional[List[int]] = None,
command: Optional[str] = None,
**kwargs,
) -> str:
Expand All @@ -410,6 +407,7 @@ def _job_submission_template(
cores (int/None):
memory_max (int/None):
run_time_max (int/None):
dependency_list (list/None):
command (str/None):
Returns:
Expand Down Expand Up @@ -441,6 +439,7 @@ def _job_submission_template(
memory_max=memory_max,
run_time_max=run_time_max,
command=command,
dependency_list=dependency_list,
**kwargs,
)

Expand Down
5 changes: 5 additions & 0 deletions tests/config/flux/flux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
{%- if run_time_max %}
# flux: -t {{ [1, run_time_max // 60]|max }}
{%- endif %}
{%- if dependency %}
{%- for jobid in dependency %}
# flux: --dependency=afterok:{{jobid}}
{%- endfor %}
{%- endif %}

{{command}}
3 changes: 3 additions & 0 deletions tests/config/slurm/slurm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
{%- if run_time_max %}
#SBATCH --time={{ [1, run_time_max // 60]|max }}
{%- endif %}
{%- if dependency %}
#SBATCH --dependency=afterok:{{ dependency | join(',') }}
{%- endif %}
{%- if memory_max %}
#SBATCH --mem={{memory_max}}G
{%- endif %}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_gent.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("gent"):
self.assertEqual(
self.gent._adapter._list_command_to_be_executed(None, "here"),
self.gent._adapter._list_command_to_be_executed("here"),
["sbatch", "--parsable", "here"],
)
with self.subTest("gent with dependency"):
self.assertRaises(
NotImplementedError,
TypeError,
self.gent._adapter._list_command_to_be_executed,
[],
"here",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("lsf"):
self.assertEqual(
self.lsf._adapter._list_command_to_be_executed(None, "here"),
self.lsf._adapter._list_command_to_be_executed("here"),
["bsub", "here"],
)
with self.subTest("lsf with dependency"):
self.assertRaises(
NotImplementedError,
TypeError,
self.lsf._adapter._list_command_to_be_executed,
[],
"here",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_moab.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("moab with dependency"):
self.assertRaises(
NotImplementedError,
TypeError,
self.moab._adapter._list_command_to_be_executed,
[],
"here",
)
with self.subTest("moab"):
self.assertEqual(
self.moab._adapter._list_command_to_be_executed(None, "here"),
self.moab._adapter._list_command_to_be_executed("here"),
["msub", "here"],
)
4 changes: 2 additions & 2 deletions tests/test_sge.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("sge"):
self.assertEqual(
self.sge._adapter._list_command_to_be_executed(None, "here"),
self.sge._adapter._list_command_to_be_executed("here"),
["qsub", "-terse", "here"],
)
with self.subTest("sge with dependency"):
self.assertRaises(
NotImplementedError,
TypeError,
self.sge._adapter._list_command_to_be_executed,
[],
"here",
Expand Down
12 changes: 1 addition & 11 deletions tests/test_slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,9 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("slurm"):
self.assertEqual(
self.slurm._adapter._list_command_to_be_executed(None, "here"),
self.slurm._adapter._list_command_to_be_executed("here"),
["sbatch", "--parsable", "here"],
)
with self.subTest("slurm with one dependency"):
self.assertEqual(
self.slurm._adapter._list_command_to_be_executed(["2"], "here"),
["sbatch", "--parsable", "--dependency=afterok:2", "here"],
)
with self.subTest("slurm with two dependencies"):
self.assertEqual(
self.slurm._adapter._list_command_to_be_executed(["2", "34"], "here"),
["sbatch", "--parsable", "--dependency=afterok:2,34", "here"],
)

def test_convert_queue_status_slurm(self):
with open(os.path.join(self.path, "config/slurm", "squeue_output"), "r") as f:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_torque.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def test_interfaces(self):
def test__list_command_to_be_executed(self):
with self.subTest("torque"):
self.assertEqual(
self.torque._adapter._list_command_to_be_executed(None, "here"),
self.torque._adapter._list_command_to_be_executed("here"),
["qsub", "here"],
)
with self.subTest("torque with dependency"):
self.assertRaises(
NotImplementedError,
TypeError,
self.torque._adapter._list_command_to_be_executed,
[],
"here",
Expand Down

0 comments on commit dd2be9c

Please sign in to comment.