|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Expand walk-forward GPU manifest rows to one SLURM task per seed.""" |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import argparse |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +from cybench.runs.slurm.benchmark_completion_lib import ( |
| 10 | + default_output_root, |
| 11 | + expand_walk_forward_manifest_lines, |
| 12 | + read_manifest, |
| 13 | + resolve_batch_dir, |
| 14 | +) |
| 15 | + |
| 16 | +_REPO_ROOT = Path(__file__).resolve().parents[3] |
| 17 | + |
| 18 | + |
| 19 | +def main(argv: list[str] | None = None) -> int: |
| 20 | + parser = argparse.ArgumentParser(description=__doc__) |
| 21 | + parser.add_argument("--input", type=Path, required=True) |
| 22 | + parser.add_argument("--output", type=Path, required=True) |
| 23 | + parser.add_argument("--batch", required=True, help="Hydra experiment.name / baselines folder") |
| 24 | + parser.add_argument("--horizon", default="eos") |
| 25 | + parser.add_argument("--repetitions", type=int, default=1) |
| 26 | + parser.add_argument("--base-seed", type=int, default=42) |
| 27 | + parser.add_argument("--resume", action="store_true") |
| 28 | + parser.add_argument( |
| 29 | + "--per-seed", |
| 30 | + action="store_true", |
| 31 | + help="Expand needs_gpu=yes rows to one line per seed (default for gpu manifests)", |
| 32 | + ) |
| 33 | + parser.add_argument("--output-root", type=Path) |
| 34 | + parser.add_argument("--repo-root", type=Path, default=_REPO_ROOT) |
| 35 | + args = parser.parse_args(argv) |
| 36 | + |
| 37 | + repo_root = args.repo_root.resolve() |
| 38 | + output_root = args.output_root or default_output_root(repo_root) |
| 39 | + baselines_dir, _ = resolve_batch_dir(output_root, args.batch) |
| 40 | + jobs = read_manifest(args.input.resolve()) |
| 41 | + lines = expand_walk_forward_manifest_lines( |
| 42 | + jobs, |
| 43 | + baselines_dir=baselines_dir, |
| 44 | + horizon=args.horizon, |
| 45 | + repo_root=repo_root, |
| 46 | + base_seed=args.base_seed, |
| 47 | + total_repetitions=args.repetitions, |
| 48 | + resume=args.resume, |
| 49 | + per_seed_for_gpu=args.per_seed, |
| 50 | + ) |
| 51 | + header = ( |
| 52 | + "# crop country model framework hp_search feature_design needs_gpu [seed]\n" |
| 53 | + "# GPU rows: one SLURM task per seed. CPU/naive: bundled (no seed column)." |
| 54 | + ) |
| 55 | + args.output.write_text( |
| 56 | + header + ("\n" + "\n".join(lines) if lines else "") + "\n", |
| 57 | + encoding="utf-8", |
| 58 | + ) |
| 59 | + print(f"[INFO] Expanded {len(jobs)} job(s) -> {len(lines)} SLURM task(s) -> {args.output}") |
| 60 | + return 0 |
| 61 | + |
| 62 | + |
| 63 | +if __name__ == "__main__": |
| 64 | + raise SystemExit(main()) |
0 commit comments