#!/usr/bin/env python3
"""Render the preregistered EXP-DECODE-BATCH-GRID schematic."""

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np

ROOT = Path(__file__).resolve().parent


def main() -> None:
    fig, axes = plt.subplots(1, 2, figsize=(9.6, 4.0))

    ax = axes[0]
    repeats = np.array([3.7, 5.0, 6.4])
    ax.scatter([1, 2, 3], repeats, color="#d95f02", s=45, label="old/possible repeats")
    ax.axhspan(4.1, 4.6, color="#1b9e77", alpha=0.18, label="stable target band")
    ax.axhline(np.median(repeats), color="#7570b3", ls="--", label="median")
    ax.set(xlabel="TP4/b2 fresh-process repeat", ylabel="execute wall (ms)")
    ax.set_title("A. Stability gate before curve fit")
    ax.set_xticks([1, 2, 3])
    ax.legend(frameon=False, fontsize=8)

    ax = axes[1]
    labels = ["TP2", "TP4", "TP1"]
    real = [4.305, 4.449, 4.876]
    sim = [5.12, 5.86, 5.49]
    corrected = [4.7, 4.9, 5.3]
    x = np.arange(3)
    width = 0.25
    ax.bar(x - width, real, width, label="real", color="#1b9e77")
    ax.bar(x, sim, width, label="current sim", color="#d95f02")
    ax.bar(x + width, corrected, width, label="target corrected", color="#7570b3")
    ax.set_xticks(x, labels)
    ax.set_ylabel("BC-8 TPOT (ms)")
    ax.set_title("B. Complete-order recovery gate")
    ax.legend(frameon=False, fontsize=8)

    fig.suptitle("EXP-DECODE-BATCH-GRID preregistered figure prototype")
    fig.tight_layout()
    fig.savefig(ROOT / "figure-prototype.png", dpi=180)
    fig.savefig(ROOT / "figure-prototype.svg")


if __name__ == "__main__":
    main()
