# poirier.py -- counts the bistochastic forms of the real Hadamard matrix had16.3 (McKay's library, class 3 of order 16), # i.e. the vectors b in T^16, b_0 = 1, with |(Hb)_i| = 4 for all i, found by the alternating iteration # u = phase(Hb), b -> phase(H^t u), from many random starts, in batches. Distinct forms are counted modulo the global # phase and complex conjugation, via rounded phases. Writes progress to poirier-out/log-.txt and the distinct forms # (phases, in turns) to poirier-out/forms-.txt, every 10 minutes and at the end. # Usage: /usr/bin/python3 poirier.py had163.txt WORKERS HOURS (e.g. 3 3.5) import sys, os, time, numpy as np from multiprocessing import Process H=np.loadtxt(sys.argv[1]).astype(float); N=len(H); W=int(sys.argv[2]); HOURS=float(sys.argv[3]) os.makedirs('poirier-out',exist_ok=True) def worker(w): rng=np.random.default_rng(1000+w); t0=time.time(); last=t0 seen={}; starts=0; conv=0; B=4096 log=open(f'poirier-out/log-{w}.txt','a') def dump(): with open(f'poirier-out/forms-{w}.txt','w') as f: for k,v in seen.items(): f.write(' '.join(str(x) for x in v)+'\n') while time.time()-t0600: last=time.time(); dump() log.write(f"{(last-t0)/3600:.2f} h starts {starts} converged {conv} distinct {len(seen)}\n"); log.flush() dump(); log.write(f"END starts {starts} converged {conv} distinct {len(seen)}\n"); log.close() if __name__=='__main__': ps=[Process(target=worker,args=(w,)) for w in range(W)] for p in ps: p.start() for p in ps: p.join() # merge allk=set() for w in range(W): for l in open(f'poirier-out/forms-{w}.txt'): allk.add(l.strip()) with open('poirier-out/summary.txt','w') as f: for w in range(W): f.write(open(f'poirier-out/log-{w}.txt').read().splitlines()[-1]+'\n') f.write(f"distinct forms over all workers: {len(allk)}\n") print(open('poirier-out/summary.txt').read())