Skip to content

Commit f6f9172

Browse files
bvanessenPeggy-Li
andauthored
Add --time-limit and --dependency (#48)
* Added support for setting the job time limit from the CLI as well as the jobs dependency. * Fix to pass through dependency arg * Fixed the matrix specific launch args to only be on run commands. Added support for dependency chaining from the CLI. * Added support for providing the job-name field from the CLI. * Removed unused file. --------- Co-authored-by: Peggy Li <li54@llnl.gov>
1 parent 1bc17de commit f6f9172

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

hpc_launcher/cli/common_args.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@ def setup_arguments(parser: argparse.ArgumentParser):
9191

9292
group.add_argument("-q", "--queue", default=None, help="Specifies the queue to use")
9393

94+
group.add_argument(
95+
"-t",
96+
"--time-limit",
97+
type=int,
98+
default=None,
99+
help="Set a time limit for the job in minutes",
100+
)
101+
94102
# Constraints
95103
group.add_argument(
96104
"-g",
@@ -225,6 +233,19 @@ def setup_arguments(parser: argparse.ArgumentParser):
225233
help="Specify the account (or bank) to use fo the job",
226234
)
227235

236+
group.add_argument(
237+
"--dependency",
238+
default=None,
239+
help="Specify a scheduler dependency of the submitted job.",
240+
)
241+
242+
group.add_argument(
243+
"-J",
244+
"--job-name",
245+
default=None,
246+
help="Specify a name to use fo the job",
247+
)
248+
228249
group.add_argument(
229250
"--reservation",
230251
default=None,

hpc_launcher/schedulers/flux.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,27 @@ def build_scheduler_specific_arguments(
7373
self.common_launch_args['--env=LD_PRELOAD'] = f'{",".join(self.ld_preloads)}'
7474

7575
if self.time_limit is not None:
76-
self.common_launch_args["--time"] = f"{self.time_limit}m"
76+
if blocking:
77+
self.common_launch_args["--time"] = f"{self.time_limit}m"
78+
else:
79+
self.submit_only_args["--time"] = f"{self.time_limit}m"
80+
81+
if self.dependency is not None:
82+
self.common_launch_args["--dependency"] = f"{self.dependency}"
83+
dependency = self.common_launch_args.get('--dependency', None)
84+
if self.override_launch_args and self.override_launch_args.get('--dependency', None):
85+
dependency = self.override_launch_args['--dependency']
86+
if dependency and not blocking:
87+
try:
88+
del self.common_launch_args['--dependency']
89+
except KeyError:
90+
pass
91+
try:
92+
if self.override_launch_args:
93+
del self.override_launch_args['--dependency']
94+
except KeyError:
95+
pass
96+
self.submit_only_args["--dependency"] = dependency
7797

7898
if self.job_name:
7999
self.common_launch_args["--job-name"] = f"{self.job_name}"

hpc_launcher/schedulers/scheduler.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class Scheduler:
6666
account: Optional[str] = None
6767
# The reservation to use for the scheduler
6868
reservation: Optional[str] = None
69+
# Dependency str
70+
dependency: Optional[str] = None
6971
# Hijack preload commands into a scheduler
7072
ld_preloads: Optional[list[str]] = None
7173
# Capture the original command so that it can be added to the launch script
@@ -88,6 +90,7 @@ def build_scheduler_specific_arguments(
8890

8991
def build_command_string_and_batch_script(
9092
self, system: "System", blocking: bool = True, cli_env_only: bool = False,
93+
for_launch_cmd: bool = True,
9194
) -> (str, list[str]):
9295
"""
9396
Returns the strings used for a launch command as well as a batch script
@@ -98,6 +101,7 @@ def build_command_string_and_batch_script(
98101
:param system: The system to use.
99102
:param blocking: Is the job interactive of blocking
100103
:param cli_env_only: Append environment variables to CLI not a launch script
104+
:param for_launch_cmd: Some args should not be in both the header and launch cmnd. Ex: flux --dependency=afterany:XXX
101105
:return: A tuple of (shell script as a string, list of command-line arguments).
102106
"""
103107
env_vars = system.environment_variables()
@@ -149,11 +153,15 @@ def build_command_string_and_batch_script(
149153
if not blocking: # Only add batch script header items on non-blocking calls
150154
prefix = self.batch_script_prefix()
151155
for k,v in self.submit_only_args.items():
156+
if not for_launch_cmd and k == '--dependency':
157+
continue
152158
if not v:
153159
header.write(f"{prefix} {k}\n")
154160
else:
155161
header.write(f"{prefix} {k}={v}\n")
156162
for k,v in self.common_launch_args.items():
163+
if not for_launch_cmd and k == '--dependency':
164+
continue
157165
if not v:
158166
header.write(f"{prefix} {k}\n")
159167
else:
@@ -300,7 +308,7 @@ def launcher_script(
300308
script = ""
301309
# Launch command only use the cmd_args to construct the shell script to be launched
302310
(header_lines, cmd_args) = self.build_command_string_and_batch_script(
303-
system, blocking, False,
311+
system, blocking, False, for_launch_cmd=False
304312
)
305313
# For batch jobs add any common args to the internal command
306314
if not blocking:

hpc_launcher/schedulers/slurm.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ def build_scheduler_specific_arguments(
8383
if self.time_limit is not None:
8484
self.common_launch_args["--time"] = f"{_time_string(self.time_limit)}"
8585

86+
if self.dependency is not None:
87+
self.common_launch_args["--dependency"] = f"{self.dependency}"
88+
dependency = self.common_launch_args.get('--dependency', None)
89+
if self.override_launch_args and self.override_launch_args.get('--dependency', None):
90+
dependency = self.override_launch_args['--dependency']
91+
if dependency and not blocking:
92+
try:
93+
del self.common_launch_args['--dependency']
94+
except KeyError:
95+
pass
96+
try:
97+
if self.override_launch_args:
98+
del self.override_launch_args['--dependency']
99+
except KeyError:
100+
pass
101+
self.submit_only_args["--dependency"] = dependency
102+
86103
if self.job_name:
87104
self.common_launch_args["--job-name"] = f"{self.job_name}"
88105

hpc_launcher/systems/lc/cts2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def environment_variables(self) -> list[tuple[str, str]]:
5959

6060
def customize_scheduler(self, scheduler):
6161
if self.system_name == "matrix" and type(scheduler) is SlurmScheduler:
62-
scheduler.common_launch_args["--mpibind"] = "off"
63-
scheduler.common_launch_args["--gpu-bind"] = "none"
62+
scheduler.run_only_args["--mpibind"] = "off"
63+
scheduler.run_only_args["--gpu-bind"] = "none"
6464

6565
return
6666

0 commit comments

Comments
 (0)