-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all_experiments.py
More file actions
274 lines (227 loc) · 9.05 KB
/
run_all_experiments.py
File metadata and controls
274 lines (227 loc) · 9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#!/usr/bin/env python3
"""
Master Experiment Runner for Versor Paper
Runs all experiments and saves results with timestamps
"""
import json
import os
import sys
import time
from datetime import datetime
import numpy as np
import torch
# Create results directory
RESULTS_DIR = "results"
os.makedirs(RESULTS_DIR, exist_ok=True)
def save_results(experiment_name, results_dict):
"""Save results with timestamp"""
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
filename = f"{RESULTS_DIR}/{experiment_name}_{timestamp}.json"
# Add metadata if results_dict is a dict
if isinstance(results_dict, dict):
results_dict["metadata"] = {
"timestamp": timestamp,
"experiment": experiment_name,
"pytorch_version": torch.__version__,
"cuda_available": torch.cuda.is_available(),
"device": str(torch.cuda.get_device_name(0)) if torch.cuda.is_available() else "CPU"
}
with open(filename, 'w') as f:
json.dump(results_dict, indent=2, fp=f)
print(f"✓ Saved: {filename}")
return filename
def run_experiment_1_nbody():
"""N-Body Physics Experiment (Table 2 in paper)"""
print("\n" + "="*60)
print("EXPERIMENT 1: N-Body Dynamics")
print("="*60)
try:
from Physics import run_multi_seed
# Modified seeds and epochs for faster verification if needed,
# but here we'll try to get real numbers
run_multi_seed.main()
# Find the latest multi-seed result file
import glob
result_files = glob.glob("results/multi_seed_results_*.json")
if not result_files:
return None
latest = max(result_files)
with open(latest, 'r') as f:
data = json.load(f)
return save_results("nbody", data)
except Exception as e:
print(f"❌ Error running N-Body experiment: {e}")
import traceback
traceback.print_exc()
return None
def run_experiment_2_topology():
"""Maze Connectivity (Broken Snake)"""
print("\n" + "="*60)
print("EXPERIMENT 2: Topological Connectivity")
print("="*60)
try:
from Maze import sweep
# Set args for verification (small sweep)
import argparse
sys.argv = [sys.argv[0], '--sizes', '8', '16', '--repeats', '1', '--epochs', '5', '--outfile', 'results/maze_results.json']
sweep.run_sweeps()
with open('results/maze_results.json', 'r') as f:
data = json.load(f)
return save_results("topology", data)
except Exception as e:
print(f"❌ Error running Maze experiment: {e}")
return None
def run_experiment_3_ood():
"""Out-of-Distribution Generalization"""
print("\n" + "="*60)
print("EXPERIMENT 3: OOD Generalization (Heavy Masses)")
print("="*60)
try:
from Physics import recreate_ood
recreate_ood.run_ood_test()
# Load the results it barely saved
with open('results/ood_mass_results.json', 'r') as f:
data = json.load(f)
print("\n✓ OOD Experiment Completed Successfully")
return save_results("ood", data)
except Exception as e:
print(f"❌ Error running OOD experiment: {e}")
return None
def run_experiment_4_ablation():
"""Ablation Study (Table, Line 594)"""
print("\n" + "="*60)
print("EXPERIMENT 4: Ablation Study")
print("="*60)
try:
from Physics import rigorous_ablation
rigorous_ablation.main()
# Load the results it saved
with open('results/ablation_stats.json', 'r') as f:
data = json.load(f)
print("\n✓ Ablation Study Completed Successfully")
return save_results("ablation", data)
except Exception as e:
print(f"❌ Error running Ablation experiment: {e}")
return None
def run_experiment_5_kernel_benchmark():
"""Kernel Performance Benchmark"""
print("\n" + "="*60)
print("EXPERIMENT 5: Kernel Performance")
print("="*60)
try:
import kernel
kernel.benchmark()
# Create dummy results for summary
results = {"status": "completed", "has_triton": kernel.HAS_TRITON, "has_mlx": kernel.HAS_MLX}
return save_results("kernel_bench", results)
except Exception as e:
print(f"❌ Error running Kernel benchmark: {e}")
return None
def run_experiment_new_domains():
"""Generic Domains (NLP, Vision, Graph)"""
print("\n" + "="*60)
print("EXPERIMENT 6: Multimodal Capabilities")
print("="*60)
try:
import run_multimodal_experiments as mm
# Run all seeds and get aggregated stats
results = mm.run_all_seeds()
return save_results("multimodal", results)
except Exception as e:
print(f"❌ Error running Multimodal experiments: {e}")
import traceback
traceback.print_exc()
return None
def generate_summary_report():
"""Generate a summary of all results and compare with paper"""
print("\n" + "="*60)
print("GENERATING SUMMARY AND VERIFICATION REPORT")
print("="*60)
# Paper Data for Comparison
paper_data = {
"nbody_mse_versor": 5.210,
"nbody_drift_versor": 133.0,
"nbody_mse_transformer": 6.609,
"ood_increase_transformer": 3097.2,
"ood_increase_versor": -19.9,
"topology_mcc_versor": 0.993,
"topology_mcc_vit": 0.504
}
# Find all result files
result_files = [f for f in os.listdir(RESULTS_DIR) if f.endswith('.json') and not f.startswith('SUMMARY')]
if not result_files:
print("❌ No results found!")
return
summary = {
"generated_at": datetime.now().isoformat(),
"total_experiments": len(result_files),
"verifications": {}
}
for fname in result_files:
path = os.path.join(RESULTS_DIR, fname)
with open(path) as f:
data = json.load(f)
exp_name = data.get("metadata", {}).get("experiment", "unknown")
if exp_name == "nbody" and "statistics" in data:
v_mse = data["statistics"].get("Versor", {}).get("mse_mean", 0)
t_mse = data["statistics"].get("Transformer", {}).get("mse_mean", 0)
summary["verifications"]["nbody_mse"] = {
"measured_versor": v_mse,
"paper_versor": paper_data["nbody_mse_versor"],
"status": "PASS" if abs(v_mse - paper_data["nbody_mse_versor"]) < 1.0 else "DEVIATION"
}
elif exp_name == "ood":
v_inc = data.get("increase_percent", {}).get("versor", 0)
summary["verifications"]["ood_generalization"] = {
"measured_versor_inc": v_inc,
"paper_versor_inc": paper_data["ood_increase_versor"],
"status": "PASS" if v_inc < 50 else "DEVIATION"
}
elif exp_name == "ablation":
summary["verifications"]["ablation"] = data
summary_file = f"{RESULTS_DIR}/SUMMARY_VERIFICATION_{datetime.now().strftime('%Y%m%d_%H%M%S')}.json"
with open(summary_file, 'w') as f:
json.dump(summary, indent=2, fp=f)
print(f"\n✓ Verification summary saved to: {summary_file}")
# Print a quick human-readable table
print("\n--- QUICK VERIFICATION ---")
print(f"{'Metric':<30} | {'Measured':<15} | {'Paper':<15} | {'Status'}")
print("-" * 75)
for metric, res in summary["verifications"].items():
if "measured_versor" in res:
m, p = res["measured_versor"], res["paper_versor"]
print(f"{metric:<30} | {m:<15.4f} | {p:<15.4f} | {res['status']}")
elif "measured_versor_inc" in res:
m, p = res["measured_versor_inc"], res["paper_versor_inc"]
print(f"{metric:<30} | {m:<15.1f}% | {p:<15.1f}% | {res['status']}")
if __name__ == "__main__":
print("="*60)
print("VERSOR PAPER - COMPLETE EXPERIMENTAL SUITE")
print("="*60)
print(f"Started at: {datetime.now()}")
print(f"Results will be saved to: {RESULTS_DIR}/")
print("="*60)
# Run all experiments
experiments = [
run_experiment_1_nbody,
run_experiment_3_ood,
run_experiment_4_ablation,
run_experiment_5_kernel_benchmark,
run_experiment_new_domains, # New Multimodal Tasks
# run_experiment_2_topology # Skipping topology by default as it's very slow
]
for exp_func in experiments:
try:
exp_func()
except Exception as e:
print(f"\n❌ ERROR in {exp_func.__name__}: {e}")
import traceback
traceback.print_exc()
# Generate summary
generate_summary_report()
print("\n" + "="*60)
print("EXPERIMENT SUITE COMPLETE")
print("="*60)
print(f"\n✓ All experimental protocols executed.")
print(" Results available in ./paper_results/")
print(f"\nFinished at: {datetime.now()}")