From 981bece681a6b012448460ebac448ba14476c0fc Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 17 May 2024 15:19:33 -0500 Subject: [PATCH 1/5] Define dependencies in submission script --- pysqa/ext/modular.py | 3 ++- pysqa/utils/basic.py | 19 +++++++++---------- tests/config/flux/flux.sh | 5 +++++ tests/config/slurm/slurm.sh | 3 +++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pysqa/ext/modular.py b/pysqa/ext/modular.py index ef9ec83f..158797ba 100644 --- a/pysqa/ext/modular.py +++ b/pysqa/ext/modular.py @@ -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, diff --git a/pysqa/utils/basic.py b/pysqa/utils/basic.py index a88c4263..04a58747 100644 --- a/pysqa/utils/basic.py +++ b/pysqa/utils/basic.py @@ -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 @@ -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, @@ -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): """ @@ -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, ): @@ -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, ) @@ -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: @@ -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: @@ -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, ) diff --git a/tests/config/flux/flux.sh b/tests/config/flux/flux.sh index 928e3ba1..7f4bf39f 100644 --- a/tests/config/flux/flux.sh +++ b/tests/config/flux/flux.sh @@ -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}} \ No newline at end of file diff --git a/tests/config/slurm/slurm.sh b/tests/config/slurm/slurm.sh index e5bcdc04..1cb6188c 100644 --- a/tests/config/slurm/slurm.sh +++ b/tests/config/slurm/slurm.sh @@ -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 %} From 1611cab1e32f75a5a368735134404e1708f75bc1 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 17 May 2024 15:25:41 -0500 Subject: [PATCH 2/5] fix tests --- tests/test_gent.py | 4 ++-- tests/test_lsf.py | 4 ++-- tests/test_moab.py | 4 ++-- tests/test_sge.py | 4 ++-- tests/test_slurm.py | 12 +----------- tests/test_torque.py | 4 ++-- 6 files changed, 11 insertions(+), 21 deletions(-) diff --git a/tests/test_gent.py b/tests/test_gent.py index b4d5a5ec..6eaac329 100644 --- a/tests/test_gent.py +++ b/tests/test_gent.py @@ -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", diff --git a/tests/test_lsf.py b/tests/test_lsf.py index da1ca615..8dcf0251 100644 --- a/tests/test_lsf.py +++ b/tests/test_lsf.py @@ -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", diff --git a/tests/test_moab.py b/tests/test_moab.py index 303e9d9f..99c2020e 100644 --- a/tests/test_moab.py +++ b/tests/test_moab.py @@ -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"], ) diff --git a/tests/test_sge.py b/tests/test_sge.py index 9b1b53fc..99223208 100644 --- a/tests/test_sge.py +++ b/tests/test_sge.py @@ -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", diff --git a/tests/test_slurm.py b/tests/test_slurm.py index 7ae67f7c..d7b4f050 100644 --- a/tests/test_slurm.py +++ b/tests/test_slurm.py @@ -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: diff --git a/tests/test_torque.py b/tests/test_torque.py index cdbe1a5a..0a10d1a3 100644 --- a/tests/test_torque.py +++ b/tests/test_torque.py @@ -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", From 83fd7849e54a43bf76e0792e60488b1c6e527704 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 17 May 2024 15:30:13 -0500 Subject: [PATCH 3/5] update all tests --- tests/config/slurm/slurm_extra.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/config/slurm/slurm_extra.sh b/tests/config/slurm/slurm_extra.sh index f7f177d2..561a527b 100644 --- a/tests/config/slurm/slurm_extra.sh +++ b/tests/config/slurm/slurm_extra.sh @@ -13,6 +13,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 %} From 9ad4c811621e76be6b69d5e48e6bdaba6600242a Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 17 May 2024 15:32:35 -0500 Subject: [PATCH 4/5] fix space in flux submission script --- tests/config/flux/flux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/config/flux/flux.sh b/tests/config/flux/flux.sh index 7f4bf39f..4fa66c40 100644 --- a/tests/config/flux/flux.sh +++ b/tests/config/flux/flux.sh @@ -1,5 +1,5 @@ #!/bin/bash -# flux:--job-name={{job_name}} +# flux: --job-name={{job_name}} # flux: --env=CORES={{cores}} # flux: --output=time.out # flux: --error=error.out From 90941d437ce5a814adf1b23502cbef2d3b63e6c3 Mon Sep 17 00:00:00 2001 From: Jan Janssen Date: Fri, 17 May 2024 15:35:40 -0500 Subject: [PATCH 5/5] fix flux test --- tests/test_flux.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_flux.py b/tests/test_flux.py index 7b9ec5d4..5882018e 100644 --- a/tests/test_flux.py +++ b/tests/test_flux.py @@ -98,7 +98,7 @@ def execute_command( output = f.read() content = """\ #!/bin/bash -# flux:--job-name=test +# flux: --job-name=test # flux: --env=CORES=4 # flux: --output=time.out # flux: --error=error.out