"""Millennium Lab round 2 poster: three measured results, one image.
Numbers verified from ~/workspace/millennium-lab/data/ on 2026-11-20:
  NS Kida-Pelz enstrophy growth: 14.23 (32^3), 18.29 (48^3), 18.86 (64^3)
  YM torelon mass: 2.6731 +- 0.7993 (beta 2.2), 1.8602 +- 0.2302 (beta 2.3),
    1.7393 +- 0.1361 (beta 2.4)
  P vs NP DF-COMP: greedy 0.5659 s, exhaustive 3-node estimate 567586 s,
    44/44 brute-force agreement, 2599 candidates max.
Style: bone/paper, ink, brass single accent. 1080x1350 portrait.
"""
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np

PAPER = "#f7f2e7"
INK = "#211d17"
MUTED = "#6b6257"
BRASS = "#9a7b2d"
LINE = "#d8cdb4"
CARD = "#fffdf6"

plt.rcParams["font.family"] = "DejaVu Sans"
plt.rcParams["axes.edgecolor"] = LINE

fig = plt.figure(figsize=(10.8, 13.5), dpi=100)
fig.patch.set_facecolor(PAPER)

# Header
fig.text(0.06, 0.972, "MILLENNIUM LAB  |  ROUND 2", fontsize=13, color=BRASS,
         fontweight="bold", va="top")
fig.text(0.06, 0.950, "Three measured results", fontsize=30, color=INK,
         fontweight="bold", va="top", family="DejaVu Serif")
fig.text(0.06, 0.910, "November 20, 2026. Nothing is solved.",
         fontsize=13, color=MUTED, va="top")
fig.text(0.06, 0.892, "Every number below was measured on real runs, receipted, hash-chained. 43 receipts.",
         fontsize=13, color=MUTED, va="top")
fig.add_artist(plt.Line2D([0.06, 0.94], [0.878, 0.878], color=BRASS,
                          linewidth=2, transform=fig.transFigure))

# Panel 1: Navier-Stokes saturation
ax1 = fig.add_axes([0.10, 0.705, 0.80, 0.145])
ax1.set_facecolor(CARD)
grid = np.array([32, 48, 64])
growth = np.array([14.23, 18.29, 18.86])
ax1.plot(grid, growth, color=BRASS, linewidth=3, marker="o", markersize=11,
         markerfacecolor=BRASS, markeredgecolor=INK, markeredgewidth=1)
for x, y in zip(grid, growth):
    ax1.annotate(f"{y}", (x, y), textcoords="offset points", xytext=(0, 14),
                 ha="center", fontsize=13, fontweight="bold", color=INK)
ax1.set_xlim(26, 70)
ax1.set_ylim(10, 22)
ax1.set_xticks([32, 48, 64])
ax1.set_xticklabels(["32\u00b3", "48\u00b3", "64\u00b3"], fontsize=11)
ax1.set_ylabel("Enstrophy growth", fontsize=11, color=MUTED)
ax1.set_title("1  |  NAVIER-STOKES: THE BLOWUP THAT WASN'T",
              fontsize=13, color=INK, fontweight="bold", loc="left", pad=10)
ax1.text(0.0, -0.30, "Kida-Pelz growth saturates with resolution: 14.23, 18.29, 18.86.\n"
         "It stayed smooth at every grid. No blowup observed.",
         transform=ax1.transAxes, fontsize=11.5, color=MUTED, va="top")
ax1.grid(True, color=LINE, linewidth=0.7, alpha=0.7)
ax1.spines["top"].set_visible(False)
ax1.spines["right"].set_visible(False)

# Panel 2: Yang-Mills torelon
ax2 = fig.add_axes([0.10, 0.450, 0.80, 0.145])
ax2.set_facecolor(CARD)
beta = np.array([2.2, 2.3, 2.4])
tor = np.array([2.6731, 1.8602, 1.7393])
err = np.array([0.7993, 0.2302, 0.1361])
ax2.errorbar(beta, tor, yerr=err, fmt="o", color=BRASS, ecolor=BRASS,
             elinewidth=2, capsize=7, capthick=2, markersize=11,
             markerfacecolor=BRASS, markeredgecolor=INK, markeredgewidth=1)
for x, y in zip(beta, tor):
    ax2.annotate(f"{y:.2f}", (x, y), textcoords="offset points", xytext=(0, 14),
                 ha="center", fontsize=13, fontweight="bold", color=INK)
ax2.set_xlim(2.12, 2.48)
ax2.set_ylim(0, 4.2)
ax2.set_xticks([2.2, 2.3, 2.4])
ax2.set_xticklabels(["\u03b2 2.2", "\u03b2 2.3", "\u03b2 2.4"], fontsize=11)
ax2.set_ylabel("Torelon mass", fontsize=11, color=MUTED)
ax2.set_title("2  |  YANG-MILLS: THE GAP THAT STAYS NONZERO",
              fontsize=13, color=INK, fontweight="bold", loc="left", pad=10)
ax2.text(0.0, -0.30, "Torelon mass at three lattice spacings, 8\u2074 SU(2). Nonzero at\n"
         "every spacing. A hint toward a continuum gap, not a proof.",
         transform=ax2.transAxes, fontsize=11.5, color=MUTED, va="top")
ax2.grid(True, color=LINE, linewidth=0.7, alpha=0.7)
ax2.spines["top"].set_visible(False)
ax2.spines["right"].set_visible(False)

# Panel 3: P vs NP greedy vs exhaustive (log scale)
ax3 = fig.add_axes([0.10, 0.195, 0.80, 0.145])
ax3.set_facecolor(CARD)
labels = ["Greedy search\n(measured)", "Exhaustive 3-node\n(estimated)"]
vals = [0.5659, 567586.0]
bars = ax3.bar([0, 1], vals, width=0.55, color=[BRASS, "#c9b98a"],
               edgecolor=INK, linewidth=1)
ax3.set_yscale("log")
ax3.set_xticks([0, 1])
ax3.set_xticklabels(labels, fontsize=11)
ax3.set_ylabel("Seconds (log scale)", fontsize=11, color=MUTED)
ax3.set_title("3  |  P vs NP: THE FRAGMENT THAT FALLS TO GREEDY",
              fontsize=13, color=INK, fontweight="bold", loc="left", pad=10)
ax3.annotate("0.57 s", (0, 0.5659), textcoords="offset points", xytext=(0, 10),
             ha="center", fontsize=13, fontweight="bold", color=INK)
ax3.annotate("567,586 s  (6.6 days)", (1, 567586.0),
             textcoords="offset points", xytext=(0, 10),
             ha="center", fontsize=13, fontweight="bold", color=INK)
ax3.text(0.0, -0.30, "Defeater-free fragment decided in polynomial time. 2,599 candidates\n"
         "max, 44 of 44 agreement with brute force. No separation claimed.",
         transform=ax3.transAxes, fontsize=11.5, color=MUTED, va="top")
ax3.set_ylim(0.1, 3000000)
ax3.grid(True, color=LINE, linewidth=0.7, alpha=0.7, axis="y")
ax3.spines["top"].set_visible(False)
ax3.spines["right"].set_visible(False)

# Footer
fig.text(0.06, 0.055, "neuruhai.github.io/neuruh-demos/millennium-lab  |  Lab v2.0, 43 receipts, chain valid",
         fontsize=11, color=MUTED, va="bottom")
fig.text(0.06, 0.028, "Hodge: group-level exponential sequence formalized in Lean, 9 theorems, 0 sorries.",
         fontsize=11, color=MUTED, va="bottom")

out = "/home/hatch/workspace/millennium-lab/poster/millennium-round2-poster.png"
fig.savefig(out, facecolor=PAPER)
print("wrote", out)
