王子睿 commited on
Commit ·
165e0b7
1
Parent(s): 60cec10
restructure + add files
Browse files
data/processed/RQ3/plot_total_tokens_violin.py
CHANGED
|
@@ -1,15 +1,25 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
|
| 3 |
import csv
|
|
|
|
| 4 |
from collections import defaultdict
|
| 5 |
from pathlib import Path
|
| 6 |
from typing import Dict, List, Tuple
|
| 7 |
|
| 8 |
-
import matplotlib.pyplot as plt
|
| 9 |
import numpy as np
|
| 10 |
-
from matplotlib.ticker import FuncFormatter
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
MODEL_ORDER: List[str] = [
|
| 15 |
"GPT-5",
|
|
@@ -31,6 +41,14 @@ MODEL_LABELS: Dict[str, str] = {
|
|
| 31 |
"Qwen3-235b": "Qwen3-235b",
|
| 32 |
}
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
MODEL_COLORS: Dict[str, str] = {
|
| 35 |
"GPT-5": "#1f77b4",
|
| 36 |
"GPT-4o-mini": "#ff7f0e",
|
|
@@ -54,6 +72,135 @@ STATUS_TITLES: Dict[str, str] = {
|
|
| 54 |
}
|
| 55 |
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def _nice_step(max_val: float, target_ticks: int = 6) -> float:
|
| 58 |
if max_val <= 0:
|
| 59 |
return 1.0
|
|
@@ -79,21 +226,47 @@ def _token_formatter(x, pos):
|
|
| 79 |
return str(int(x))
|
| 80 |
|
| 81 |
|
| 82 |
-
def load_projects(
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
| 85 |
reader = csv.DictReader(f)
|
| 86 |
for row in reader:
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
if not task or not arch:
|
| 90 |
continue
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
def classify_status(status_raw: str, with_retry_raw: str) -> str:
|
|
@@ -116,10 +289,14 @@ def load_total_tokens(
|
|
| 116 |
with details_csv.open("r", encoding="utf-8", newline="") as f:
|
| 117 |
reader = csv.DictReader(f)
|
| 118 |
for row in reader:
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
| 121 |
key = (task, arch)
|
| 122 |
-
|
|
|
|
| 123 |
continue
|
| 124 |
|
| 125 |
model = (row.get("model") or "").strip()
|
|
@@ -136,7 +313,6 @@ def load_total_tokens(
|
|
| 136 |
except ValueError:
|
| 137 |
continue
|
| 138 |
|
| 139 |
-
project_name = project_map[key]
|
| 140 |
data[project_name][status_group][model].append(total_val)
|
| 141 |
|
| 142 |
return data
|
|
@@ -166,10 +342,14 @@ def load_all_token_data(
|
|
| 166 |
with details_csv.open("r", encoding="utf-8", newline="") as f:
|
| 167 |
reader = csv.DictReader(f)
|
| 168 |
for row in reader:
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
key = (task, arch)
|
| 172 |
-
project_name = project_map.get(key)
|
| 173 |
if not project_name:
|
| 174 |
continue
|
| 175 |
|
|
@@ -241,16 +421,24 @@ def generate_project_stats_md(
|
|
| 241 |
overall_status_values: Dict[str, List[float]],
|
| 242 |
out_dir: Path,
|
| 243 |
) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
def build_series_data() -> Dict[str, Dict[str, Dict[str, List[float]]]]:
|
| 245 |
series: Dict[str, Dict[str, Dict[str, List[float]]]] = defaultdict(
|
| 246 |
lambda: defaultdict(lambda: defaultdict(list))
|
| 247 |
)
|
| 248 |
for task, arch, name in projects:
|
|
|
|
| 249 |
pdata = project_data.get(name, {})
|
| 250 |
for status in STATUS_ORDER:
|
| 251 |
by_model = pdata.get(status, {})
|
| 252 |
for model, vals in by_model.items():
|
| 253 |
-
series[
|
| 254 |
return series
|
| 255 |
|
| 256 |
def append_status_table(
|
|
@@ -350,7 +538,7 @@ def generate_project_stats_md(
|
|
| 350 |
for task in sorted(series_data.keys()):
|
| 351 |
sdata = series_data[task]
|
| 352 |
lines.append("")
|
| 353 |
-
lines.append(f"### {task} (aggregated across
|
| 354 |
append_status_table(lines, sdata, statuses)
|
| 355 |
append_status_comparison(
|
| 356 |
lines,
|
|
@@ -384,184 +572,189 @@ def generate_architecture_deltas_md(
|
|
| 384 |
arch_model_data: Dict[str, Dict[str, Dict[str, List[float]]]],
|
| 385 |
out_dir: Path,
|
| 386 |
) -> None:
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
|
| 397 |
-
def render_chain(
|
| 398 |
-
task: str, chain: List[str], task_arch_data: Dict[str, Dict[str, List[float]]]
|
| 399 |
-
) -> None:
|
| 400 |
-
arch_display = {
|
| 401 |
-
"Unknown": "CrewAI (Unknown)",
|
| 402 |
-
"MCP": "MCP",
|
| 403 |
-
"A2A": "A2A",
|
| 404 |
-
"A2A_mix": "A2A_mix",
|
| 405 |
-
}
|
| 406 |
-
|
| 407 |
-
is_pair = len(chain) == 2
|
| 408 |
-
if is_pair:
|
| 409 |
header = f"| Model | {arch_display[chain[0]]} | {arch_display[chain[1]]} | Δ {arch_display[chain[1]]}-{arch_display[chain[0]]} |"
|
| 410 |
sep = "| --- | --- | --- | --- |"
|
| 411 |
-
else:
|
| 412 |
-
header = (
|
| 413 |
-
f"| Model | {arch_display[chain[0]]} | {arch_display[chain[1]]} | Δ {arch_display[chain[1]]}-{arch_display[chain[0]]} | "
|
| 414 |
-
f"{arch_display[chain[2]]} | Δ {arch_display[chain[2]]}-{arch_display[chain[1]]} |"
|
| 415 |
-
)
|
| 416 |
-
sep = "| --- | --- | --- | --- | --- | --- |"
|
| 417 |
-
|
| 418 |
-
lines.append("")
|
| 419 |
-
lines.append(header)
|
| 420 |
-
lines.append(sep)
|
| 421 |
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
vals = task_arch_data.get(arch, {}).get(model, [])
|
| 426 |
-
arch_means[arch] = float(np.mean(vals)) if vals else None
|
| 427 |
|
| 428 |
-
|
| 429 |
-
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
|
| 433 |
-
if arch_means[chain[0]] is None
|
| 434 |
-
else _fmt_number(arch_means[chain[0]])
|
| 435 |
-
),
|
| 436 |
-
(
|
| 437 |
-
"-"
|
| 438 |
-
if arch_means[chain[1]] is None
|
| 439 |
-
else _fmt_number(arch_means[chain[1]])
|
| 440 |
-
),
|
| 441 |
-
_fmt_delta(arch_means[chain[1]], arch_means[chain[0]]),
|
| 442 |
-
]
|
| 443 |
-
else:
|
| 444 |
row = [
|
| 445 |
MODEL_LABELS.get(model, model),
|
| 446 |
-
(
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
else _fmt_number(arch_means[chain[0]])
|
| 450 |
-
),
|
| 451 |
-
(
|
| 452 |
-
"-"
|
| 453 |
-
if arch_means[chain[1]] is None
|
| 454 |
-
else _fmt_number(arch_means[chain[1]])
|
| 455 |
-
),
|
| 456 |
-
_fmt_delta(arch_means[chain[1]], arch_means[chain[0]]),
|
| 457 |
-
(
|
| 458 |
-
"-"
|
| 459 |
-
if arch_means[chain[2]] is None
|
| 460 |
-
else _fmt_number(arch_means[chain[2]])
|
| 461 |
-
),
|
| 462 |
-
_fmt_delta(arch_means[chain[2]], arch_means[chain[1]]),
|
| 463 |
]
|
| 464 |
-
|
| 465 |
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
lines.append("")
|
| 470 |
-
if is_pair:
|
| 471 |
lines.append(
|
| 472 |
f"| Metric | {arch_display[chain[0]]} | {arch_display[chain[1]]} | Δ {arch_display[chain[1]]}-{arch_display[chain[0]]} |"
|
| 473 |
)
|
| 474 |
lines.append("| --- | --- | --- | --- |")
|
| 475 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 476 |
lines.append(
|
| 477 |
-
|
| 478 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
)
|
| 480 |
-
lines.append("| --- | --- | --- | --- | --- | --- |")
|
| 481 |
-
|
| 482 |
-
arch_mean_all: Dict[str, float] = {}
|
| 483 |
-
for arch in chain:
|
| 484 |
-
combined: List[float] = []
|
| 485 |
-
models = task_arch_data.get(arch, {})
|
| 486 |
-
for vals in models.values():
|
| 487 |
-
combined.extend(vals)
|
| 488 |
-
arch_mean_all[arch] = float(np.mean(combined)) if combined else None
|
| 489 |
-
|
| 490 |
-
if is_pair:
|
| 491 |
-
row = [
|
| 492 |
-
"Avg tokens (all models)",
|
| 493 |
-
(
|
| 494 |
-
"-"
|
| 495 |
-
if arch_mean_all[chain[0]] is None
|
| 496 |
-
else _fmt_number(arch_mean_all[chain[0]])
|
| 497 |
-
),
|
| 498 |
-
(
|
| 499 |
-
"-"
|
| 500 |
-
if arch_mean_all[chain[1]] is None
|
| 501 |
-
else _fmt_number(arch_mean_all[chain[1]])
|
| 502 |
-
),
|
| 503 |
-
_fmt_delta(arch_mean_all[chain[1]], arch_mean_all[chain[0]]),
|
| 504 |
-
]
|
| 505 |
-
else:
|
| 506 |
-
row = [
|
| 507 |
-
"Avg tokens (all models)",
|
| 508 |
-
(
|
| 509 |
-
"-"
|
| 510 |
-
if arch_mean_all[chain[0]] is None
|
| 511 |
-
else _fmt_number(arch_mean_all[chain[0]])
|
| 512 |
-
),
|
| 513 |
-
(
|
| 514 |
-
"-"
|
| 515 |
-
if arch_mean_all[chain[1]] is None
|
| 516 |
-
else _fmt_number(arch_mean_all[chain[1]])
|
| 517 |
-
),
|
| 518 |
-
_fmt_delta(arch_mean_all[chain[1]], arch_mean_all[chain[0]]),
|
| 519 |
-
(
|
| 520 |
-
"-"
|
| 521 |
-
if arch_mean_all[chain[2]] is None
|
| 522 |
-
else _fmt_number(arch_mean_all[chain[2]])
|
| 523 |
-
),
|
| 524 |
-
_fmt_delta(arch_mean_all[chain[2]], arch_mean_all[chain[1]]),
|
| 525 |
-
]
|
| 526 |
-
lines.append("| " + " | ".join(row) + " |")
|
| 527 |
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
"MCP",
|
| 537 |
-
"A2A_mix",
|
| 538 |
-
}.issubset(arches)
|
| 539 |
-
|
| 540 |
-
if not task_arch_data:
|
| 541 |
-
lines.append("")
|
| 542 |
-
lines.append("> No token data found for this task.")
|
| 543 |
-
continue
|
| 544 |
|
| 545 |
-
if has_unknown_pair:
|
| 546 |
lines.append("")
|
| 547 |
-
lines.append("##
|
| 548 |
-
|
| 549 |
|
| 550 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
lines.append("")
|
| 552 |
-
lines.append(
|
| 553 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 554 |
|
| 555 |
-
if not has_unknown_pair and not has_three_chain:
|
| 556 |
lines.append("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
lines.append(
|
| 558 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 559 |
)
|
| 560 |
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
| 566 |
|
| 567 |
def generate_project_model_distribution_md(
|
|
@@ -689,6 +882,10 @@ def plot_violin_for_project(
|
|
| 689 |
out_dir: Path,
|
| 690 |
global_max: float,
|
| 691 |
) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 692 |
any_values = False
|
| 693 |
for status in STATUS_ORDER:
|
| 694 |
by_model = project_data.get(status, {})
|
|
@@ -783,18 +980,20 @@ def plot_violin_for_project(
|
|
| 783 |
def main() -> None:
|
| 784 |
part1_dir = Path(__file__).resolve().parent
|
| 785 |
details_csv = part1_dir / "task_token_statistics-DETAILS.csv"
|
| 786 |
-
|
|
|
|
|
|
|
|
|
|
| 787 |
out_dir = part1_dir / "Violin"
|
| 788 |
|
| 789 |
-
projects = load_projects(
|
| 790 |
-
project_map: Dict[Tuple[str, str], str] = {
|
| 791 |
-
(task, arch): name for task, arch, name in projects
|
| 792 |
-
}
|
| 793 |
|
| 794 |
project_data, arch_model_data, overall_status_values = load_all_token_data(
|
| 795 |
details_csv, project_map
|
| 796 |
)
|
| 797 |
|
|
|
|
|
|
|
| 798 |
# Compute a shared y-axis maximum per task so that all architectures
|
| 799 |
# of the same task use the same vertical scale in their violin plots.
|
| 800 |
task_max_values: Dict[str, float] = {}
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
|
| 3 |
import csv
|
| 4 |
+
import os
|
| 5 |
from collections import defaultdict
|
| 6 |
from pathlib import Path
|
| 7 |
from typing import Dict, List, Tuple
|
| 8 |
|
|
|
|
| 9 |
import numpy as np
|
|
|
|
| 10 |
|
| 11 |
+
try:
|
| 12 |
+
import matplotlib.pyplot as plt
|
| 13 |
+
from matplotlib.ticker import FuncFormatter
|
| 14 |
+
|
| 15 |
+
HAS_MATPLOTLIB = True
|
| 16 |
+
except ModuleNotFoundError:
|
| 17 |
+
plt = None # type: ignore[assignment]
|
| 18 |
+
FuncFormatter = None # type: ignore[assignment]
|
| 19 |
+
HAS_MATPLOTLIB = False
|
| 20 |
+
|
| 21 |
+
if HAS_MATPLOTLIB:
|
| 22 |
+
plt.rcParams["font.family"] = "Times New Roman"
|
| 23 |
|
| 24 |
MODEL_ORDER: List[str] = [
|
| 25 |
"GPT-5",
|
|
|
|
| 41 |
"Qwen3-235b": "Qwen3-235b",
|
| 42 |
}
|
| 43 |
|
| 44 |
+
|
| 45 |
+
ARCH_ORDER: List[str] = [
|
| 46 |
+
"Unknown",
|
| 47 |
+
"MCP",
|
| 48 |
+
"A2A",
|
| 49 |
+
"A2A_mix",
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
MODEL_COLORS: Dict[str, str] = {
|
| 53 |
"GPT-5": "#1f77b4",
|
| 54 |
"GPT-4o-mini": "#ff7f0e",
|
|
|
|
| 72 |
}
|
| 73 |
|
| 74 |
|
| 75 |
+
def infer_project_dir(file_path: str) -> str:
|
| 76 |
+
raw = (file_path or "").strip()
|
| 77 |
+
if not raw:
|
| 78 |
+
return ""
|
| 79 |
+
try:
|
| 80 |
+
p = Path(raw)
|
| 81 |
+
return p.parents[2].name
|
| 82 |
+
except Exception:
|
| 83 |
+
return ""
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def infer_architecture(project_dir: str) -> str:
|
| 87 |
+
name = (project_dir or "").strip()
|
| 88 |
+
if not name:
|
| 89 |
+
return "Unknown"
|
| 90 |
+
if name.endswith("-MCP"):
|
| 91 |
+
return "MCP"
|
| 92 |
+
if name.endswith("-H_A2A") or name.endswith("-H-A2A"):
|
| 93 |
+
return "A2A_mix"
|
| 94 |
+
if name.endswith("-A2A"):
|
| 95 |
+
return "A2A"
|
| 96 |
+
return "Unknown"
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def infer_base_task(project_dir: str) -> str:
|
| 100 |
+
name = (project_dir or "").strip()
|
| 101 |
+
for suffix in ("-H_A2A", "-H-A2A", "-MCP", "-A2A"):
|
| 102 |
+
if name.endswith(suffix):
|
| 103 |
+
return name[: -len(suffix)]
|
| 104 |
+
return name
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def make_project_name(base_task: str, arch: str) -> str:
|
| 108 |
+
task = (base_task or "").strip()
|
| 109 |
+
if not task:
|
| 110 |
+
return ""
|
| 111 |
+
if arch == "Unknown":
|
| 112 |
+
return task
|
| 113 |
+
if arch == "MCP":
|
| 114 |
+
return f"{task}-MCP"
|
| 115 |
+
if arch == "A2A_mix":
|
| 116 |
+
return f"{task}-H-A2A"
|
| 117 |
+
if arch == "A2A":
|
| 118 |
+
return f"{task}-A2A"
|
| 119 |
+
return f"{task}-{arch}"
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def infer_architecture_from_project_name(project_name: str) -> str:
|
| 123 |
+
name = (project_name or "").strip()
|
| 124 |
+
if not name:
|
| 125 |
+
return "Unknown"
|
| 126 |
+
if name.endswith("-MCP"):
|
| 127 |
+
return "MCP"
|
| 128 |
+
if name.endswith("-H-A2A") or name.endswith("-H_A2A"):
|
| 129 |
+
return "A2A_mix"
|
| 130 |
+
if name.endswith("-A2A"):
|
| 131 |
+
return "A2A"
|
| 132 |
+
return "Unknown"
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def base_task_from_project_name(project_name: str) -> str:
|
| 136 |
+
name = (project_name or "").strip()
|
| 137 |
+
for suffix in ("-H-A2A", "-H_A2A", "-MCP", "-A2A"):
|
| 138 |
+
if name.endswith(suffix):
|
| 139 |
+
return name[: -len(suffix)]
|
| 140 |
+
return name
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def export_violin_input_summary(
|
| 144 |
+
projects: List[Tuple[str, str, str]],
|
| 145 |
+
project_data: Dict[str, Dict[str, Dict[str, List[float]]]],
|
| 146 |
+
out_dir: Path,
|
| 147 |
+
) -> None:
|
| 148 |
+
if (os.environ.get("EXPORT_VIOLIN_INPUT") or "").strip() not in {
|
| 149 |
+
"1",
|
| 150 |
+
"true",
|
| 151 |
+
"True",
|
| 152 |
+
}:
|
| 153 |
+
return
|
| 154 |
+
|
| 155 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 156 |
+
out_path = out_dir / "violin_input_summary.csv"
|
| 157 |
+
|
| 158 |
+
with out_path.open("w", encoding="utf-8", newline="") as f:
|
| 159 |
+
writer = csv.writer(f)
|
| 160 |
+
writer.writerow(
|
| 161 |
+
[
|
| 162 |
+
"project",
|
| 163 |
+
"base_task",
|
| 164 |
+
"architecture",
|
| 165 |
+
"status_group",
|
| 166 |
+
"model",
|
| 167 |
+
"n",
|
| 168 |
+
"mean",
|
| 169 |
+
"median",
|
| 170 |
+
"min",
|
| 171 |
+
"max",
|
| 172 |
+
]
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
for _, _, name in projects:
|
| 176 |
+
pdata = project_data.get(name, {})
|
| 177 |
+
base_task = base_task_from_project_name(name)
|
| 178 |
+
arch = infer_architecture_from_project_name(name)
|
| 179 |
+
for status in STATUS_ORDER:
|
| 180 |
+
by_model = pdata.get(status, {})
|
| 181 |
+
for model in MODEL_ORDER:
|
| 182 |
+
vals = by_model.get(model, [])
|
| 183 |
+
if not vals:
|
| 184 |
+
continue
|
| 185 |
+
arr = np.asarray(vals, dtype=float)
|
| 186 |
+
writer.writerow(
|
| 187 |
+
[
|
| 188 |
+
name,
|
| 189 |
+
base_task,
|
| 190 |
+
arch,
|
| 191 |
+
status,
|
| 192 |
+
model,
|
| 193 |
+
int(arr.size),
|
| 194 |
+
float(np.mean(arr)),
|
| 195 |
+
float(np.median(arr)),
|
| 196 |
+
float(np.min(arr)),
|
| 197 |
+
float(np.max(arr)),
|
| 198 |
+
]
|
| 199 |
+
)
|
| 200 |
+
|
| 201 |
+
print(f"saved violin input summary: {out_path}")
|
| 202 |
+
|
| 203 |
+
|
| 204 |
def _nice_step(max_val: float, target_ticks: int = 6) -> float:
|
| 205 |
if max_val <= 0:
|
| 206 |
return 1.0
|
|
|
|
| 226 |
return str(int(x))
|
| 227 |
|
| 228 |
|
| 229 |
+
def load_projects(
|
| 230 |
+
details_csv: Path,
|
| 231 |
+
) -> Tuple[List[Tuple[str, str, str]], Dict[Tuple[str, str], str]]:
|
| 232 |
+
present: Dict[str, set] = defaultdict(set)
|
| 233 |
+
|
| 234 |
+
with details_csv.open("r", encoding="utf-8", newline="") as f:
|
| 235 |
reader = csv.DictReader(f)
|
| 236 |
for row in reader:
|
| 237 |
+
project_dir = infer_project_dir(row.get("file_path") or "")
|
| 238 |
+
if not project_dir:
|
|
|
|
| 239 |
continue
|
| 240 |
+
arch = infer_architecture(project_dir)
|
| 241 |
+
base_task = infer_base_task(project_dir)
|
| 242 |
+
if not base_task:
|
| 243 |
+
continue
|
| 244 |
+
|
| 245 |
+
model = (row.get("model") or "").strip()
|
| 246 |
+
if model and model not in MODEL_ORDER:
|
| 247 |
+
continue
|
| 248 |
+
|
| 249 |
+
total_raw = row.get("total_tokens")
|
| 250 |
+
if total_raw is None or total_raw == "":
|
| 251 |
+
continue
|
| 252 |
+
try:
|
| 253 |
+
float(total_raw)
|
| 254 |
+
except ValueError:
|
| 255 |
+
continue
|
| 256 |
+
|
| 257 |
+
present[base_task].add(arch)
|
| 258 |
+
|
| 259 |
+
projects: List[Tuple[str, str, str]] = []
|
| 260 |
+
project_map: Dict[Tuple[str, str], str] = {}
|
| 261 |
+
for base_task in sorted(present.keys()):
|
| 262 |
+
for arch in ARCH_ORDER:
|
| 263 |
+
if arch not in present[base_task]:
|
| 264 |
+
continue
|
| 265 |
+
name = make_project_name(base_task, arch)
|
| 266 |
+
project_map[(base_task, arch)] = name
|
| 267 |
+
projects.append((base_task, arch, name))
|
| 268 |
+
|
| 269 |
+
return projects, project_map
|
| 270 |
|
| 271 |
|
| 272 |
def classify_status(status_raw: str, with_retry_raw: str) -> str:
|
|
|
|
| 289 |
with details_csv.open("r", encoding="utf-8", newline="") as f:
|
| 290 |
reader = csv.DictReader(f)
|
| 291 |
for row in reader:
|
| 292 |
+
project_dir = infer_project_dir(row.get("file_path") or "")
|
| 293 |
+
if not project_dir:
|
| 294 |
+
continue
|
| 295 |
+
task = infer_base_task(project_dir)
|
| 296 |
+
arch = infer_architecture(project_dir)
|
| 297 |
key = (task, arch)
|
| 298 |
+
project_name = project_map.get(key) or make_project_name(task, arch)
|
| 299 |
+
if not project_name:
|
| 300 |
continue
|
| 301 |
|
| 302 |
model = (row.get("model") or "").strip()
|
|
|
|
| 313 |
except ValueError:
|
| 314 |
continue
|
| 315 |
|
|
|
|
| 316 |
data[project_name][status_group][model].append(total_val)
|
| 317 |
|
| 318 |
return data
|
|
|
|
| 342 |
with details_csv.open("r", encoding="utf-8", newline="") as f:
|
| 343 |
reader = csv.DictReader(f)
|
| 344 |
for row in reader:
|
| 345 |
+
project_dir = infer_project_dir(row.get("file_path") or "")
|
| 346 |
+
if not project_dir:
|
| 347 |
+
continue
|
| 348 |
+
|
| 349 |
+
task = infer_base_task(project_dir)
|
| 350 |
+
arch = infer_architecture(project_dir)
|
| 351 |
key = (task, arch)
|
| 352 |
+
project_name = project_map.get(key) or make_project_name(task, arch)
|
| 353 |
if not project_name:
|
| 354 |
continue
|
| 355 |
|
|
|
|
| 421 |
overall_status_values: Dict[str, List[float]],
|
| 422 |
out_dir: Path,
|
| 423 |
) -> None:
|
| 424 |
+
def _base_task_name(task: str) -> str:
|
| 425 |
+
suffixes = ("-H_A2A", "-H-A2A", "-MCP", "-A2A")
|
| 426 |
+
for suffix in suffixes:
|
| 427 |
+
if task.endswith(suffix):
|
| 428 |
+
return task[: -len(suffix)]
|
| 429 |
+
return task
|
| 430 |
+
|
| 431 |
def build_series_data() -> Dict[str, Dict[str, Dict[str, List[float]]]]:
|
| 432 |
series: Dict[str, Dict[str, Dict[str, List[float]]]] = defaultdict(
|
| 433 |
lambda: defaultdict(lambda: defaultdict(list))
|
| 434 |
)
|
| 435 |
for task, arch, name in projects:
|
| 436 |
+
base_task = _base_task_name(task)
|
| 437 |
pdata = project_data.get(name, {})
|
| 438 |
for status in STATUS_ORDER:
|
| 439 |
by_model = pdata.get(status, {})
|
| 440 |
for model, vals in by_model.items():
|
| 441 |
+
series[base_task][status][model].extend(vals)
|
| 442 |
return series
|
| 443 |
|
| 444 |
def append_status_table(
|
|
|
|
| 538 |
for task in sorted(series_data.keys()):
|
| 539 |
sdata = series_data[task]
|
| 540 |
lines.append("")
|
| 541 |
+
lines.append(f"### {task} (aggregated across variants)")
|
| 542 |
append_status_table(lines, sdata, statuses)
|
| 543 |
append_status_comparison(
|
| 544 |
lines,
|
|
|
|
| 572 |
arch_model_data: Dict[str, Dict[str, Dict[str, List[float]]]],
|
| 573 |
out_dir: Path,
|
| 574 |
) -> None:
|
| 575 |
+
def write_report(title: str, chain: List[str], filename: str) -> None:
|
| 576 |
+
lines: List[str] = []
|
| 577 |
+
lines.append("# Token shifts across architectures")
|
| 578 |
+
lines.append("")
|
| 579 |
+
lines.append(f"Series: **{title}**")
|
| 580 |
+
lines.append("")
|
| 581 |
+
lines.append(
|
| 582 |
+
"Each table shows the absolute change (Δ) and the relative percentage change of the mean total tokens."
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
def render_pair(task_arch_data: Dict[str, Dict[str, List[float]]]) -> None:
|
| 586 |
+
arch_display = {
|
| 587 |
+
"Unknown": "Pure CrewAI",
|
| 588 |
+
"MCP": "MCP",
|
| 589 |
+
"A2A": "A2A",
|
| 590 |
+
"A2A_mix": "H-A2A",
|
| 591 |
+
}
|
| 592 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
header = f"| Model | {arch_display[chain[0]]} | {arch_display[chain[1]]} | Δ {arch_display[chain[1]]}-{arch_display[chain[0]]} |"
|
| 594 |
sep = "| --- | --- | --- | --- |"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
|
| 596 |
+
lines.append("")
|
| 597 |
+
lines.append(header)
|
| 598 |
+
lines.append(sep)
|
|
|
|
|
|
|
| 599 |
|
| 600 |
+
for model in MODEL_ORDER:
|
| 601 |
+
left_vals = task_arch_data.get(chain[0], {}).get(model, [])
|
| 602 |
+
right_vals = task_arch_data.get(chain[1], {}).get(model, [])
|
| 603 |
+
left_mean = float(np.mean(left_vals)) if left_vals else None
|
| 604 |
+
right_mean = float(np.mean(right_vals)) if right_vals else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 605 |
row = [
|
| 606 |
MODEL_LABELS.get(model, model),
|
| 607 |
+
"-" if left_mean is None else _fmt_number(left_mean),
|
| 608 |
+
"-" if right_mean is None else _fmt_number(right_mean),
|
| 609 |
+
_fmt_delta(right_mean, left_mean),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 610 |
]
|
| 611 |
+
lines.append("| " + " | ".join(row) + " |")
|
| 612 |
|
| 613 |
+
lines.append("")
|
| 614 |
+
lines.append("Project-level average (all models combined)")
|
| 615 |
+
lines.append("")
|
|
|
|
|
|
|
| 616 |
lines.append(
|
| 617 |
f"| Metric | {arch_display[chain[0]]} | {arch_display[chain[1]]} | Δ {arch_display[chain[1]]}-{arch_display[chain[0]]} |"
|
| 618 |
)
|
| 619 |
lines.append("| --- | --- | --- | --- |")
|
| 620 |
+
|
| 621 |
+
def _mean_all(arch: str) -> float:
|
| 622 |
+
combined: List[float] = []
|
| 623 |
+
for vals in task_arch_data.get(arch, {}).values():
|
| 624 |
+
combined.extend(vals)
|
| 625 |
+
return float(np.mean(combined)) if combined else None
|
| 626 |
+
|
| 627 |
+
left_all = _mean_all(chain[0])
|
| 628 |
+
right_all = _mean_all(chain[1])
|
| 629 |
lines.append(
|
| 630 |
+
"| "
|
| 631 |
+
+ " | ".join(
|
| 632 |
+
[
|
| 633 |
+
"Avg tokens (all models)",
|
| 634 |
+
"-" if left_all is None else _fmt_number(left_all),
|
| 635 |
+
"-" if right_all is None else _fmt_number(right_all),
|
| 636 |
+
_fmt_delta(right_all, left_all),
|
| 637 |
+
]
|
| 638 |
+
)
|
| 639 |
+
+ " |"
|
| 640 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
|
| 642 |
+
task_set = {t for t, _, _ in projects}
|
| 643 |
+
for task in sorted(task_set):
|
| 644 |
+
task_arch_data = arch_model_data.get(task, {})
|
| 645 |
+
arches = set(task_arch_data.keys())
|
| 646 |
+
if not task_arch_data:
|
| 647 |
+
continue
|
| 648 |
+
if not set(chain).issubset(arches):
|
| 649 |
+
continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
|
|
|
|
| 651 |
lines.append("")
|
| 652 |
+
lines.append(f"## {task}")
|
| 653 |
+
render_pair(task_arch_data)
|
| 654 |
|
| 655 |
+
out_path = out_dir / filename
|
| 656 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 657 |
+
out_path.write_text("\n".join(lines), encoding="utf-8")
|
| 658 |
+
print(f"saved markdown: {out_path}")
|
| 659 |
+
|
| 660 |
+
def write_a2a_to_h_a2a_report(filename: str) -> None:
|
| 661 |
+
lines: List[str] = []
|
| 662 |
+
lines.append("# Token shifts across architectures")
|
| 663 |
+
lines.append("")
|
| 664 |
+
lines.append("Series: **A2A → H-A2A**")
|
| 665 |
+
lines.append("")
|
| 666 |
+
lines.append(
|
| 667 |
+
"Each table shows the absolute change (Δ) and the relative percentage change of the mean total tokens."
|
| 668 |
+
)
|
| 669 |
+
|
| 670 |
+
def render_pair(
|
| 671 |
+
task_base: str,
|
| 672 |
+
left_arch_data: Dict[str, Dict[str, List[float]]],
|
| 673 |
+
right_arch_data: Dict[str, Dict[str, List[float]]],
|
| 674 |
+
) -> None:
|
| 675 |
+
right_label = "H-A2A"
|
| 676 |
+
header = f"| Model | A2A | {right_label} | Δ {right_label}-A2A |"
|
| 677 |
+
sep = "| --- | --- | --- | --- |"
|
| 678 |
lines.append("")
|
| 679 |
+
lines.append(header)
|
| 680 |
+
lines.append(sep)
|
| 681 |
+
|
| 682 |
+
for model in MODEL_ORDER:
|
| 683 |
+
left_vals = left_arch_data.get("A2A", {}).get(model, [])
|
| 684 |
+
right_vals: List[float] = []
|
| 685 |
+
for arch_vals in right_arch_data.values():
|
| 686 |
+
right_vals.extend(arch_vals.get(model, []))
|
| 687 |
+
left_mean = float(np.mean(left_vals)) if left_vals else None
|
| 688 |
+
right_mean = float(np.mean(right_vals)) if right_vals else None
|
| 689 |
+
row = [
|
| 690 |
+
MODEL_LABELS.get(model, model),
|
| 691 |
+
"-" if left_mean is None else _fmt_number(left_mean),
|
| 692 |
+
"-" if right_mean is None else _fmt_number(right_mean),
|
| 693 |
+
_fmt_delta(right_mean, left_mean),
|
| 694 |
+
]
|
| 695 |
+
lines.append("| " + " | ".join(row) + " |")
|
| 696 |
|
|
|
|
| 697 |
lines.append("")
|
| 698 |
+
lines.append("Project-level average (all models combined)")
|
| 699 |
+
lines.append("")
|
| 700 |
+
lines.append(f"| Metric | A2A | {right_label} | Δ {right_label}-A2A |")
|
| 701 |
+
lines.append("| --- | --- | --- | --- |")
|
| 702 |
+
|
| 703 |
+
def _mean_all(
|
| 704 |
+
arch_data: Dict[str, Dict[str, List[float]]], arch: str
|
| 705 |
+
) -> float:
|
| 706 |
+
combined: List[float] = []
|
| 707 |
+
for vals in arch_data.get(arch, {}).values():
|
| 708 |
+
combined.extend(vals)
|
| 709 |
+
return float(np.mean(combined)) if combined else None
|
| 710 |
+
|
| 711 |
+
left_all = _mean_all(left_arch_data, "A2A")
|
| 712 |
+
right_combined: List[float] = []
|
| 713 |
+
for arch_vals in right_arch_data.values():
|
| 714 |
+
for vals in arch_vals.values():
|
| 715 |
+
right_combined.extend(vals)
|
| 716 |
+
right_all = float(np.mean(right_combined)) if right_combined else None
|
| 717 |
lines.append(
|
| 718 |
+
"| "
|
| 719 |
+
+ " | ".join(
|
| 720 |
+
[
|
| 721 |
+
"Avg tokens (all models)",
|
| 722 |
+
"-" if left_all is None else _fmt_number(left_all),
|
| 723 |
+
"-" if right_all is None else _fmt_number(right_all),
|
| 724 |
+
_fmt_delta(right_all, left_all),
|
| 725 |
+
]
|
| 726 |
+
)
|
| 727 |
+
+ " |"
|
| 728 |
)
|
| 729 |
|
| 730 |
+
task_set = sorted({t for t, _, _ in projects})
|
| 731 |
+
for task in task_set:
|
| 732 |
+
task_arch_data = arch_model_data.get(task, {})
|
| 733 |
+
if not task_arch_data:
|
| 734 |
+
continue
|
| 735 |
+
if "A2A" not in task_arch_data or "A2A_mix" not in task_arch_data:
|
| 736 |
+
continue
|
| 737 |
+
|
| 738 |
+
left_arch_data = {"A2A": task_arch_data.get("A2A", {})}
|
| 739 |
+
right_arch_data = {"A2A_mix": task_arch_data.get("A2A_mix", {})}
|
| 740 |
+
|
| 741 |
+
lines.append("")
|
| 742 |
+
lines.append(f"## {task}")
|
| 743 |
+
|
| 744 |
+
render_pair(task, left_arch_data, right_arch_data)
|
| 745 |
+
|
| 746 |
+
out_path = out_dir / filename
|
| 747 |
+
out_dir.mkdir(parents=True, exist_ok=True)
|
| 748 |
+
out_path.write_text("\n".join(lines), encoding="utf-8")
|
| 749 |
+
print(f"saved markdown: {out_path}")
|
| 750 |
+
|
| 751 |
+
write_report(
|
| 752 |
+
"Pure CrewAI → MCP",
|
| 753 |
+
["Unknown", "MCP"],
|
| 754 |
+
"architecture_token_deltas_crewai_to_mcp.md",
|
| 755 |
+
)
|
| 756 |
+
write_report("MCP → A2A", ["MCP", "A2A"], "architecture_token_deltas_mcp_to_a2a.md")
|
| 757 |
+
write_a2a_to_h_a2a_report("architecture_token_deltas_a2a_to_h-a2a.md")
|
| 758 |
|
| 759 |
|
| 760 |
def generate_project_model_distribution_md(
|
|
|
|
| 882 |
out_dir: Path,
|
| 883 |
global_max: float,
|
| 884 |
) -> None:
|
| 885 |
+
if not HAS_MATPLOTLIB:
|
| 886 |
+
print("matplotlib not available; skip violin plots")
|
| 887 |
+
return
|
| 888 |
+
|
| 889 |
any_values = False
|
| 890 |
for status in STATUS_ORDER:
|
| 891 |
by_model = project_data.get(status, {})
|
|
|
|
| 980 |
def main() -> None:
|
| 981 |
part1_dir = Path(__file__).resolve().parent
|
| 982 |
details_csv = part1_dir / "task_token_statistics-DETAILS.csv"
|
| 983 |
+
if not details_csv.exists():
|
| 984 |
+
details_csv = (
|
| 985 |
+
part1_dir / "performance_reports" / "task_token_statistics-DETAILS.csv"
|
| 986 |
+
)
|
| 987 |
out_dir = part1_dir / "Violin"
|
| 988 |
|
| 989 |
+
projects, project_map = load_projects(details_csv)
|
|
|
|
|
|
|
|
|
|
| 990 |
|
| 991 |
project_data, arch_model_data, overall_status_values = load_all_token_data(
|
| 992 |
details_csv, project_map
|
| 993 |
)
|
| 994 |
|
| 995 |
+
export_violin_input_summary(projects, project_data, out_dir)
|
| 996 |
+
|
| 997 |
# Compute a shared y-axis maximum per task so that all architectures
|
| 998 |
# of the same task use the same vertical scale in their violin plots.
|
| 999 |
task_max_values: Dict[str, float] = {}
|