#!/bin/bash
set -euo pipefail
cd /srv/home/gc-sdk/ipu-stack
while ! test -f artifacts/exchange-frontier-20260911/plots/index.html; do sleep 5; done
python3 - <<'PY'
import json
from pathlib import Path
root=Path('artifacts/exchange-frontier-20260911')
s=json.loads((root/'ordinary.json').read_text())
s['phases']=[p for p in s['phases'] if p['phase']==9]
(root/'ordinary-phase9.json').write_text(json.dumps(s,separators=(',',':')))
PY
python3 scripts/exchange-frontier.py artifacts/exchange-frontier-20260911/ordinary-phase9.json --output artifacts/exchange-frontier-20260911/ordinary-phase9-plots > artifacts/exchange-frontier-20260911/ordinary-phase9-sweep.log 2>&1
python3 - <<'PY'
import json
from pathlib import Path
root=Path('artifacts/exchange-frontier-20260911')
rows=json.loads((root/'plots/results.json').read_text())
extra=json.loads((root/'ordinary-phase9-plots/results.json').read_text())
for row in rows: row['widths']='selected'
for row in extra:
 row['configuration']+='-ordinary'
 row['widths']='ordinary'
combined=root/'combined'
combined.mkdir(exist_ok=True)
(combined/'results.json').write_text(json.dumps(rows+extra,indent=2)+'\n')
(combined/'manifest.json').write_text(json.dumps({'runs':[json.loads((root/p/'manifest.json').read_text()) for p in ['plots','ordinary-phase9-plots']]},indent=2)+'\n')
PY
python3 scripts/exchange-frontier.py artifacts/exchange-frontier-20260911/selected.json --output artifacts/exchange-frontier-20260911/combined --render-only
