Spaces:
Runtime error
Runtime error
Update Down/down/exp/run_paradox_tabular.py
Browse files
Down/down/exp/run_paradox_tabular.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
-
|
| 2 |
# --- twoquarks bootstrap (path-stable imports) ---
|
| 3 |
import sys
|
| 4 |
from pathlib import Path
|
|
|
|
| 5 |
_ROOT = Path(__file__).resolve().parents[1] # project root (sibling of exp/)
|
| 6 |
if str(_ROOT) not in sys.path:
|
| 7 |
sys.path.insert(0, str(_ROOT))
|
| 8 |
# -------------------------------------------------
|
| 9 |
|
|
|
|
| 10 |
import csv
|
| 11 |
import os
|
| 12 |
from pathlib import Path
|
| 13 |
-
import sys
|
| 14 |
|
| 15 |
import numpy as np
|
| 16 |
|
|
@@ -35,12 +35,10 @@ def run_experiment(
|
|
| 35 |
Run HF-Levo and Levo Paradox tabular agents and log results to CSV.
|
| 36 |
|
| 37 |
The CSV schema is:
|
| 38 |
-
|
| 39 |
global_episode,phase,episode,env_seed,agent,episode_reward,failure_mode,rho_state
|
| 40 |
"""
|
| 41 |
out_path = Path(out_csv)
|
| 42 |
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 43 |
-
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 44 |
|
| 45 |
rng = np.random.default_rng(seed)
|
| 46 |
|
|
@@ -74,12 +72,12 @@ def run_experiment(
|
|
| 74 |
writer.writeheader()
|
| 75 |
|
| 76 |
for phase in (1, 2, 3):
|
| 77 |
-
for local_ep in range(episodes_per_phase):
|
| 78 |
env_seed = int(rng.integers(0, 2**31 - 1))
|
| 79 |
|
| 80 |
for agent, name in zip(agents, agent_names, strict=True):
|
| 81 |
env = EpistemicValleyEnv(phase=phase, seed=env_seed)
|
| 82 |
-
s_idx,
|
| 83 |
a = agent.select_action(s_idx)
|
| 84 |
s_next_idx, reward, done, step_info = env.step(a)
|
| 85 |
|
|
@@ -116,9 +114,26 @@ def run_experiment(
|
|
| 116 |
global_ep += 1
|
| 117 |
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
if __name__ == "__main__":
|
|
|
|
|
|
|
| 120 |
# Allow a caller (e.g., run_all.py) to route outputs to a shared folder.
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# --- twoquarks bootstrap (path-stable imports) ---
|
| 2 |
import sys
|
| 3 |
from pathlib import Path
|
| 4 |
+
|
| 5 |
_ROOT = Path(__file__).resolve().parents[1] # project root (sibling of exp/)
|
| 6 |
if str(_ROOT) not in sys.path:
|
| 7 |
sys.path.insert(0, str(_ROOT))
|
| 8 |
# -------------------------------------------------
|
| 9 |
|
| 10 |
+
import argparse
|
| 11 |
import csv
|
| 12 |
import os
|
| 13 |
from pathlib import Path
|
|
|
|
| 14 |
|
| 15 |
import numpy as np
|
| 16 |
|
|
|
|
| 35 |
Run HF-Levo and Levo Paradox tabular agents and log results to CSV.
|
| 36 |
|
| 37 |
The CSV schema is:
|
|
|
|
| 38 |
global_episode,phase,episode,env_seed,agent,episode_reward,failure_mode,rho_state
|
| 39 |
"""
|
| 40 |
out_path = Path(out_csv)
|
| 41 |
out_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
| 42 |
|
| 43 |
rng = np.random.default_rng(seed)
|
| 44 |
|
|
|
|
| 72 |
writer.writeheader()
|
| 73 |
|
| 74 |
for phase in (1, 2, 3):
|
| 75 |
+
for local_ep in range(int(episodes_per_phase)):
|
| 76 |
env_seed = int(rng.integers(0, 2**31 - 1))
|
| 77 |
|
| 78 |
for agent, name in zip(agents, agent_names, strict=True):
|
| 79 |
env = EpistemicValleyEnv(phase=phase, seed=env_seed)
|
| 80 |
+
s_idx, _info = env.reset()
|
| 81 |
a = agent.select_action(s_idx)
|
| 82 |
s_next_idx, reward, done, step_info = env.step(a)
|
| 83 |
|
|
|
|
| 114 |
global_ep += 1
|
| 115 |
|
| 116 |
|
| 117 |
+
def _build_argparser() -> argparse.ArgumentParser:
|
| 118 |
+
p = argparse.ArgumentParser(description="Run DOWN paradox tabular experiment and save CSV.")
|
| 119 |
+
p.add_argument("--episodes", type=int, default=400, help="Episodes per phase (phases: 1,2,3).")
|
| 120 |
+
p.add_argument("--seed", type=int, default=2025, help="RNG seed.")
|
| 121 |
+
p.add_argument(
|
| 122 |
+
"--out",
|
| 123 |
+
type=str,
|
| 124 |
+
default="",
|
| 125 |
+
help="Optional output CSV path. If omitted, uses TWOQUARKS_RESULTS_DIR or down/results.",
|
| 126 |
+
)
|
| 127 |
+
return p
|
| 128 |
+
|
| 129 |
+
|
| 130 |
if __name__ == "__main__":
|
| 131 |
+
args = _build_argparser().parse_args()
|
| 132 |
+
|
| 133 |
# Allow a caller (e.g., run_all.py) to route outputs to a shared folder.
|
| 134 |
+
results_dir = Path(os.environ.get("TWOQUARKS_RESULTS_DIR", (_QUARK_DIR / "results").as_posix()))
|
| 135 |
+
results_dir.mkdir(parents=True, exist_ok=True)
|
| 136 |
+
|
| 137 |
+
out_csv = Path(args.out) if args.out.strip() else (results_dir / "down_paradox_tabular_results.csv")
|
| 138 |
+
|
| 139 |
+
run_experiment(out_csv.as_posix(), episodes_per_phase=int(args.episodes), seed=int(args.seed))
|