Frozen Slurm launch plans¶
trade_study.slurm
¶
Frozen Python task submission and node packing for existing study runners.
Adapted from the FLU_USA, denv-ade-v2 and mcvf frozen-worktree/packing scripts. Tasks are explicit Python argv lists; no live evaluators are pickled. Existing grid ledgers and adaptive journals remain responsible for within-task recovery.
FrozenCheckout(path, commit)
dataclass
¶
A detached checkout's location and full commit identity.
Construction alone does not verify files. verify checks the current
commit and tracked worktree/index before submission and each task boundary.
Keep data, logs, virtual environments and outputs outside the tracked tree.
verify()
¶
Refuse a moved commit or modified tracked source/index.
Raises:
| Type | Description |
|---|---|
ValueError
|
The current commit or tracked source differs. |
Source code in src/trade_study/slurm.py
SlurmResources(width=1, cpus_per_task=1, time_limit='01:00:00', memory=None, partition=None, account=None)
dataclass
¶
One node's CPU packing and site-specific submission choices.
width * cpus_per_task CPUs are requested in one allocation. Child tasks
share that allocation's CPU set; no per-child CPU affinity is imposed.
Memory and wall time apply to the whole allocation, rather than each child.
Examples:
>>> resource = SlurmResources(width=4, cpus_per_task=2)
>>> resource.width * resource.cpus_per_task
8
__post_init__()
¶
Reject invalid packing sizes and malformed resource tokens.
Raises:
| Type | Description |
|---|---|
ValueError
|
Counts are not positive integers or a token is invalid. |
Source code in src/trade_study/slurm.py
SlurmTask(args, outputs=())
dataclass
¶
One Python argv vector and optional declared output files.
Output paths are absolute and outside the frozen checkout. Completion receipts hash these files. Missing files cause reevaluation; changed content is refused. Without declared outputs, a receipt attests successful exit only.
__post_init__()
¶
Validate immutable task arguments and explicit output locations.
Raises:
| Type | Description |
|---|---|
ValueError
|
Arguments or output paths do not meet the task contract. |
Source code in src/trade_study/slurm.py
SlurmPlan(path, identity)
dataclass
¶
A reviewed launch manifest and its independently retained content identity.
submit explicitly launches a batch job. run_local exercises packing
without a scheduler. Both refuse changed source/runtime and reuse only task
completions matching this exact plan. Keep the output directory unchanged.
run_local()
¶
Run the same guarded pack locally, propagating any child failure.
Native child failures raise subprocess.CalledProcessError.
Raises:
| Type | Description |
|---|---|
ValueError
|
Plan, launcher, source or runtime differs. |
Source code in src/trade_study/slurm.py
submit(*, after=())
¶
Submit one packed job, checking finished dependencies before afterok.
Scheduler errors propagate as subprocess.CalledProcessError; failed
submission commands are not silently retried.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
after
|
Sequence[str]
|
Numeric job IDs on the connected Slurm cluster. Active jobs become afterok dependencies; confirmed successful jobs are omitted. |
()
|
Returns:
| Type | Description |
|---|---|
str
|
Native parsable sbatch job reference, retaining any cluster suffix. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Plan/source/runtime or dependency status is incompatible. |
Source code in src/trade_study/slurm.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
freeze_checkout(repository, destination, *, ref='HEAD')
¶
Create or reuse a detached worktree at an explicitly resolved commit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repository
|
str | Path
|
Existing local Git repository; no fetch or branch change occurs. |
required |
destination
|
str | Path
|
New worktree location, or the same previously frozen checkout. |
required |
ref
|
str
|
Commit or ref resolved once, before any job is submitted. |
'HEAD'
|
Returns:
| Type | Description |
|---|---|
FrozenCheckout
|
Verified full-commit checkout. Queued jobs do not read the submitter's tree. |
Git errors propagate as subprocess.CalledProcessError; verification
raises ValueError for a moved commit or changed tracked source.
Source code in src/trade_study/slurm.py
prepare_slurm_plan(checkout, tasks, *, directory, revision, imports, python=sys.executable, resources=None)
¶
Freeze explicit Python task argv, runtime, code and external-data revision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkout
|
FrozenCheckout
|
Detached worktree created by |
required |
tasks
|
Sequence[SlurmTask]
|
Ordered tasks, e.g. |
required |
directory
|
str | Path
|
Plan/log/completion directory outside the frozen source tree. |
required |
revision
|
str
|
Nonempty caller-managed identity for external data, configuration and environment behavior not captured by commits/package versions. |
required |
imports
|
Sequence[str]
|
Project modules whose tracked import origins must be in the frozen checkout; at least one guard is required. |
required |
python
|
str | Path
|
Exact shared interpreter path, preserving virtualenv symlinks. |
executable
|
resources
|
SlurmResources | None
|
Single-node CPU packing and site-specific Slurm choices. |
None
|
Returns:
| Type | Description |
|---|---|
SlurmPlan
|
Immutable plan that can be reviewed, run locally, or explicitly submitted. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Commands, revision, imports, source, runtime or reuse are invalid. |