#!/usr/bin/env python3 import argparse,json,pathlib,hashlib,torch A=pathlib.Path(__file__).resolve().parent p=argparse.ArgumentParser();p.add_argument('--left',required=True);p.add_argument('--right',required=True);args=p.parse_args();torch.set_num_threads(2) paths=[A/'runs'/n/'campaign/run/trace.pt' for n in (args.left,args.right)];traces=[torch.load(p,map_location='cpu',weights_only=True) for p in paths];a,b=traces unequal=[];diagnostics={} for k in a: if k not in b or a[k].dtype!=b[k].dtype or a[k].shape!=b[k].shape or not torch.equal(a[k].contiguous().reshape(-1).view(torch.uint8),b[k].contiguous().reshape(-1).view(torch.uint8)): unequal.append(k) if k in b and a[k].shape==b[k].shape:diagnostics[k]={'max_abs':float((a[k].double()-b[k].double()).abs().max()),'unequal_values':int((a[k]!=b[k]).sum())} r={'left':args.left,'right':args.right,'trace_sha256':[hashlib.sha256(p.read_bytes()).hexdigest() for p in paths],'tensor_keys':len(a),'keysets_equal':a.keys()==b.keys(),'all_bitwise_equal':a.keys()==b.keys() and not unequal,'unequal_keys':unequal,'diagnostics':diagnostics,'scope':'Measured native same-seed same-protocol traces only; not a promise of determinism elsewhere. No new physical steps.'};out=A/(args.left+'--'+args.right+'-comparison.json');out.write_text(json.dumps(r,indent=2)+'\n');print(r)