from pathlib import Path import subprocess,json,time,resource,hashlib,sys p=Path('work/statistic-986');out=Path('outputs');records=[] start=resource.getrusage(resource.RUSAGE_CHILDREN) def execute(label,script,args): before=resource.getrusage(resource.RUSAGE_CHILDREN);begin=time.monotonic() r=subprocess.run([sys.executable,str(out/script),*args],capture_output=True,text=True) after=resource.getrusage(resource.RUSAGE_CHILDREN);cpu=(after.ru_utime+after.ru_stime)-(before.ru_utime+before.ru_stime) record={'label':label,'exit_code':r.returncode,'wall_seconds':time.monotonic()-begin,'cpu_seconds':cpu,'max_rss_bytes':after.ru_maxrss, 'stdout_sha256':hashlib.sha256(r.stdout.encode()).hexdigest()} records.append(record);(p/(label+'.stderr.txt')).write_text(r.stderr) return r,record r,record=execute('producer','transfer986-producer.py',['outputs/transfer986-input.json']) (out/'transfer986-result.json').write_text(r.stdout) print(record);assert r.returncode==0,r.stderr v=json.loads(r.stdout);print({'complete':v['complete'],'eligible':v['eligible'],'template_strict':v['template_strict'],'H':v['H'], 'per_window':[{'j':x['index'],'a':x['a'],'available':x['available'],'L':x.get('L'),'uniform':x.get('uniform',{}).get('C'),'template':x.get('template',{}).get('C'),'control_strict':x.get('control_strict')} for x in v['rows']]}) r,record=execute('checker','transfer986-checker.py',['outputs/transfer986-input.json','outputs/transfer986-result.json']) (out/'transfer986-check.out').write_text(r.stdout);print(record);print(r.stdout);assert r.returncode==0,r.stderr # The mutations fail early and are retained as separate files in work. Never # change the published producer result to obtain a passing check. import copy mutants={} t=copy.deepcopy(v);t['rows'].pop();mutants['missing-window']=t t=copy.deepcopy(v);t['rows'][0]['controls'][0]['weights'][0]+=1;mutants['wrong-multiset']=t t=copy.deepcopy(v);t['rows'][0]['template']['C']+=1;mutants['wrong-capacity']=t t=copy.deepcopy(v);t['rows'][0]['controls'][0]['argmax'][0]=101;mutants['invalid-phase']=t for name,target in mutants.items(): path=p/(name+'.json');path.write_text(json.dumps(target)) r,record=execute(name,'transfer986-checker.py',['outputs/transfer986-input.json',str(path)]) (p/(name+'.out')).write_text(r.stdout);print(record);assert r.returncode!=0,name now=resource.getrusage(resource.RUSAGE_CHILDREN) assert (now.ru_utime+now.ru_stime)-(start.ru_utime+start.ru_stime)<60,'totalCPU budget exceeded' now=resource.getrusage(resource.RUSAGE_CHILDREN) observed={'python_version':sys.version.split()[0],'platform':sys.platform,'one_thread_stdlib':True, 'producer_and_checks_cpu_seconds':(now.ru_utime+now.ru_stime)-(start.ru_utime+start.ru_stime), 'max_rss_bytes':now.ru_maxrss,'records':records,'controls_rejected':list(mutants)} (out/'transfer986-observed-resources.json').write_text(json.dumps(observed,indent=2)+'\n');print({'observed_totals':observed})