StatePlay-Reward-2280 / source /project /scripts /start_new_generation_benchmark.py
lupele's picture
Add files using upload-large-folder tool
4ec41f2 verified
Raw History Blame Contribute Delete
1.6 kB
#!/usr/bin/env python3
"""Launch the benchmark detached without placing API credentials in shell history."""
from __future__ import annotations
import getpass
import os
import subprocess
import sys
import time
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
RUNNER = ROOT / "scripts/run_new_generation_benchmark.sh"
LOG_DIR = ROOT / "evaluation/new_generation100/logs"
def main() -> None:
env = os.environ.copy()
for name in ("STATEPLAY_GPT_API_KEY", "STATEPLAY_GEMINI_API_KEY"):
if not env.get(name):
if not sys.stdin.isatty():
raise SystemExit(f"{name} is required; launch interactively or set it in the environment")
env[name] = getpass.getpass(f"{name}: ").strip()
if not env[name]:
raise SystemExit(f"{name} cannot be empty")
os.umask(0o077)
LOG_DIR.mkdir(parents=True, exist_ok=True)
log_path = LOG_DIR / "launcher.log"
with log_path.open("ab") as log:
process = subprocess.Popen(
["bash", str(RUNNER)],
cwd=ROOT,
env=env,
stdin=subprocess.DEVNULL,
stdout=log,
stderr=subprocess.STDOUT,
start_new_session=True,
)
(LOG_DIR / "launcher.pid").write_text(f"{process.pid}\n", encoding="ascii")
del env
time.sleep(2)
if process.poll() is not None:
raise SystemExit(f"Benchmark exited during startup (code {process.returncode}); see {log_path}")
print(f"Started detached benchmark PID {process.pid}; log: {log_path}")
if __name__ == "__main__":
main()