This notebook runs the analysis script that generates figures and CSVs for the stylized exercises.
If figures already exist in paper/figures/, it reuses them to keep builds fast.
import os, sys, json, subprocess, shutil
from pathlib import Path
from datetime import datetime
# Ensure package import works for subprocess
here = Path.cwd()
project_root = (here / '..' / '..').resolve()
src_path = (project_root / 'src').resolve()
figdir = (here / '..' / 'figures').resolve()
scripts_runner = (project_root / 'scripts' / 'run_analysis.py').resolve()
expected = [
'block1_bias_loss.png',
'block2_uncertainty_loss.png',
'block3_two_worker_welfare.png',
'block4_opt_tax_vs_sd.png',
'block4_welfare_vs_sd.png',
]
figdir.mkdir(parents=True, exist_ok=True)
missing = [f for f in expected if not (figdir / f).exists()]
missing# If any expected figure is missing, generate a lighter set to keep execution quick.
if missing:
env = os.environ.copy()
# Ensure the runner can import the local package
env['PYTHONPATH'] = str(src_path) + os.pathsep + env.get('PYTHONPATH', '')
cmd = [
sys.executable, str(scripts_runner),
'--outdir', str(figdir),
'--seed', '123',
'--grid', '81',
'--pop-n', '400',
'--opt-tax-grid', '21',
'--opt-sd-n', '3',
'--tax-n', '16',
]
print('Generating figures via:', ' '.join(cmd))
subprocess.run(cmd, check=True, env=env)
else:
print('Using existing figures in', figdir)
sorted(os.listdir(figdir))
# Display the figures inline
from IPython.display import display, Image
for f in expected:
path = figdir / f
if path.exists():
display(Image(filename=str(path)))
else:
print('Missing figure:', path)