Skip to content

Commit fa2ba22

Browse files
committed
Add cdfs of steps, files_edited
1 parent 48e48ef commit fa2ba22

4 files changed

Lines changed: 104 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import json
2+
3+
from matplotlib import pyplot as plt
4+
from tqdm.auto import tqdm
5+
6+
from codeclash.constants import LOCAL_LOG_DIR
7+
8+
OUTPUT_FILE = "cdf_files_edited_per_round.png"
9+
10+
11+
def main():
12+
# Create data structure of model -> list of files_edited per round
13+
model_to_num_files = {}
14+
15+
tournaments = [x.parent for x in LOCAL_LOG_DIR.rglob("game.log")]
16+
for game_log_folder in tqdm(tournaments):
17+
with open(game_log_folder / "metadata.json") as f:
18+
metadata = json.load(f)
19+
try:
20+
p2m = {x["name"]: x["config"]["model"]["model_name"].strip("@") for x in metadata["config"]["players"]}
21+
for model in p2m.values():
22+
if model not in model_to_num_files:
23+
model_to_num_files[model] = []
24+
except KeyError:
25+
continue
26+
27+
for name in p2m.keys():
28+
changes_files = (game_log_folder / "players" / name).rglob("changes_r*.json")
29+
for changes_file in changes_files:
30+
with open(changes_file) as f:
31+
changes = json.load(f)
32+
num_files = len(changes["modified_files"])
33+
model_to_num_files[p2m[name]].append(num_files)
34+
35+
# Plot CDF
36+
plt.figure(figsize=(10, 6))
37+
for model, files_edited in model_to_num_files.items():
38+
sorted_files_edited = sorted(files_edited)
39+
yvals = [i / len(sorted_files_edited) for i in range(len(sorted_files_edited))]
40+
plt.step(sorted_files_edited, yvals, label=model, where="post")
41+
42+
plt.xlabel("Files Edited per Round")
43+
plt.ylabel("Cumulative Probability")
44+
plt.title("CDF of Files Edited per Round by Model")
45+
plt.legend()
46+
plt.grid(True)
47+
plt.savefig(OUTPUT_FILE)
48+
print(f"Saved CDF plot to {OUTPUT_FILE}")
49+
50+
51+
if __name__ == "__main__":
52+
main()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import json
2+
3+
from matplotlib import pyplot as plt
4+
from tqdm.auto import tqdm
5+
6+
from codeclash.constants import LOCAL_LOG_DIR
7+
8+
OUTPUT_FILE = "cdf_steps_per_round.png"
9+
10+
11+
def main():
12+
# Create data structure of model -> list of steps per round
13+
model_to_steps = {}
14+
15+
tournaments = [x.parent for x in LOCAL_LOG_DIR.rglob("game.log")]
16+
for game_log_folder in tqdm(tournaments):
17+
with open(game_log_folder / "metadata.json") as f:
18+
metadata = json.load(f)
19+
try:
20+
p2m = {x["name"]: x["config"]["model"]["model_name"].strip("@") for x in metadata["config"]["players"]}
21+
for model in p2m.values():
22+
if model not in model_to_steps:
23+
model_to_steps[model] = []
24+
except KeyError:
25+
continue
26+
27+
for name in p2m.keys():
28+
traj_files = (game_log_folder / "players" / name).rglob("*.traj.json")
29+
for traj_file in traj_files:
30+
with open(traj_file) as f:
31+
traj = json.load(f)
32+
num_steps = sum([1 for _ in traj["messages"] if _["role"] == "assistant"])
33+
model_to_steps[p2m[name]].append(num_steps)
34+
35+
# Plot CDF
36+
plt.figure(figsize=(10, 6))
37+
for model, steps in model_to_steps.items():
38+
sorted_steps = sorted(steps)
39+
yvals = [i / len(sorted_steps) for i in range(len(sorted_steps))]
40+
plt.step(sorted_steps, yvals, label=model, where="post")
41+
42+
plt.xlabel("Steps per Round")
43+
plt.ylabel("Cumulative Probability")
44+
plt.title("CDF of Steps per Round by Model")
45+
plt.legend()
46+
plt.grid(True)
47+
plt.savefig(OUTPUT_FILE)
48+
print(f"Saved CDF plot to {OUTPUT_FILE}")
49+
50+
51+
if __name__ == "__main__":
52+
main()
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)