Skip to content

Commit 0b7d618

Browse files
committed
Minor viz updates
1 parent d15120a commit 0b7d618

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

codeclash/analysis/code_evolve/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from tqdm.auto import tqdm
1515
from unidiff import PatchSet
1616

17-
from codeclash.analysis.viz.utils import FONT_BOLD, MODEL_TO_COLOR, MODEL_TO_DISPLAY_NAME
17+
from codeclash.analysis.viz.utils import FONT_BOLD, MARKERS, MODEL_TO_COLOR, MODEL_TO_DISPLAY_NAME
1818
from codeclash.constants import LOCAL_LOG_DIR
1919
from codeclash.games import ARENAS
2020

@@ -402,12 +402,22 @@ def plot_consistency_over_rounds(data_cache: str, output_path: str = "assets/lin
402402
plt.figure(figsize=(6, 6))
403403

404404
# Plot one line per model
405+
idx = 0
405406
for model, round_data in sorted(model_consistency.items()):
406407
rounds = sorted(round_data.keys())
407408
similarities = [round_data[r] for r in rounds]
408409
display = MODEL_TO_DISPLAY_NAME.get(model, model)
409410
color = MODEL_TO_COLOR.get(model, None)
410-
plt.plot(rounds, similarities, marker="o", label=display, linewidth=1.5, markersize=6, color=color)
411+
plt.plot(
412+
rounds,
413+
similarities,
414+
marker=MARKERS[idx % len(MARKERS)],
415+
label=display,
416+
linewidth=1.5,
417+
markersize=6,
418+
color=color,
419+
)
420+
idx += 1
411421

412422
plt.xlabel("Round", fontsize=18, fontproperties=FONT_BOLD)
413423
plt.ylabel("Mean Code Similarity", fontsize=18, fontproperties=FONT_BOLD)

codeclash/analysis/viz/heatmap_win_rates.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
from codeclash.analysis.viz.utils import ASSETS_DIR, FONT_BOLD, MODEL_TO_DISPLAY_NAME
1313
from codeclash.constants import LOCAL_LOG_DIR
1414

15-
OUTPUT_FILE = ASSETS_DIR / "heatmap_win_rates.png"
1615

17-
18-
def main(log_dir: Path):
16+
def main(log_dir: Path, unit: str = "rounds", output_file: Path = ASSETS_DIR / "heatmap_win_rates.png"):
1917
print(f"Creating win rate heatmap from logs in {log_dir}...")
2018

2119
# Track round-level wins: (model1, model2) -> [wins, total_rounds]
@@ -33,6 +31,7 @@ def main(log_dir: Path):
3331
continue
3432

3533
# Process each round (skip round 0)
34+
tracker = defaultdict(int)
3635
for round_id, round_data in metadata["round_stats"].items():
3736
if round_id == "0":
3837
continue
@@ -42,9 +41,19 @@ def main(log_dir: Path):
4241
winner_model = p2m[winner]
4342
loser_model = next(m for m in p2m.values() if m != winner_model)
4443

45-
results[(winner_model, loser_model)][0] += 1 # win
46-
results[(winner_model, loser_model)][1] += 1 # total
47-
results[(loser_model, winner_model)][1] += 1 # total for loser
44+
if unit == "rounds":
45+
results[(winner_model, loser_model)][0] += 1 # win
46+
results[(winner_model, loser_model)][1] += 1 # total
47+
results[(loser_model, winner_model)][1] += 1 # total for loser
48+
elif unit == "tournaments":
49+
tracker[winner_model] += 1
50+
51+
if unit == "tournaments":
52+
winner = max(tracker, key=tracker.get)
53+
loser = min(tracker, key=tracker.get)
54+
results[(winner, loser)][0] += 1 # win
55+
results[(winner, loser)][1] += 1 # total
56+
results[(loser, winner)][1] += 1 # total for loser
4857
except:
4958
continue
5059

@@ -89,12 +98,19 @@ def main(log_dir: Path):
8998

9099
# plt.colorbar(im, label="Win Rate")
91100
plt.tight_layout()
92-
plt.savefig(OUTPUT_FILE, dpi=300, bbox_inches="tight")
93-
print(f"Heatmap saved to {OUTPUT_FILE}")
101+
if unit == "tournaments":
102+
suffix = output_file.suffix or ".png"
103+
output_file = output_file.with_name(f"{output_file.stem}_tournaments{suffix}")
104+
plt.savefig(output_file, dpi=300, bbox_inches="tight")
105+
print(f"Heatmap saved to {output_file}")
94106

95107

96108
if __name__ == "__main__":
97109
parser = argparse.ArgumentParser(description="Create model win rate heatmap")
98110
parser.add_argument("-d", "--log_dir", type=Path, default=LOCAL_LOG_DIR, help="Path to logs")
111+
parser.add_argument("-u", "--unit", type=str, default="rounds", help="Unit of analysis: rounds or tournaments")
112+
parser.add_argument(
113+
"-o", "--output_file", type=Path, default=ASSETS_DIR / "heatmap_win_rates.png", help="Output file path"
114+
)
99115
args = parser.parse_args()
100-
main(args.log_dir)
116+
main(**vars(args))

0 commit comments

Comments
 (0)