"""Inspect the saved local run and exercise selection refusals without retraining.""" import argparse import json from pathlib import Path import shutil import tempfile import run_jobs as job HERE = Path(__file__).resolve().parent def inspect(): receipt = json.loads((HERE/'recorded-selection.json').read_text()) selected = job.select(HERE/'recorded-runs', receipt['run_id'], receipt['record_sha256']) folder = HERE/'recorded-runs'/receipt['run_id'] record = json.loads((folder/'run.json').read_text()) if record['launcher_sha256'] != job.digest((HERE/'run_jobs.py').read_bytes()): raise ValueError('current launcher differs from the recorded execution source') refusals = {} with tempfile.TemporaryDirectory() as tmp: runs = Path(tmp)/'runs' shutil.copytree(HERE/'recorded-runs', runs) artifact = runs/receipt['run_id']/'evaluation.json' artifact.write_bytes(artifact.read_bytes()+b'\n') for name, run_id in (('edited_report', receipt['run_id']), ('mutable_alias', 'latest')): try: job.select(runs, run_id, receipt['record_sha256']) except ValueError as error: refusals[name] = str(error) else: raise AssertionError(name+' was accepted') return {'execution_mode':'inspection of a saved local CPU validation run; no new training', 'selected':selected, 'transitions':record['transitions'], 'returncode':record['returncode'], 'refusals':refusals} def main(): parser=argparse.ArgumentParser() parser.add_argument('--save',type=Path) parser.add_argument('--check',action='store_true') args=parser.parse_args() result=inspect() if args.check: if result != json.loads((HERE/'result.json').read_text()): raise SystemExit('saved inspection differs') if args.save: with args.save.open('x') as file: file.write(json.dumps(result,indent=2)+'\n') selected=result['selected'] print('Saved run: '+selected['run_id']) print('State transitions: '+' -> '.join(result['transitions'])) print('Selected artifact: '+selected['artifact']['kind']) print('Report bytes: '+str(selected['artifact']['bytes'])+'; SHA-256 verified') metric=selected['validation'] print(f"Saved validation: {metric['rows']} rows; accuracy {metric['accuracy']:.4f}") print('Edited report: refused; mutable latest alias: refused') print('Inspection complete; no training started') if __name__=='__main__': main()