submit
sbatch_args_from_dict
Convert a dict of sbatch options to a list of command-line flags.
Key-to-flag conversion:
- multi-char key + non-empty string value →
--key=value - single-char key + non-empty string value →
-k value(two separate args) - any key +
True→ bare flag (--keyor-k) - any key +
""orFalse→ omitted entirely
sbatch_args_from_dict({"time": "2:00:00", "gpus": "1"}) ['--time=2:00:00', '--gpus=1'] sbatch_args_from_dict({"exclusive": True}) ['--exclusive'] sbatch_args_from_dict({"N": "2"}) ['-N', '2'] sbatch_args_from_dict({"gpus": "", "requeue": False}) [] sbatch_args_from_dict({"n": True}) ['-n']
Source code in cluv/cli/submit.py
submit
submit(
cluster: str,
job_script: Path | None,
sbatch_args: list[str],
program_args: list[str],
autocommit: bool = False,
_skip_sync: bool = False,
) -> Job | None
Submit a SLURM job on a remote cluster.
Enforces a clean git state, syncs the project, sets GIT_COMMIT and any
environment variables configured in [tool.cluv.env] / [tool.cluv.clusters.<name>.env],
then calls sbatch on the remote.
sbatch_args are forwarded as flags to sbatch; program_args are passed to
the job script.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cluster
|
str
|
SSH hostname of the target cluster. Can be set to "first" to launch the job on all clusters and keep only the first one to starts. |
required |
job_script
|
Path | None
|
Path to the job script to submit, relative to the project root. When omitted, uses the configured default for the target cluster. |
required |
sbatch_args
|
list[str]
|
List of additional flags to pass to |
required |
program_args
|
list[str]
|
List of arguments to pass to the job script, for example |
required |
autocommit
|
bool
|
If True, automatically create a local commit with tracked changes before submitting. |
False
|
_skip_sync
|
bool
|
If True, skip the synchronization step before submitting. |
False
|
Returns:
| Type | Description |
|---|---|
Job | None
|
The job ID of the submitted job or None if the sbatch command fails. |
Examples:
submit(
"mila",
"scripts/job.sh",
sbatch_args=["--time=00:00:10"],
program_args=["python", "--version"],
)
Source code in cluv/cli/submit.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
submit_first
submit_first(
job_script: Path | None,
sbatch_args: list[str],
program_args: list[str],
git_commit: str,
_skip_sync: bool = False,
) -> Job | None
Submit the job on all clusters, and wait until one of them starts. Once one starts, cancel the others.
Source code in cluv/cli/submit.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
wait_for_running_job
wait_for_running_job(
cluster_and_jobid_to_jobstate: dict[
tuple[str, int], str
],
cluster_to_remote: dict[str, Remote | None],
max_wait_time_seconds: int = 60,
) -> JobHandle | None
Watch the jobs with sacct until one of them starts (or completes).
Source code in cluv/cli/submit.py
build_submit_command
build_submit_command(
cluster: str,
job_script: str | Path | PurePosixPath,
sbatch_args: list[str],
program_args: list[str],
) -> str
Build the local cluv submit command line used to launch the job.
Source code in cluv/cli/submit.py
create_submit_commit
create_submit_commit(submit_command: str) -> None
Create a commit with tracked changes and include the launched job command in the body.
Source code in cluv/cli/submit.py
ensure_clean_git_state
Check git is clean locally and return the current commit hash.
Source code in cluv/cli/submit.py
get_sbatch_command
get_sbatch_command(
cluster: str,
job_script: Path,
sbatch_args: list[str],
program_args: list[str],
git_commit: str,
) -> str
Generate the command to submit the job via sbatch on the remote cluster, with the appropriate env vars set.
Source code in cluv/cli/submit.py
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 | |
sbatch
sbatch(
remote: Remote | None,
job_script: Path,
sbatch_args: list[str],
program_args: list[str],
git_commit: str,
) -> CompletedProcess[str]
Submit the job via sbatch on the remote cluster, and return the job id.
Source code in cluv/cli/submit.py
cancel_job
Cancel the job with the given id on the remote cluster.