Skip to content

Commit 294c163

Browse files
slurm
1 parent b9437d6 commit 294c163

3 files changed

Lines changed: 64 additions & 4 deletions

File tree

cybench/runs/slurm/benchmark_completion_lib.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ def walk_forward_complete(
304304
*,
305305
horizon_tag_value: str,
306306
repo_root: Path,
307+
base_seed: int = 42,
308+
total_repetitions: int | None = None,
307309
) -> tuple[bool, str]:
308310
run_dir = _latest_run(
309311
baselines_dir,
@@ -316,10 +318,20 @@ def walk_forward_complete(
316318
)
317319
if run_dir is None:
318320
return False, "no walk-forward run"
319-
seeds = discover_run_seeds(run_dir)
320-
if not seeds:
321+
existing = set(discover_run_seeds(run_dir))
322+
if not existing:
321323
return False, "no walk-forward predictions"
322-
for seed in seeds:
324+
if total_repetitions is not None:
325+
targets = target_walk_forward_seeds(
326+
base_seed=base_seed, total_repetitions=total_repetitions
327+
)
328+
missing = [seed for seed in targets if seed not in existing]
329+
if missing:
330+
return False, f"missing walk-forward seeds {missing} in {run_dir.name}"
331+
check_seeds = targets
332+
else:
333+
check_seeds = sorted(existing)
334+
for seed in check_seeds:
323335
try:
324336
load_pooled_predictions(run_dir, model_slug=job.model, seed=seed)
325337
except ValueError as exc:
@@ -336,6 +348,8 @@ def assess_job(
336348
data_dir: Path | None = None,
337349
min_year: int = DEFAULT_MIN_YEAR,
338350
max_year: int = DEFAULT_MAX_YEAR,
351+
wf_repetitions: int | None = None,
352+
wf_base_seed: int = 42,
339353
) -> JobAssessment:
340354
hz_tag = horizon_tag(horizon)
341355
years = load_yield_years(
@@ -362,7 +376,12 @@ def assess_job(
362376
baselines_dir, job, horizon_tag_value=hz_tag, repo_root=repo_root
363377
)
364378
wf_ok, wf_reason = walk_forward_complete(
365-
baselines_dir, job, horizon_tag_value=hz_tag, repo_root=repo_root
379+
baselines_dir,
380+
job,
381+
horizon_tag_value=hz_tag,
382+
repo_root=repo_root,
383+
base_seed=wf_base_seed,
384+
total_repetitions=wf_repetitions,
366385
)
367386
if not scr_ok:
368387
wf_reason = "waiting for screening"
@@ -385,6 +404,8 @@ def assess_manifest(
385404
horizon: str,
386405
repo_root: Path,
387406
data_dir: Path | None = None,
407+
wf_repetitions: int | None = None,
408+
wf_base_seed: int = 42,
388409
) -> list[JobAssessment]:
389410
return [
390411
assess_job(
@@ -393,6 +414,8 @@ def assess_manifest(
393414
horizon=horizon,
394415
repo_root=repo_root,
395416
data_dir=data_dir,
417+
wf_repetitions=wf_repetitions,
418+
wf_base_seed=wf_base_seed,
396419
)
397420
for job in jobs
398421
]

cybench/runs/slurm/orchestrate_benchmark_complete.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ def _process_batch(
272272
horizon=horizon,
273273
repo_root=_REPO_ROOT,
274274
data_dir=args.data_dir,
275+
wf_repetitions=args.repetitions,
275276
)
276277
retry_jobs = jobs_for_phase(assessments, args.phase, force_rerun=args.force_rerun)
277278

tests/runs/test_benchmark_completion.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,39 @@ def test_expand_walk_forward_gpu_per_seed(tmp_path: Path):
299299
assert sum(1 for line in lines if "lstm_lf" in line) == 4
300300
assert sum(1 for line in lines if "ridge" in line) == 1
301301
assert all("ridge" not in line or line.count(" ") == 6 for line in lines if "ridge" in line)
302+
303+
304+
def test_walk_forward_complete_requires_all_repetitions(tmp_path: Path):
305+
from cybench.runs.slurm.benchmark_completion_lib import (
306+
JobRow,
307+
walk_forward_complete,
308+
)
309+
310+
repo = tmp_path / "repo"
311+
baselines = tmp_path / "output" / "baselines_EL_early_v2"
312+
run_dir = baselines / "maize_EL_tst_lf_walk_forward_early_season_20260709_120000"
313+
pred = "adm_id,year,targets,preds\nEL-01,2019,10,9\n"
314+
for seed in (42, 43):
315+
d = run_dir / "2019" / str(seed)
316+
d.mkdir(parents=True)
317+
(d / "test_preds.csv").write_text(pred, encoding="utf-8")
318+
319+
job = JobRow("maize", "EL", "tst_lf", "torch", "yes", "no", "yes")
320+
ok_any, _ = walk_forward_complete(
321+
baselines,
322+
job,
323+
horizon_tag_value="early_season",
324+
repo_root=repo,
325+
)
326+
assert ok_any is True
327+
328+
ok_all, reason = walk_forward_complete(
329+
baselines,
330+
job,
331+
horizon_tag_value="early_season",
332+
repo_root=repo,
333+
total_repetitions=5,
334+
)
335+
assert ok_all is False
336+
assert "missing walk-forward seeds" in reason
337+
assert "[44, 45, 46]" in reason

0 commit comments

Comments
 (0)