File size: 24,643 Bytes
828bff4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 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 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 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 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 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 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 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 665 666 | #!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import math
import os
import statistics
import subprocess
from collections import Counter
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Any
DEFAULT_OBJECTIVE = "transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1"
BEST_CLEAN_SUMMARY = (
"h16_transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_summary.json"
)
BEST_CLEAN_SUCCESS = 0.3889855072463768
SOURCE_SCORE_MAP = "manifests/source_score_bonus_pick001_stack005.json"
DATASET = "/scratch/{user}/dovla/experiments/six_task_h16_collection"
RUN_ROOT = "/scratch/{user}/dovla/experiments/dovla_h16_policy_ckpt_runs"
EXCLUDE_TYPES = (
"residual_random_negative:"
"residual_wrong_direction:"
"residual_near_miss+residual_no_op:"
"residual_no_op+residual_wrong_gripper"
)
@dataclass(frozen=True)
class V1Config:
key: str
label: str
out_name: str
summary_tag: str
anchor: str
advantage_weight: float
min_source_advantage: float = -1.0e9
candidate_oracle_rollouts: int = 0
INITIAL_CONFIGS = (
V1Config(
key="advw1p0",
label="Generator V1 utility-weighted tangents, expert anchor, advantage weight 1.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw1p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw1p0"
),
anchor="expert",
advantage_weight=1.0,
),
V1Config(
key="advw2p0",
label="Generator V1 utility-weighted tangents, expert anchor, advantage weight 2.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw2p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw2p0"
),
anchor="expert",
advantage_weight=2.0,
),
V1Config(
key="policyanchor_advw2p0",
label="Generator V1 positive tangents, policy anchor, advantage weight 2.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw2p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw2p0"
),
anchor="policy",
advantage_weight=2.0,
),
)
NEXT_SWEEP_CONFIGS = (
V1Config(
key="advw0p5",
label="Generator V1 utility-weighted tangents, expert anchor, advantage weight 0.5",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw0p5.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw0p5"
),
anchor="expert",
advantage_weight=0.5,
),
V1Config(
key="advw4p0",
label="Generator V1 utility-weighted tangents, expert anchor, advantage weight 4.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw4p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw4p0"
),
anchor="expert",
advantage_weight=4.0,
),
V1Config(
key="policyanchor_advw1p0",
label="Generator V1 positive tangents, policy anchor, advantage weight 1.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw1p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw1p0"
),
anchor="policy",
advantage_weight=1.0,
),
V1Config(
key="policyanchor_advw4p0",
label="Generator V1 positive tangents, policy anchor, advantage weight 4.0",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw4p0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw4p0"
),
anchor="policy",
advantage_weight=4.0,
),
V1Config(
key="advw2p0_gate0",
label="Generator V1 utility-weighted tangents, expert anchor, positive-source gate",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw2p0_gate0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_advw2p0_gate0"
),
anchor="expert",
advantage_weight=2.0,
min_source_advantage=0.0,
),
V1Config(
key="policyanchor_advw2p0_gate0",
label="Generator V1 positive tangents, policy anchor, positive-source gate",
out_name=(
"policy_rollout_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw2p0_gate0.json"
),
summary_tag=(
"transport_field_reground_fieldonly_k6clean_dropnoopwg_b12_v1_"
"besttransport_margin0p00_k6_srcscore_task_pick001_stack005_policyanchor_advw2p0_gate0"
),
anchor="policy",
advantage_weight=2.0,
min_source_advantage=0.0,
),
)
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--project-dir", type=Path, default=Path.cwd())
parser.add_argument("--run-root", type=Path, default=None)
parser.add_argument("--dataset", type=Path, default=None)
parser.add_argument("--objective", default=DEFAULT_OBJECTIVE)
parser.add_argument("--results-dir", type=Path, default=Path("results"))
parser.add_argument("--submit-next", action="store_true")
parser.add_argument("--dry-run", action="store_true")
parser.add_argument("--round", type=int, default=int(os.environ.get("ADVANCE_ROUND", "0")))
args = parser.parse_args()
user = os.environ.get("USER", "knguy52")
run_root = args.run_root or Path(RUN_ROOT.format(user=user))
dataset = args.dataset or Path(DATASET.format(user=user))
project_dir = args.project_dir.resolve()
results_dir = args.results_dir
results_dir.mkdir(parents=True, exist_ok=True)
summaries = [
_summarize_config(config, run_root=run_root, objective=args.objective, results_dir=results_dir)
for config in INITIAL_CONFIGS
]
baseline_success = _baseline_success(results_dir)
complete = [item for item in summaries if item["num_completed"] == 3]
best = max(complete, key=lambda item: float(item["mean_success"]), default=None)
decision = _decision_payload(
summaries,
best=best,
baseline_success=baseline_success,
round_index=args.round,
)
decision_path = results_dir / "v1_generator_decision.json"
decision_md_path = results_dir / "v1_generator_decision.md"
decision_path.write_text(json.dumps(decision, indent=2))
decision_md_path.write_text(_render_decision_markdown(decision))
if complete:
_run_build_paper_analysis(project_dir, dry_run=args.dry_run)
if args.submit_next and not decision["complete"]:
submitted_missing = _maybe_resubmit_missing(
summaries,
INITIAL_CONFIGS,
project_dir=project_dir,
run_root=run_root,
dataset=dataset,
objective=args.objective,
dry_run=args.dry_run,
)
decision["submitted_missing"] = submitted_missing
decision_path.write_text(json.dumps(decision, indent=2))
decision_md_path.write_text(_render_decision_markdown(decision))
elif args.submit_next and complete:
submitted = _maybe_submit_next(
decision,
project_dir=project_dir,
run_root=run_root,
dataset=dataset,
objective=args.objective,
dry_run=args.dry_run,
)
decision["submitted"] = submitted
decision_path.write_text(json.dumps(decision, indent=2))
decision_md_path.write_text(_render_decision_markdown(decision))
print(json.dumps(decision, indent=2))
return 0
def _load_json(path: Path) -> dict[str, Any]:
return json.loads(path.read_text())
def _mean(values: list[float]) -> float:
return statistics.mean(values) if values else 0.0
def _std(values: list[float]) -> float:
return statistics.stdev(values) if len(values) > 1 else 0.0
def _baseline_success(results_dir: Path) -> float:
path = results_dir / BEST_CLEAN_SUMMARY
if path.exists():
value = _load_json(path).get("mean_success")
if isinstance(value, (int, float)) and math.isfinite(float(value)):
return float(value)
return BEST_CLEAN_SUCCESS
def _summarize_config(
config: V1Config,
*,
run_root: Path,
objective: str,
results_dir: Path,
) -> dict[str, Any]:
rows = []
base_dir = run_root / objective
for result_path in sorted(base_dir.glob(f"seed_*/{config.out_name}")):
raw = _load_json(result_path)
seed = int(result_path.parent.name.split("_")[-1])
selected_scale_counts = Counter(
str(row.get("selected_residual_scale"))
for row in raw.get("rows", [])
if row.get("selected_residual_scale") is not None
)
rows.append(
{
"seed": seed,
"path": str(result_path),
"num_groups": raw.get("num_groups", 0),
"selection_mode": raw.get("selection_mode"),
"num_candidates": raw.get("num_candidates"),
"candidate_sigma": raw.get("candidate_sigma", 0.0),
"selection_margin": raw.get("selection_margin", 0.0),
"retrieval_neighbors": raw.get("retrieval_neighbors", 0),
"retrieval_metric": raw.get("retrieval_metric", "none"),
"retrieval_residual_anchor": raw.get("retrieval_residual_anchor", "none"),
"retrieval_residual_direction": raw.get("retrieval_residual_direction", "none"),
"retrieval_residual_reduce": raw.get("retrieval_residual_reduce", "none"),
"retrieval_residual_scales": raw.get("retrieval_residual_scales", []),
"retrieval_residual_source_score_bonus_by_task": raw.get(
"retrieval_residual_source_score_bonus_by_task", {}
),
"retrieval_residual_source_advantage_weight_scale": raw.get(
"retrieval_residual_source_advantage_weight_scale", 0.0
),
"retrieval_residual_min_source_advantage": raw.get(
"retrieval_residual_min_source_advantage", -1.0e9
),
"lattice_exclude_types": raw.get("lattice_exclude_types", []),
"selected_residual_scale_counts": dict(selected_scale_counts),
"policy_rollout_success_rate": raw.get("policy_rollout_success_rate", 0.0),
"policy_rollout_progress": raw.get("policy_rollout_progress", 0.0),
"oracle_success_rate": raw.get("oracle_success_rate", 0.0),
"action_mse_to_best": raw.get("action_mse_to_best", 0.0),
"per_task": raw.get("per_task", {}),
}
)
successes = [float(row["policy_rollout_success_rate"]) for row in rows]
progresses = [float(row["policy_rollout_progress"]) for row in rows]
mses = [float(row["action_mse_to_best"]) for row in rows]
summary = {
"run_root": str(run_root),
"objective": objective,
"out_name": config.out_name,
"key": config.key,
"label": config.label,
"num_completed": len(rows),
"mean_success": _mean(successes),
"std_success": _std(successes),
"mean_progress": _mean(progresses),
"mean_action_mse_to_best": _mean(mses),
"rows": rows,
}
json_path = results_dir / f"h16_{config.summary_tag}_summary.json"
md_path = results_dir / f"h16_{config.summary_tag}_summary.md"
if len(rows) == 3:
json_path.write_text(json.dumps(summary, indent=2))
md_path.write_text(_render_summary_markdown(summary))
return summary | {"summary_path": str(json_path)}
def _render_summary_markdown(summary: dict[str, Any]) -> str:
lines = [
"# Generator V1 Rollout Summary",
"",
f"Objective: `{summary['objective']}`",
f"Result file: `{summary['out_name']}`",
f"Completed seeds: {summary['num_completed']}",
f"Mean success: {summary['mean_success']:.2%} +/- {summary['std_success']:.2%}",
f"Mean progress: {summary['mean_progress']:.2%}",
"",
"| seed | success | progress | mse | anchor | adv weight | min src adv | scales |",
"|---:|---:|---:|---:|---|---:|---|---|",
]
for row in summary["rows"]:
scales = ",".join(str(item) for item in row.get("retrieval_residual_scales", []))
lines.append(
"| {seed} | {success:.2%} | {progress:.2%} | {mse:.3f} | {anchor} | {weight:.2f} | {min_adv} | {scales} |".format(
seed=row["seed"],
success=row["policy_rollout_success_rate"],
progress=row["policy_rollout_progress"],
mse=row["action_mse_to_best"],
anchor=row.get("retrieval_residual_anchor", "none"),
weight=row.get("retrieval_residual_source_advantage_weight_scale", 0.0),
min_adv=_format_min_source_advantage(
row.get("retrieval_residual_min_source_advantage", -1.0e9)
),
scales=scales or "none",
)
)
return "\n".join(lines) + "\n"
def _format_min_source_advantage(value: Any) -> str:
try:
numeric = float(value)
except (TypeError, ValueError):
return "none"
if numeric <= -1.0e8:
return "none"
return f"{numeric:.2f}"
def _decision_payload(
summaries: list[dict[str, Any]],
*,
best: dict[str, Any] | None,
baseline_success: float,
round_index: int,
) -> dict[str, Any]:
return {
"generated_utc": datetime.now(timezone.utc).isoformat(),
"round": round_index,
"baseline_success": baseline_success,
"complete": all(item["num_completed"] == 3 for item in summaries),
"summaries": [
{
"key": item["key"],
"label": item["label"],
"num_completed": item["num_completed"],
"mean_success": item["mean_success"],
"delta_vs_baseline": item["mean_success"] - baseline_success,
"summary_path": item["summary_path"],
}
for item in summaries
],
"best_key": best["key"] if best else None,
"best_success": best["mean_success"] if best else None,
"best_delta_vs_baseline": (
best["mean_success"] - baseline_success if best else None
),
"recommendation": _recommendation(best, baseline_success),
}
def _recommendation(best: dict[str, Any] | None, baseline_success: float) -> str:
if best is None:
return "wait_for_v1_rollouts_or_debug_failures"
if float(best["mean_success"]) > baseline_success + 0.002:
return "submit_candidate_oracle_for_best_v1"
return "submit_wider_advantage_weight_support_sweep"
def _render_decision_markdown(decision: dict[str, Any]) -> str:
lines = [
"# Generator V1 Decision",
"",
f"Generated: `{decision['generated_utc']}`",
f"Baseline clean success: {decision['baseline_success']:.2%}",
f"Recommendation: `{decision['recommendation']}`",
"",
"| key | completed | success | delta |",
"|---|---:|---:|---:|",
]
for item in decision["summaries"]:
lines.append(
f"| {item['key']} | {item['num_completed']} | {item['mean_success']:.2%} | {item['delta_vs_baseline']:+.2%} |"
)
if decision.get("submitted"):
lines.extend(["", "Submitted follow-up jobs:", ""])
for item in decision["submitted"]:
lines.append(f"- `{item['key']}`: eval `{item.get('eval_job')}`, summary `{item.get('summary_job')}`")
if decision.get("submitted_missing"):
lines.extend(["", "Resubmitted missing seeds:", ""])
for item in decision["submitted_missing"]:
lines.append(
f"- `{item['key']}` seeds `{item.get('missing_seeds')}`: "
f"eval `{item.get('eval_job')}`, summary `{item.get('summary_job')}`"
)
return "\n".join(lines) + "\n"
def _run_build_paper_analysis(project_dir: Path, *, dry_run: bool) -> None:
if dry_run:
return
subprocess.run(
["python3", "scripts/build_paper_analysis.py"],
cwd=project_dir,
check=True,
)
def _maybe_submit_next(
decision: dict[str, Any],
*,
project_dir: Path,
run_root: Path,
dataset: Path,
objective: str,
dry_run: bool,
) -> list[dict[str, str]]:
marker = project_dir / "results" / "v1_generator_next_submitted.json"
if marker.exists():
return _load_json(marker).get("submitted", [])
best_key = decision.get("best_key")
recommendation = str(decision.get("recommendation"))
if recommendation == "submit_candidate_oracle_for_best_v1":
configs = [
_oracle_config(config)
for config in INITIAL_CONFIGS
if config.key == best_key
]
elif recommendation == "submit_wider_advantage_weight_support_sweep":
configs = list(NEXT_SWEEP_CONFIGS)
else:
configs = []
submitted = [
_submit_config(
config,
project_dir=project_dir,
run_root=run_root,
dataset=dataset,
objective=objective,
dry_run=dry_run,
)
for config in configs
]
marker.write_text(
json.dumps(
{
"generated_utc": datetime.now(timezone.utc).isoformat(),
"recommendation": recommendation,
"submitted": submitted,
},
indent=2,
)
)
return submitted
def _maybe_resubmit_missing(
summaries: list[dict[str, Any]],
configs: tuple[V1Config, ...],
*,
project_dir: Path,
run_root: Path,
dataset: Path,
objective: str,
dry_run: bool,
) -> list[dict[str, str]]:
marker = project_dir / "results" / "v1_generator_missing_resubmitted.json"
if marker.exists():
return _load_json(marker).get("submitted", [])
by_key = {item.key: item for item in configs}
submitted: list[dict[str, str]] = []
for summary in summaries:
config = by_key.get(str(summary.get("key")))
if config is None:
continue
present = {int(row["seed"]) for row in summary.get("rows", [])}
missing = [str(seed) for seed in (0, 1, 2) if seed not in present]
if not missing:
continue
submitted.append(
_submit_config(
config,
project_dir=project_dir,
run_root=run_root,
dataset=dataset,
objective=objective,
array_spec=",".join(missing),
dry_run=dry_run,
)
)
submitted[-1]["missing_seeds"] = ",".join(missing)
marker.write_text(
json.dumps(
{
"generated_utc": datetime.now(timezone.utc).isoformat(),
"submitted": submitted,
},
indent=2,
)
)
return submitted
def _oracle_config(config: V1Config) -> V1Config:
return V1Config(
key=f"{config.key}_oraclek8",
label=f"{config.label}, candidate oracle K8",
out_name=config.out_name.replace(".json", "_oraclek8.json"),
summary_tag=f"{config.summary_tag}_oraclek8",
anchor=config.anchor,
advantage_weight=config.advantage_weight,
min_source_advantage=config.min_source_advantage,
candidate_oracle_rollouts=8,
)
def _submit_config(
config: V1Config,
*,
project_dir: Path,
run_root: Path,
dataset: Path,
objective: str,
array_spec: str = "0-2",
dry_run: bool,
) -> dict[str, str]:
export = {
"PROJECT_DIR": str(project_dir),
"RUN_ROOT": str(run_root),
"DATASET": str(dataset),
"OBJECTIVE": objective,
"CHECKPOINT_NAME": "best_transport.pt",
"MAX_GROUPS": "all",
"GROUP_BATCH_SIZE": "8",
"EVAL_SPLIT": "validation",
"SELECTION_MODE": "retrieval_residual",
"NUM_CANDIDATES": "1",
"CANDIDATE_SIGMA": "0.2",
"SELECTION_MARGIN": "0.0",
"RETRIEVAL_NEIGHBORS": "6",
"RETRIEVAL_METRIC": "raw",
"RETRIEVAL_RESIDUAL_REDUCE": "compose_mean_by_type",
"RETRIEVAL_RESIDUAL_DIRECTION": "candidate_minus_anchor",
"RETRIEVAL_RESIDUAL_SCALES_COLON": "0.35:0.4:0.45",
"LATTICE_EXCLUDE_TYPES_COLON": EXCLUDE_TYPES,
"RETRIEVAL_RESIDUAL_SOURCE_SCORE_BONUS_MAP": str(project_dir / SOURCE_SCORE_MAP),
"OUT_NAME": config.out_name,
"RETRIEVAL_RESIDUAL_ANCHOR": config.anchor,
"RETRIEVAL_RESIDUAL_SOURCE_ADVANTAGE_WEIGHT_SCALE": str(config.advantage_weight),
"RETRIEVAL_RESIDUAL_MIN_SOURCE_ADVANTAGE": str(config.min_source_advantage),
"CANDIDATE_ORACLE_ROLLOUTS": str(config.candidate_oracle_rollouts),
}
eval_cmd = [
"sbatch",
"--array=0-2",
"--job-name",
_job_name(config.key),
"--export",
"ALL," + ",".join(f"{key}={value}" for key, value in export.items()),
"scripts/slurm/eval_maniskill_policy_rollout.sbatch",
]
eval_cmd[1] = f"--array={array_spec}"
eval_job = _submit(eval_cmd, project_dir=project_dir, dry_run=dry_run)
summary_export = {
"PROJECT_DIR": str(project_dir),
"RUN_ROOT": str(run_root),
"OBJECTIVE": objective,
"OUT_NAME": config.out_name,
"SUMMARY_TAG": config.summary_tag,
}
summary_cmd = [
"sbatch",
"--dependency",
f"afterok:{eval_job}" if eval_job != "dry-run" else "afterok:0",
"--job-name",
_job_name(f"sum_{config.key}"),
"--export",
"ALL," + ",".join(f"{key}={value}" for key, value in summary_export.items()),
"scripts/slurm/summarize_h16_policy_ckpt.sbatch",
]
summary_job = _submit(summary_cmd, project_dir=project_dir, dry_run=dry_run)
return {"key": config.key, "eval_job": eval_job, "summary_job": summary_job}
def _job_name(key: str) -> str:
return ("v1_" + key).replace("policyanchor", "pol")[:20]
def _submit(cmd: list[str], *, project_dir: Path, dry_run: bool) -> str:
if dry_run:
print("DRY RUN:", " ".join(cmd))
return "dry-run"
result = subprocess.run(
cmd,
cwd=project_dir,
check=True,
text=True,
capture_output=True,
)
for token in result.stdout.split():
if token.isdigit():
return token
raise RuntimeError(f"Could not parse sbatch job id from: {result.stdout}")
if __name__ == "__main__":
raise SystemExit(main())
|