#!/usr/bin/env python3
"""Render the preregistered Qwen235 collective-profile ablation layout."""

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np


OUT = Path(__file__).with_name("qwen235-collective-ablation-mock.png")


def main() -> None:
    configs = ["TP4 / EP1", "TP8 / EP8"]
    real_tpot = np.array([21.0442, 27.9942])
    current_frontier_tpot = np.array([87.7735, 61.5878])

    fig, (ax0, ax1) = plt.subplots(1, 2, figsize=(10.8, 4.4))
    x = np.arange(len(configs))
    width = 0.34
    ax0.bar(
        x - width / 2,
        real_tpot,
        width,
        color="#4c78a8",
        label="Frozen real",
    )
    ax0.bar(
        x + width / 2,
        current_frontier_tpot,
        width,
        color="#e45756",
        label="A0 current Frontier",
    )
    for index in x:
        ax0.text(
            index,
            max(real_tpot[index], current_frontier_tpot[index]) + 4,
            "A1 measured-profile\nresult: TBD",
            ha="center",
            va="bottom",
            fontsize=8,
            color="#222222",
        )
    ax0.set_xticks(x, configs)
    ax0.set_ylim(0, 112)
    ax0.set_ylabel("Fixed-PD mean TPOT (ms)")
    ax0.set_title("A. Does A1 reverse the simulated TP margin?")
    ax0.legend(frameon=False, fontsize=8)
    ax0.grid(axis="y", alpha=0.25)

    outcomes = ["A0 current", "A1 flips\nto TP4", "A1 stays\nat TP8"]
    regret = [33.0, 0.0, 33.0]
    colors = ["#e45756", "#54a24b", "#f2cf5b"]
    bars = ax1.bar(outcomes, regret, color=colors, width=0.68)
    ax1.axhline(10.0, color="#222222", linestyle="--", linewidth=1.2, label="10% gate")
    ax1.bar_label(bars, labels=["33%", "0%", "33%"], padding=3, fontsize=9)
    ax1.set_ylim(0, 42)
    ax1.set_ylabel("Real TPOT selection regret (%)")
    ax1.set_title("B. Preregistered decision outcomes")
    ax1.legend(frameon=False, fontsize=8)
    ax1.grid(axis="y", alpha=0.25)

    fig.suptitle(
        "SCHEMATIC / preregistered layout — A1 values are not yet measured",
        fontsize=11,
    )
    fig.tight_layout()
    fig.savefig(OUT, dpi=180, bbox_inches="tight")
    print(OUT)


if __name__ == "__main__":
    main()
