SPB Git

spb/wp24_uqo

Public
3.9 KB · 74 lines python
1"""Phase B: exact replication of Restrepo (2025) Propositions 1-6 in the finite-task CES economy.23Outputs: results/data/benchmark.csv, results/figures/fig01_benchmark.{pdf,png}, results/tables/tab01_benchmark.tex4"""5import os6import sys78import numpy as np9import pandas as pd1011sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))12from agi_ge.tasks import restrepo_benchmark  # noqa: E4021314ROOT = os.path.join(os.path.dirname(__file__), "..")15NU = [0.3, 0.25, 0.25, 0.2, 0, 0]16GAMMA = [0, 0, 0, 0, 0.05, 0.05]17SKILL = [0, 0, 1, 1, 0, 1]18ALPHA = np.array([1.0, 2.0, 4.0, 8.0, 3.0, 6.0])19H = [0.6, 0.4]20NAMES = ["task 1 (L, alpha=1)", "task 2 (L, alpha=2)", "task 3 (H, alpha=4)", "task 4 (H, alpha=8)", "accessory L (alpha=3)", "accessory H (alpha=6)"]2122Qg = np.concatenate([[0.0], np.logspace(-2, 5, 120)])23sols = restrepo_benchmark(NU, GAMMA, SKILL, -1.0, ALPHA, H, Qg)24rows = []25for Q, s in zip(Qg, sols):26    rows.append(dict(Q=Q, Y=s["Y"], A=s["A"], wL=s["w"][0], wH=s["w"][1], labor_share=s["labor_share"],27                     compute_share=s["compute_share"], wage_bill=float(np.sum(s["w"] * np.array(H))),28                     **{f"L{i+1}": s["L"][i] for i in range(6)}, **{f"Q{i+1}": s["Q"][i] for i in range(6)}))29df = pd.DataFrame(rows)30os.makedirs(os.path.join(ROOT, "results", "data"), exist_ok=True)31df.to_csv(os.path.join(ROOT, "results", "data", "benchmark.csv"), index=False)3233# --- figure34import matplotlib35matplotlib.use("Agg")36import matplotlib.pyplot as plt3738plt.rcParams.update({"font.size": 9, "axes.spines.top": False, "axes.spines.right": False})39fig, ax = plt.subplots(2, 2, figsize=(7.2, 5.2))40d = df[df.Q > 0]41Alim = d.A.iloc[-1]42ax[0, 0].plot(d.Q, d.Y, color="#1f3b73")43ax[0, 0].plot(d.Q, Alim * (d.Q + d.wage_bill.iloc[-1] / Alim), ls="--", color="#999999", label=r"$A(Q+\sum\widetilde{\mathrm{CEU}}H)$")44ax[0, 0].set_xscale("log"); ax[0, 0].set_yscale("log"); ax[0, 0].set_title("Output $Y$ (log-log)"); ax[0, 0].legend(frameon=False)45ax[0, 1].plot(d.Q, d.A, color="#1f3b73", label="$A$ (price of compute)")46ax[0, 1].axhline(Alim, ls=":", color="#999999")47ax[0, 1].set_xscale("log"); ax[0, 1].set_title("Price of compute $A$"); ax[0, 1].legend(frameon=False)48ax[1, 0].plot(d.Q, d.wL, color="#c0392b", label="$w_L$")49ax[1, 0].plot(d.Q, d.wH, color="#1f3b73", label="$w_H$")50ax[1, 0].plot(d.Q, d.A * 2, ls="--", color="#c0392b", alpha=.5, label=r"$A\cdot\widetilde{\mathrm{CEU}}(L)=2A$")51ax[1, 0].plot(d.Q, d.A * 8, ls="--", color="#1f3b73", alpha=.5, label=r"$A\cdot\mathrm{CEU}(H)=8A$")52ax[1, 0].set_xscale("log"); ax[1, 0].set_title("Wages"); ax[1, 0].legend(frameon=False, fontsize=7)53ax[1, 1].plot(d.Q, d.labor_share, color="#c0392b", label="labor share")54ax[1, 1].plot(d.Q, d.compute_share, color="#1f3b73", label="compute share")55ax[1, 1].set_xscale("log"); ax[1, 1].set_title("Factor shares"); ax[1, 1].legend(frameon=False)56for a in ax.ravel():57    a.set_xlabel("compute endowment $Q$")58fig.tight_layout()59os.makedirs(os.path.join(ROOT, "results", "figures"), exist_ok=True)60for ext in ("pdf", "png"):61    fig.savefig(os.path.join(ROOT, "results", "figures", f"fig01_benchmark.{ext}"), dpi=200)6263# --- table64sel = df[df.Q.isin([0.0]) | np.isclose(np.log10(df.Q.replace(0, np.nan)), np.round(np.log10(df.Q.replace(0, np.nan))))]65sel = sel.drop_duplicates("Q")66os.makedirs(os.path.join(ROOT, "results", "tables"), exist_ok=True)67with open(os.path.join(ROOT, "results", "tables", "tab01_benchmark.tex"), "w") as f:68    f.write("\\begin{tabular}{@{}rrrrrrrr@{}}\n\\toprule\n$Q$ & $Y$ & $A$ & $w_L$ & $w_H$ & $w_L/A$ & $w_H/A$ & labor share\\\\\n\\midrule\n")69    for _, r in sel.iterrows():70        wa = (r.wL / r.A, r.wH / r.A) if r.A > 0 else (np.nan, np.nan)71        f.write(f"{r.Q:g} & {r.Y:.4f} & {r.A:.4f} & {r.wL:.4f} & {r.wH:.4f} & {wa[0]:.2f} & {wa[1]:.2f} & {r.labor_share:.4f}\\\\\n".replace("nan", "--"))72    f.write("\\bottomrule\n\\end{tabular}\n")73print(df.tail(3).to_string())74
Files · f7215f55e72789efa8efb849ec6020a1edb0a939
Menu

Theme