#!/usr/bin/env python3 import glob, json, numpy as np def coerce_gates(g): out = {} for k,v in (g or {}).items(): if isinstance(v, str): lv = v.strip().lower() out[k] = lv in ('true','1','yes') else: out[k] = bool(v) return out logs_path = sorted(glob.glob('experiments/*_logs.json'))[-1] phi_path = sorted(glob.glob('experiments/*_phi_best.npy'))[-1] logs = json.load(open(logs_path)) phi = np.load(phi_path) for entry in logs[0]: entry['gates'] = coerce_gates(entry.get('gates')) if entry.get('accepted') and 'candidate_array' not in entry: entry['candidate_array'] = phi.tolist() fixed = logs_path.replace('_logs.json','_logs.fixed.json') with open(fixed,'w') as fh: json.dump(logs, fh, indent=2) print("Wrote", fixed)