"""Command line entry point: `ptb setup | run | eval`.""" import argparse import json import time from pathlib import Path from . import config from .evaluate import evaluate from .provision import setup from .solve import solve def run(args: argparse.Namespace) -> None: """Full benchmark run: agent phase, then evaluation of its final model.""" safe = str.maketrans("/:[]", "____") # same run dir naming as upstream, so its scripts/ keep working run_dir = (config.RESULTS_DIR / f"{args.agent}_{args.agent_model.translate(safe)}_{args.hours}h{args.experiment_name}" / f"{args.task}_{args.model.translate(safe)}_{time.strftime('%Y%m%d-%H%M%S')}") run_dir.mkdir(parents=True) print(f"Run directory: {run_dir}") solve(run_dir, args.task, args.model, args.agent, args.agent_model, args.hours, args.container) if not (run_dir / "final_model").is_dir(): raise SystemExit("The agent produced no final_model; nothing to evaluate.") report(evaluate(run_dir, args.task, str(run_dir / "final_model"))) def report(metrics: dict | None) -> None: if metrics is None: raise SystemExit("Evaluation failed; see the final_eval_*.txt logs.") print(json.dumps(metrics, indent=2)) def main() -> None: parser = argparse.ArgumentParser(prog="ptb", description=__doc__) commands = parser.add_subparsers(dest="command", required=True) p = commands.add_parser("setup", help="build the container images, download models and test data") p.add_argument("--containers", nargs="*", default=[config.AGENT_CONTAINER, config.EVAL_CONTAINER], choices=config.DEFINITIONS, help="upstream container definitions to build") p.add_argument("--full-cache", action="store_true", help="prefill the HF cache with upstream's 14 models and 382 dataset splits") p.add_argument("--models", nargs="*", default=[], help="HF ids of base models to download") p.add_argument("--tasks", nargs="*", default=[], choices=config.TASKS, help="benchmarks to fetch test data for") p.set_defaults(func=lambda a: setup(a.containers, a.models, a.tasks, a.full_cache)) p = commands.add_parser("run", help="let an agent post-train a model, then evaluate the result") p.add_argument("--task", required=True, choices=config.TASKS) p.add_argument("--model", required=True, help="HF id of the base model to post-train") p.add_argument("--agent", default="claude_non_api", choices=config.AGENTS, help="upstream agent scaffold") p.add_argument("--agent-model", required=True, help="API model driving the agent, e.g. claude-opus-5") p.add_argument("--container", default=config.AGENT_CONTAINER, choices=config.DEFINITIONS, help="container for the agent phase; upstream picks one per cell") p.add_argument("--hours", type=int, default=10, help="time budget of the agent") # Upstream's EXPERIMENT_NAME: a suffix on the results dir, so the repeated seeds of one cell # land in the `..._10h_run1/_run2/_run3` directories `scripts/collect.py` aggregates over. p.add_argument("--experiment-name", default="", help="suffix for the results directory, e.g. _run1") p.set_defaults(func=run) p = commands.add_parser("eval", help="evaluate a model only (e.g. a base model as baseline)") p.add_argument("--task", required=True, choices=config.TASKS) p.add_argument("--model", required=True, help="model directory or HF id") p.add_argument("--out-dir", required=True, type=Path) p.add_argument("--limit", type=int, default=-1, help="number of samples; -1 = full benchmark") p.set_defaults(func=lambda a: report(evaluate(a.out_dir, a.task, a.model, a.limit))) args = parser.parse_args() args.func(args)