TwoQuarks commited on
Commit
b79e083
·
verified ·
1 Parent(s): 321af6c

Update Down/run_all.py

Browse files
Files changed (1) hide show
  1. Down/run_all.py +110 -15
Down/run_all.py CHANGED
@@ -1,4 +1,5 @@
1
  from __future__ import annotations
 
2
  import matplotlib
3
  matplotlib.use("Agg")
4
 
@@ -8,38 +9,132 @@ 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__":
 
1
  from __future__ import annotations
2
+
3
  import matplotlib
4
  matplotlib.use("Agg")
5
 
 
9
  import sys
10
  from pathlib import Path
11
 
12
+
13
  ROOT = Path(__file__).resolve().parent
14
+
15
+ # IMPORTANT:
16
+ # In your repo structure (as shown by HF logs), these exist:
17
+ # /app/Down/down
18
+ # /app/Down/AntiDown
19
  DOWN_DIR = ROOT / "down"
20
  ANTIDOWN_DIR = ROOT / "AntiDown"
21
  OUT_GRAPHICS = ROOT / "graphics"
22
 
23
+
24
+ def _run(cmd: list[str], cwd: Path, env: dict[str, str]) -> None:
25
  print(f"[run] ({cwd}) $ {' '.join(cmd)}")
26
+ subprocess.run(cmd, cwd=str(cwd), env=env, check=True)
27
+
28
 
29
+ def _build_parser() -> argparse.ArgumentParser:
30
+ p = argparse.ArgumentParser(description="Run DOWN + AntiDown pipelines and generate plots.")
31
+ p.add_argument("--episodes", type=int, default=400, help="Episodes per phase for DOWN tabular experiment.")
32
+ p.add_argument("--seed", type=int, default=2025, help="Seed for DOWN tabular experiment.")
33
+ return p
34
 
35
+
36
+ def main() -> None:
37
+ args = _build_parser().parse_args()
38
  py = sys.executable
39
+
40
+ # Sanity checks (fail fast with good errors)
41
+ if not DOWN_DIR.exists():
42
+ raise RuntimeError(f"DOWN_DIR not found: {DOWN_DIR} (check repo folder names)")
43
+ if not ANTIDOWN_DIR.exists():
44
+ raise RuntimeError(f"ANTIDOWN_DIR not found: {ANTIDOWN_DIR} (check repo folder names)")
45
+
46
  OUT_GRAPHICS.mkdir(parents=True, exist_ok=True)
47
 
48
+ # Base env for subprocesses
49
+ base_env = os.environ.copy()
50
+
51
+ # ----------------------------
52
  # DOWN
53
+ # ----------------------------
54
+ down_results_dir = DOWN_DIR / "results"
55
+ down_results_dir.mkdir(parents=True, exist_ok=True)
 
 
56
 
57
+ # Keep the filename your plot script already expects
58
+ down_csv = down_results_dir / "paradox_tabular_results.csv"
59
+
60
+ down_env = base_env.copy()
61
+ down_env["TWOQUARKS_RESULTS_DIR"] = str(down_results_dir)
62
+
63
+ _run(
64
+ [
65
+ py,
66
+ str(DOWN_DIR / "exp" / "run_paradox_tabular.py"),
67
+ "--episodes",
68
+ str(int(args.episodes)),
69
+ "--seed",
70
+ str(int(args.seed)),
71
+ "--out",
72
+ str(down_csv),
73
+ ],
74
+ cwd=DOWN_DIR,
75
+ env=down_env,
76
+ )
77
+
78
+ _run(
79
+ [
80
+ py,
81
+ str(DOWN_DIR / "exp" / "plot_paradox_results.py"),
82
+ "--csv",
83
+ str(down_csv),
84
+ "--out",
85
+ str(OUT_GRAPHICS),
86
+ "--prefix",
87
+ "down",
88
+ ],
89
+ cwd=DOWN_DIR,
90
+ env=down_env,
91
+ )
92
+
93
+ # ----------------------------
94
  # AntiDown
95
+ # ----------------------------
96
+ antidown_results_dir = ANTIDOWN_DIR / "results"
97
+ antidown_results_dir.mkdir(parents=True, exist_ok=True)
 
 
98
 
99
+ # Your current plot script expects this exact filename
100
+ antidown_csv = antidown_results_dir / "paradox_tabular_results.csv"
101
 
102
+ antidown_env = base_env.copy()
103
+ antidown_env["TWOQUARKS_RESULTS_DIR"] = str(antidown_results_dir)
104
 
105
+ # NOTE:
106
+ # I’m not passing --episodes here because I don’t know if your AntiDown runner parses it.
107
+ # If it DOES, you can safely add: "--episodes", str(int(args.episodes))
108
+ _run(
109
+ [
110
+ py,
111
+ str(ANTIDOWN_DIR / "exp" / "run_corrupted_valley_tabular.py"),
112
+ ],
113
+ cwd=ANTIDOWN_DIR,
114
+ env=antidown_env,
115
+ )
116
+
117
+ _run(
118
+ [
119
+ py,
120
+ str(ANTIDOWN_DIR / "exp" / "plot_corrupted_valley_results.py"),
121
+ "--csv",
122
+ str(antidown_csv),
123
+ "--out",
124
+ str(OUT_GRAPHICS),
125
+ "--prefix",
126
+ "AntiDown",
127
+ ],
128
+ cwd=ANTIDOWN_DIR,
129
+ env=antidown_env,
130
+ )
131
+
132
+ # ----------------------------
133
+ # Dual plot
134
+ # ----------------------------
135
+ _run([py, str(ROOT / "plot_dual_down_antidown.py")], cwd=ROOT, env=base_env)
136
+
137
+ print(f"[ok] Finished. All plots saved: {OUT_GRAPHICS}")
138
 
139
 
140
  if __name__ == "__main__":