-rwxr-xr-x 2150 cryptattacktester-20231020/isdsims.py raw
#!/usr/bin/env python3
import sys
import subprocess
import multiprocessing
NKWlist = []
for N in range(16,130,2):
problemparams = subprocess.run(['./problemparams','problem=uniformmatrix','N=%d'%N],capture_output=True,universal_newlines=True,check=True)
for line in problemparams.stdout.splitlines():
line = line.split()
assert len(line) == 3
assert line[0] == 'problemparams'
assert line[1] == 'problem=uniformmatrix'
NKW = line[2]
NKWlist += [NKW]
todo = []
for NKW in NKWlist:
for A in (
'attack=isd0,P=0,L=0,FW=1',
'attack=isd0,L=0,FW=1',
'attack=isd0,FW=1',
'attack=isd1,FW=1',
'attack=isd2,CP=1,CS=0,FW=1',
'attack=isd2,CP=0,CS=1,FW=1',
):
for IRE in ('I=1',),('I=2','RE=1'),('I=4','RE=4'):
todo += [(NKW,A,IRE)]
def handle(task):
NKW,A,IRE = task
searchparams = subprocess.run(['./searchparams','problem=uniformmatrix',NKW,A]+list(IRE),capture_output=True,universal_newlines=True,check=True)
if len(searchparams.stdout) == 0:
return task,None
bestparams = searchparams.stdout.splitlines()[-1]
bestparams = bestparams.split()
assert bestparams[0] == 'searchparams'
assert bestparams[1] == 'problem=uniformmatrix'
assert bestparams[2] == NKW
assert bestparams[3] == A.split(',')[0]
Q = bestparams[4]
result = 'trying %s %s %s\n' % (NKW,A,Q)
cost = subprocess.run(['./circuitcost','problem=uniformmatrix',NKW,A,Q],capture_output=True,universal_newlines=True,check=True)
result += cost.stdout
prob = subprocess.run(['./circuitprob','problem=uniformmatrix',NKW,A,Q,'trialfactor=100000','probfactor=100'],capture_output=True,universal_newlines=True,check=True)
result += prob.stdout
return task,result
results = {}
printpos = 0
def maybeprint():
global printpos
while printpos < len(todo):
task = todo[printpos]
if task not in results: break
result = results[task]
if result is not None:
sys.stdout.write(result)
sys.stdout.flush()
printpos += 1
with multiprocessing.Pool() as p:
for task,result in p.imap_unordered(handle,reversed(todo),chunksize=1):
results[task] = result
maybeprint()