#!/usr/bin/env python3 """Deterministically normalize SORILUN release evidence; never rerun measurements.""" from __future__ import annotations import argparse from collections import Counter import hashlib import json from pathlib import Path VERSION = '1.0' RELEASE_DATE = '2026-11-08' # Each tuple is a real release array. Its nested record is retained losslessly. COLLECTIONS = [ ('fixed_budget.json', 'rows', 'fixed_budget', 'recorded_control_comparison'), ('holdout.json', 'rows', 'holdout', 'recorded_holdout'), ('hardware_gate.json', 'records', 'hardware_gate', 'recorded_promotion_trial'), ('native_pilot.json', 'rows', 'native_pilot', 'recorded_development_pilot'), ('payback.json', 'rows', 'payback', 'recorded_deployment_comparison'), ('resonant_experiments.json', 'records', 'resonant_compilation', 'recorded_compiler_trial'), ('resonant_experiments.json', 'same_child', 'resonant_same_child', 'recorded_same_candidate_intervention'), ('resonant_experiments.json', 'continuous_updates', 'continuous_inverse_updates', 'recorded_update_stream'), ('resonant_service.json', 'records', 'resonant_service', 'recorded_service_request'), ('same_child.json', 'rows', 'arithmetic_same_child', 'recorded_same_candidate_intervention'), ('training.json', 'records', 'arithmetic_promotions', 'recorded_arithmetic_promotion'), ('training.json', 'service', 'arithmetic_training_service', 'recorded_training_service'), ('e_simulation.json', 'results', 'evidence_gate_simulation', 'recorded_statistical_simulation'), ] SUITES = [ 'verification.json', 'resonant_verification.json', 'support_verification.json', 'context_verification.json', 'boundary_verification.json', 'reservation_verification.json', ] def compact(value): return json.dumps(value, ensure_ascii=False, separators=(',', ':'), sort_keys=True, allow_nan=False) def sha(path): return hashlib.sha256(path.read_bytes()).hexdigest() def common(source_file, pointer): return {'release_version': VERSION, 'release_date': RELEASE_DATE, 'provenance_status': 'original_recorded_release', 'source_file': source_file, 'source_pointer': pointer} def int_or_none(v): return v if isinstance(v, int) and not isinstance(v, bool) else None def build(source, output): output.mkdir(parents=True, exist_ok=True) arrays = {} cache = {} def load(filename): if filename not in cache: path = source / 'results' / filename cache[filename] = json.loads(path.read_text(encoding='utf-8')) return cache[filename] experiments = [] for filename, key, label, role in COLLECTIONS: document = load(filename) records = document[key] assert isinstance(records, list) for index, record in enumerate(records): assert isinstance(record, dict) row = common('research/results/' + filename, f'/{key}/{index}') row.update({ 'record_id': f'{label}-{index:05d}', 'experiment': label, 'evidence_role': role, 'family': str(record.get('family', '')), 'method': str(record.get('method', '')), 'generation': int_or_none(record.get('generation')), 'characteristic': int_or_none(record.get('p')), 'length': int_or_none(record.get('length', record.get('n'))), 'record_json': compact(record), 'source_sha256': sha(source / 'results' / filename), }) experiments.append(row) arrays['experiments'] = experiments verification = [] for filename in SUITES: doc = load(filename) row = common('research/results/' + filename, '') passed = doc.get('all_passed', doc.get('passed')) assertions = doc['assertions'] assert isinstance(passed, bool) and isinstance(assertions, int) row.update({'suite': filename[:-5], 'status': 'passed' if passed else 'failed', 'assertions': assertions, 'groups_json': compact(doc.get('groups', {})), 'record_json': compact(doc), 'source_sha256': sha(source / 'results' / filename)}) verification.append(row) arrays['verification'] = verification claims = [] ledger = source / 'CLAIM_LEDGER.md' for line_index, line in enumerate(ledger.read_text(encoding='utf-8').splitlines(), start=1): if not line.startswith('|'): continue columns = [c.strip() for c in line.split('|')[1:-1]] if len(columns) != 3 or columns[0] == 'Claim' or all(set(c) <= {'-', ':'} for c in columns): continue row = common('research/CLAIM_LEDGER.md', f'line:{line_index}') row.update({'claim_id': f'claim-{len(claims)+1:03d}', 'claim': columns[0], 'evidence': columns[1], 'boundary': columns[2], 'source_sha256': sha(ledger)}) claims.append(row) arrays['claims'] = claims for name, rows in arrays.items(): with (output / f'{name}.jsonl').open('w', encoding='utf-8', newline='\n') as f: for row in rows: f.write(json.dumps(row, ensure_ascii=False, sort_keys=True, allow_nan=False) + '\n') assert sum(r['assertions'] for r in verification) == 5811 assert len({r['record_id'] for r in experiments}) == len(experiments) info = {'release_version': VERSION, 'release_date': RELEASE_DATE, 'created_by': 'Deterministic normalization of original release evidence; no new experiment run.', 'configs': {k: len(v) for k,v in arrays.items()}, 'experiment_counts': dict(Counter(r['experiment'] for r in experiments)), 'verification_assertions_total': sum(r['assertions'] for r in verification), 'schemas': {k:{field:type(value).__name__ for field,value in rows[0].items()} for k,rows in arrays.items()}} (output.parent/'table_build_report.json').write_text(json.dumps(info, indent=2, ensure_ascii=False)+'\n', encoding='utf-8') print(json.dumps(info, indent=2)) if __name__ == '__main__': ap=argparse.ArgumentParser(description=__doc__) ap.add_argument('--source', type=Path, required=True, help='Extracted original SORILUN_RSI directory') ap.add_argument('--output', type=Path, default=Path('data')) args=ap.parse_args() build(args.source, args.output)