"""Compare selected compatible run curves without seed-range shading.""" import argparse import json from pathlib import Path import sys ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT/'src')) from experiments_codebase.paths import paths import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt def main(): p=argparse.ArgumentParser(description=__doc__);p.add_argument('--config',type=Path,required=True);p.add_argument('--out',type=Path,required=True);a=p.parse_args() if not a.out.resolve().is_relative_to(paths()['results'].resolve()):raise ValueError('Plots belong under shared results') a.out.mkdir(parents=True,exist_ok=True);cfg=json.loads(a.config.read_text()) for metric in ('loss','accuracy'): fig,ax=plt.subplots(figsize=(9,4));any_curve=False for item in cfg['runs']: if not item.get('enabled',True):continue folder=Path(item['directory']);curve=json.loads((folder/'curve.json').read_text());split=cfg.get('split','development') points=[v for v in curve if metric in v[split]] if points:ax.plot([v['main_forwards'] for v in points],[v[split][metric] for v in points],label=item['label']);any_curve=True if any_curve: ax.set(xlabel='Cumulative main forwards',ylabel=metric,title=cfg.get('title',''));ax.legend();ax.grid(alpha=.2);fig.tight_layout();fig.savefig(a.out/f'{metric}_curve.png',dpi=180) plt.close(fig) (a.out/'plot_config.json').write_text(json.dumps(cfg,indent=2)) if __name__=='__main__':main()