submit
ClusterSyncFailed ¶
JobSubmissionFailed ¶
SubmissionProgress ¶
Bases: Generic[JobSubmission]
Live, mutable tracking of one Submission's progress into becoming a Job.
Tracks a submission from before it's even synced (state="SYNCING", no job yet),
through submission (job known, state polled from sacct), to running and, possibly,
cancellation.
A single flat list of these -- covering every submission, on every cluster, for one
submit() call -- is all a live display needs to render the whole picture, from a plain
rich.Live table (see render_job_table below) up to, eventually, a table shared across
several concurrent submit/submit_first calls (rich.Live only supports one live region
per console, so that would fuse several such lists together instead of replacing this one).
- Reference CLI submit
Source code in cluv/cli/submit.py
render_job_table ¶
render_job_table(
cluster_to_job_submissions: dict[
str, list[SubmissionProgress]
],
*,
cancelling: bool = False,
) -> Table
Render the current state of every submission as a single table.
A plain rich.Live for now; the natural place to plug in a registry that fuses several
concurrent submit/submit_first calls' rows into one shared live region later on.
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,
chunking: int | None = None,
vram: str | None = None,
_skip_sync: bool = False,
sync_datasets: bool = True,
parsable: bool = False,
) -> Job | None
Submit a job to the given cluster (or all clusters if cluster=="first"),
and return the Job object if successful.
When vram is set, one job is submitted per GPU type of each cluster that has at least
that much VRAM (including MIG slices), racing them the same way as multiple allocations.
If parsable is True, print only the job ID (or 'cluster
is 'first') to stdout, for programmatic use, instead of the usual human-readable summary.
Everything else (logs, the live jobs table, command outputs) is silenced, as with --quiet.
Returns None if the submission failed.
Source code in cluv/cli/submit.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 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 | |
wait_for_first_running_job ¶
wait_for_first_running_job(
cluster_to_job_submissions: dict[
str, list[SubmissionProgress[Submission]]
],
*,
cluster_to_remote: dict[str, Remote | None],
found_running_job: Event,
_skip_sync: bool,
sync_datasets: bool,
initial_delay: int = 10,
max_wait_time_seconds: int = 60,
) -> SubmissionProgress[Job] | None
Poll sacct on each cluster until one submitted job starts running, or every submission has failed.
Mutates the job submissions in place with the latest known job id / state, so a live display
can render them at any point during this wait. Sets found_running_job the moment a job starts,
so that clusters which haven't submitted their own jobs yet can skip doing so.
Returns the submission for the job that started, or None if every submission ended up failing.
Source code in cluv/cli/submit.py
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 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 | |
wait_for_jobs_to_cancel ¶
wait_for_jobs_to_cancel(
job_submissions: list[SubmissionProgress[Job]],
cluster_to_remote: dict[str, Remote | None],
max_wait_time_seconds: int = 60,
initial_delay: int = 1,
) -> None
Cancel every (already-submitted) job in rows, and wait until they're all done.
Source code in cluv/cli/submit.py
run_scancel ¶
run_scancel(jobs: list[SubmissionProgress]) -> None
Cancel the (already-submitted) jobs behind rows, grouped by remote.
Source code in cluv/cli/submit.py
sync_and_submit_jobs_to_cluster ¶
sync_and_submit_jobs_to_cluster(
cluster: str,
remote: Remote | None,
job_submissions: list[SubmissionProgress[Submission]],
found_running_job: Event,
_skip_sync: bool = False,
sync_datasets: bool = True,
) -> list[SubmissionProgress[Job]]
Sync then submit every submission for one cluster, in parallel.
NOTE: This modifies the job submissions in-place.
Returns the job submissions that were successfully submitted and now have a job id.
Source code in cluv/cli/submit.py
get_submissions ¶
get_submissions(
cluster: str,
remote: Remote | None,
*,
job_script: Path | None,
sbatch_args: list[str],
program_args: list[str],
chunking: int | None,
git_commit: str,
vram: str | None = None,
) -> list[Submission]
Expand the possible job configurations for a cluster. Returns a list of Submission objects.
One Submission is produced per allocation configured for cluster (see
[tool.cluv.clusters.<name>].sbatch_args), times one per compatible GPU type when vram
is set (see expand_for_vram).
Does not do the actual job submission with sbatch.
Source code in cluv/cli/submit.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 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 | |
merge_sbatch_args ¶
Merge the sbatch args from the config and from the CLI, with CLI args taking precedence.
-t is normalized to time (its long-flag alias) as it's merged in, so --time=1:00:00
-t=2:00:00 -- config or CLI, either order -- resolves to a single time value (the last
one written) instead of leaving two separate keys for what's really the same sbatch option.
Source code in cluv/cli/submit.py
check_path_is_safe_to_interpolate ¶
check_path_is_safe_to_interpolate(
path: PurePosixPath | str, setting: str
) -> None
Raise a ValueError if path can't be interpolated into the sbatch command as-is.
Values that may contain environment variables are written into the command unquoted, so that
the cluster's login shell is the one that expands them (see get_sbatch_command). Escaping them
with shlex.quote first would stop exactly that, so anything else that shell treats specially
has to be rejected up front instead: a space would split the value into two sbatch arguments,
and a ; would end the command and start another one.
check_path_is_safe_to_interpolate("$SCRATCH/logs/imagenet", "results_path") check_path_is_safe_to_interpolate("/home/me/my logs", "results_path") ... # doctest: +ELLIPSIS Traceback (most recent call last): ... ValueError: The results_path '/home/me/my logs' contains a ' ', ...
Source code in cluv/cli/submit.py
add_cluv_sbatch_args ¶
add_cluv_sbatch_args(
sbatch_args: SbatchArgs,
job_script: Path,
cluster: str,
cluster_config: ClusterConfig,
) -> SbatchArgs
- Add the --output flag (So that outputs are created in the
results_pathfor the run prescribed by Cluv) - Add the --job-name flag (So that we can identify the cluv jobs later)
- Add the --export=ALL flag (since trillium and trillium-gpu apparently have
--export=Noneas default). - Add the --chdir flag to move to the project folder when running the command.
Returns a new dict; the one passed in is left alone.
Source code in cluv/cli/submit.py
get_sbatch_command ¶
get_sbatch_command(
job_script: PurePosixPath,
sbatch_args: SbatchArgs,
program_args: list[str],
env_vars: dict[str, str],
project_dir_on_cluster: PurePosixPath | None = None,
) -> str
Generate the command to submit the job via sbatch on the cluster.
Source code in cluv/cli/submit.py
submit_job ¶
submit_job(submission: Submission, log_path: Path) -> Job
Does the actual sbatch call, and writes its outcome to log_path.
Raise a JobSubmissionFailed if the job submission fails for some reason.
Source code in cluv/cli/submit.py
logging_commands_to ¶
Append the commands run in this context (and their outputs) to log_paths, as well as
the traceback of any exception raised.
Source code in cluv/cli/submit.py
write_submission_log ¶
write_submission_log(
log_path: Path,
*,
job_id: int | None,
error: str | None,
result: CompletedProcess[str],
) -> None
Append the outcome of one sbatch call to log_path, so it can be found on its own even
when many submissions' console output is interleaved.
Source code in cluv/cli/submit.py
build_submit_command ¶
build_submit_command(
cluster: str,
job_script: str | Path | PurePosixPath | None,
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.