TwoQuarks commited on
Commit
262e074
·
verified ·
1 Parent(s): cdb95be

Update Down/run_all.py

Browse files
Files changed (1) hide show
  1. Down/run_all.py +22 -53
Down/run_all.py CHANGED
@@ -1,76 +1,45 @@
1
- """Run both DOWN and AntiDown tabular experiments.
2
-
3
- Usage:
4
- python run_all.py --episodes 400
5
-
6
- This will:
7
- - run down tabular paradox experiment
8
- - run AntiDown corrupted valley tabular experiment
9
- - generate plots for each into their graphics/ folders
10
- """
11
-
12
  from __future__ import annotations
13
-
14
- # Headless-safe plotting (Hugging Face / Linux without DISPLAY)
15
  import matplotlib
16
  matplotlib.use("Agg")
17
 
18
  import argparse
19
  import os
20
  import subprocess
21
- from pathlib import Path
22
  import sys
 
23
 
 
 
 
 
24
 
25
- def _run(cmd: list[str], cwd: Path, env: dict[str, str] | None = None) -> None:
26
  print(f"[run] ({cwd}) $ {' '.join(cmd)}")
27
- merged = os.environ.copy()
28
- if env:
29
- merged.update(env)
30
- subprocess.run(cmd, cwd=str(cwd), check=True, env=merged)
31
-
32
-
33
- def main() -> None:
34
- ap = argparse.ArgumentParser()
35
- ap.add_argument("--episodes", type=int, default=400, help="Episodes per phase (or main loop) where applicable")
36
- args = ap.parse_args()
37
 
38
- root = Path(__file__).resolve().parent
39
- results_dir = root / "results"
40
- graphics_dir = root / "graphics"
41
- results_dir.mkdir(parents=True, exist_ok=True)
42
- graphics_dir.mkdir(parents=True, exist_ok=True)
43
 
44
- # Common env for all subprocesses (plots must be headless-safe)
45
- common_env = {
46
- "TWOQUARKS_RESULTS_DIR": results_dir.as_posix(),
47
- "TWOQUARKS_GRAPHICS_DIR": graphics_dir.as_posix(),
48
- "MPLBACKEND": "Agg", # <-- critical for HF headless plotting
49
- }
50
-
51
- down_dir = root / "down"
52
- AntiDown_dir = root / "AntiDown"
53
 
54
  # DOWN
55
- down_script = down_dir / "exp" / "run_paradox_tabular.py"
56
- _run([sys.executable, str(down_script)], cwd=down_dir, env=common_env)
57
-
58
- plot_script = down_dir / "exp" / "plot_paradox_results.py"
59
- _run([sys.executable, str(plot_script)], cwd=down_dir, env=common_env)
60
 
61
  # AntiDown
62
- AntiDown_script = AntiDown_dir / "exp" / "run_corrupted_valley_tabular.py"
63
- _run([sys.executable, str(AntiDown_script)], cwd=AntiDown_dir, env=common_env)
 
 
 
64
 
65
- AntiDown_plot = AntiDown_dir / "exp" / "plot_corrupted_valley_results.py"
66
- _run([sys.executable, str(AntiDown_plot)], cwd=AntiDown_dir, env=common_env)
67
 
68
- # Dual overlay plot (Down vs AntiDown)
69
- dual_plot = root / "plot_dual_down_antidown.py"
70
- if dual_plot.exists():
71
- _run([sys.executable, str(dual_plot)], cwd=root, env=common_env)
72
 
73
- print("\nDone. Results and plots saved into root/results and root/graphics.")
74
 
75
 
76
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
1
  from __future__ import annotations
 
 
2
  import matplotlib
3
  matplotlib.use("Agg")
4
 
5
  import argparse
6
  import os
7
  import subprocess
 
8
  import sys
9
+ from pathlib import Path
10
 
11
+ ROOT = Path(__file__).resolve().parent
12
+ DOWN_DIR = ROOT / "down"
13
+ ANTIDOWN_DIR = ROOT / "AntiDown"
14
+ OUT_GRAPHICS = ROOT / "graphics"
15
 
16
+ def _run(cmd, cwd: Path):
17
  print(f"[run] ({cwd}) $ {' '.join(cmd)}")
18
+ subprocess.run(cmd, cwd=str(cwd), check=True)
 
 
 
 
 
 
 
 
 
19
 
 
 
 
 
 
20
 
21
+ def main():
22
+ py = sys.executable
23
+ OUT_GRAPHICS.mkdir(parents=True, exist_ok=True)
 
 
 
 
 
 
24
 
25
  # DOWN
26
+ _run([py, str(DOWN_DIR / "exp" / "run_paradox_tabular.py")], cwd=DOWN_DIR)
27
+ _run([py, str(DOWN_DIR / "exp" / "plot_paradox_results.py"),
28
+ "--csv", str(DOWN_DIR / "results" / "paradox_tabular_results.csv"),
29
+ "--out", str(OUT_GRAPHICS),
30
+ "--prefix", "down"], cwd=DOWN_DIR)
31
 
32
  # AntiDown
33
+ _run([py, str(ANTIDOWN_DIR / "exp" / "run_corrupted_valley_tabular.py")], cwd=ANTIDOWN_DIR)
34
+ _run([py, str(ANTIDOWN_DIR / "exp" / "plot_corrupted_valley_results.py"),
35
+ "--csv", str(ANTIDOWN_DIR / "results" / "paradox_tabular_results.csv"),
36
+ "--out", str(OUT_GRAPHICS),
37
+ "--prefix", "AntiDown"], cwd=ANTIDOWN_DIR)
38
 
39
+ _run([py, str(ROOT / "plot_dual_down_antidown.py")], cwd=ROOT)
 
40
 
41
+ print(f"[ok] Finished. All plots saved: {OUT_GRAPHICS}")
 
 
 
42
 
 
43
 
44
 
45
  if __name__ == "__main__":