File size: 810 Bytes
b48dd06 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #!/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)
|