76 lines
4.3 KiB
Python
76 lines
4.3 KiB
Python
"""Finish display only from the retained successful join; no repeated scientific step."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import math
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
import time
|
|
from s2_recovery_supervisor import save,supervise
|
|
|
|
|
|
def checked(p,h):
|
|
raw=Path(p).read_bytes()
|
|
if hashlib.sha256(raw).hexdigest()!=h:raise ValueError('Existing evidence changed')
|
|
return json.loads(raw)
|
|
|
|
|
|
def worker(root):
|
|
start=time.process_time();scope=json.loads((root/'display-scope.json').read_text())
|
|
for p,h in scope['inputs'].items():checked(p,h)
|
|
rows=json.loads((root/'joined-parts.json').read_text());c=json.loads((root/'contract.json').read_text())
|
|
if len(rows)!=617 or len({r['case'] for r in rows})!=617:raise ValueError('Join roster')
|
|
arms=c['arms']
|
|
for r in rows:
|
|
for arm in arms:
|
|
m=r['oracle_relative_l2'][arm]
|
|
if m['reason'] is not None or not isinstance(m['value'],(float,int)) or not math.isfinite(m['value']):
|
|
raise ValueError('Undefined/non-numeric source metric')
|
|
canonical_path=next(p for p in c['source_sha256'] if p.endswith('/canonical-preparation.json'))
|
|
canonical=checked(canonical_path,c['source_sha256'][canonical_path]);by_case={r['case']:r for r in rows};endpoints=[]
|
|
for row in canonical['parts']:
|
|
m=checked(row['result_path'],row['result_sha256']);r=by_case[row['case']]
|
|
endpoints.append(dict(case=row['case'],source_result=row['result_path'],source_sha256=row['result_sha256'],
|
|
full_tet_T_end=m['full_tet_T_end'],raw_VTU_T_end=m['full_VTU_T_end'],query_T_max=m['query_T_max'],
|
|
log_first_printed_time_s=r['log_first_printed_time_s'],log_first_printed_fill_percent=r['log_first_printed_fill_percent'],
|
|
log_printed_100_time_s=r['log_printed_100_time_s'],log_explicit_switch_rows=r['log_explicit_switch_rows']))
|
|
save(root/'endpoint-provenance.json',endpoints)
|
|
import matplotlib
|
|
matplotlib.use('Agg')
|
|
import matplotlib.pyplot as plt
|
|
fig,axes=plt.subplots(1,3,figsize=(12,3.7),layout='constrained')
|
|
for ax,arm in zip(axes,arms):
|
|
ax.scatter([r['log_max_linearity_deviation_pp'] for r in rows],
|
|
[r['oracle_relative_l2'][arm]['value'] for r in rows],s=10,alpha=.5)
|
|
ax.set(xlabel='LOG volume deviation (percentage points)',ylabel='Per-part time relative L2',title=arm)
|
|
fig.suptitle('617 exact-case joins: descriptive, distinct LOG-volume and tet-time quantities')
|
|
fig.savefig(root/'oracle-log-join.png',dpi=170);plt.close(fig)
|
|
save(root/'completion.json',dict(status='EXACT_CASE_JOIN_AND_DISPLAY_COMPLETE',parts=617,log_only=7,
|
|
first_guard_failure_retained=True,first_failure_stage='display: relative_l2 is a metric object with value/reason',
|
|
existing_join_not_recomputed=True,new_decodes=0,new_fits=0,new_predictions=0,
|
|
new_significance_tests=0,worker_CPU_s=time.process_time()-start,
|
|
limitations=['Matching case IDs does not equate the volume domains or time endpoints.',
|
|
'LOG ordinate deviation is volume percentage points; oracle ordinate is time relative L2.',
|
|
'No subtraction as ordering-error share, no floor or causality claim.'],
|
|
output_sha256={p.name:hashlib.sha256(p.read_bytes()).hexdigest() for p in root.iterdir()
|
|
if p.name in ('joined-parts.json','log-only-parts.json','endpoint-provenance.json','oracle-log-join.png')}))
|
|
return 0
|
|
|
|
|
|
def guard(root):
|
|
original=json.loads((root/'guard-result.json').read_text());spent=original['worker']['cpu_seconds']
|
|
os.sched_setaffinity(0,[24])
|
|
r=supervise([sys.executable,__file__,str(root),'--worker'],root/'display-guard','worker',dict(
|
|
total_cpu_seconds=60-spent,job_cpu_seconds=60-spent,job_wall_seconds=120,
|
|
tree_rss_bytes=1073741824,disk_bytes=10485760,max_processes=1),poll=.2)
|
|
save(root/'display-guard-result.json',dict(worker=r,first_worker_CPU_s=spent,
|
|
cumulative_join_CPU_s=spent+r['cpu_seconds'],join_cap_CPU_s=60,
|
|
cumulative_LOG_task_CPU_s=original['cumulative_LOG_task_CPU_s']+r['cpu_seconds'],LOG_cap_CPU_s=3600))
|
|
return 0 if r['status']=='PASS' else 1
|
|
|
|
|
|
if __name__=='__main__':
|
|
p=argparse.ArgumentParser();p.add_argument('root',type=Path);p.add_argument('--worker',action='store_true');a=p.parse_args()
|
|
raise SystemExit(worker(a.root) if a.worker else guard(a.root))
|