Download ops/random_baseline_runfile.py from tchbcb/qwenjev: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/tchbcb/qwenjev/resolve/main/ops/random_baseline_runfile.py
- Command line
-
hf download hf://tchbcb/qwenjev/ops/random_baseline_runfile.py
-
curl -L -o random_baseline_runfile.py https://huggingface.co/tchbcb/qwenjev/resolve/main/ops/random_baseline_runfile.py
2.73 kB
| # Random-baseline control for the v3/v4/v4b 150-step ruler (ar25+bp35). | |
| # Linear code only (exec globals/locals separation — HANDOVER pitfall 7). | |
| # Uniform-random policy over available_actions, RESET only on GAME_OVER | |
| # (mirrors run_game lifecycle). Seed fixed per game index for reproducibility. | |
| import os, sys, json, time, random | |
| os.chdir('/content/qwenjev') | |
| sys.path.insert(0, '/content/qwenjev') | |
| sys.path.insert(0, '/content/qwenjev/train') | |
| from data.collect_selfplay import make_env, meta_from | |
| from data.mock_env import step_env | |
| GAMES = [('bp35', 150)] | |
| BASE_SEED = 42 | |
| report = [] | |
| t0 = time.time() | |
| for idx, (game_id, max_actions) in enumerate(GAMES): | |
| rng = random.Random(BASE_SEED + idx * 100) | |
| env = make_env(game_id, None) | |
| env.reset() | |
| actions = 0 | |
| resets = 0 | |
| best_level = 0 | |
| final_state = 'NOT_FINISHED' | |
| started = time.time() | |
| action_hist = {} | |
| for _ in range(max_actions): | |
| meta = meta_from(env) | |
| final_state = meta['state'] | |
| if final_state == 'WIN': | |
| break | |
| if final_state == 'GAME_OVER': | |
| env.reset() | |
| resets += 1 | |
| continue | |
| best_level = max(best_level, meta['levels_completed']) | |
| avail = list(meta['available_actions']) or ['ACTION1'] | |
| a = rng.choice([x for x in avail if x != 'RESET'] or ['ACTION1']) | |
| action_hist[a] = action_hist.get(a, 0) + 1 | |
| step_env(env, a) | |
| actions += 1 | |
| best_level = max(best_level, meta_from(env)['levels_completed']) | |
| rec = { | |
| 'game_id': game_id, | |
| 'win': final_state == 'WIN', | |
| 'final_state': final_state, | |
| 'best_level': best_level, | |
| 'resets': resets, | |
| 'actions': actions, | |
| 'seconds': round(time.time() - started, 1), | |
| 'action_hist': action_hist, | |
| } | |
| report.append(rec) | |
| print('RESULT', json.dumps(rec), flush=True) | |
| out = { | |
| 'meta': { | |
| 'backend': 'random-uniform', 'seed_note_v2': 'budget paired with v4b-600 ar25 probe', | |
| 'seed_note': 'rng = Random(42 + idx*100) per run, fixed for reproducibility', | |
| 'games': [f'{g}@{m}' for g, m in GAMES], | |
| 'max_actions': [m for _, m in GAMES], | |
| 'seconds_total': round(time.time() - t0, 1), | |
| 'timestamp': time.strftime('%F %T'), | |
| }, | |
| 'games': report, | |
| 'summary': { | |
| 'played': len(report), | |
| 'wins': sum(1 for r in report if r['win']), | |
| 'best_level_sum': sum(r['best_level'] for r in report), | |
| 'resets_sum': sum(r['resets'] for r in report), | |
| 'actions_sum': sum(r['actions'] for r in report), | |
| }, | |
| } | |
| open('/content/eval_random_baseline.json', 'w').write(json.dumps(out, indent=2)) | |
| print('SUMMARY', json.dumps(out['summary']), flush=True) | |