#!/usr/bin/env python3 """Build all four native implementations and compare eight executions exactly.""" import argparse import hashlib import os from pathlib import Path import shutil import subprocess import sys from datetime import datetime, timezone def main(): parser = argparse.ArgumentParser(description=__doc__) for name in ['julia', 'cargo', 'rustc', 'java', 'javac']: parser.add_argument('--'+name, default=None, help='Optional executable path') parser.add_argument('--output', default='run-results', help='Directory for builds and logs') args = parser.parse_args() root = Path(__file__).resolve().parent output = Path(args.output).resolve() output.mkdir(parents=True, exist_ok=True) executable = {} for name in ['julia', 'cargo', 'rustc', 'java']: value = getattr(args, name) or shutil.which(name) if value is None: raise RuntimeError(f'Missing {name}: install its runtime or use --{name} PATH') executable[name] = str(Path(value).resolve()) javac = args.javac or shutil.which('javac') env = dict(os.environ) env['RUSTC'] = executable['rustc'] env['CARGO_TARGET_DIR'] = str(output/'rust-target') env['CARGO_HOME'] = str(output/'cargo-home') expected = (root/'expected.txt').read_bytes() if not expected.endswith(b'TOTAL\t21\tPASS\n'): raise RuntimeError('Invalid reference transcript') expected_sha = hashlib.sha256(expected).hexdigest() results = [] def execute(name, command, cwd=root, compare=False): process = subprocess.run(command, cwd=cwd, env=env, capture_output=True, timeout=300) (output/(name+'.stdout.txt')).write_bytes(process.stdout) (output/(name+'.stderr.txt')).write_bytes(process.stderr) if process.returncode: message = process.stderr.decode(errors='replace')[-4000:] raise RuntimeError(f'{name} exited {process.returncode}:\n{message}') if compare: if process.stdout != expected: raise RuntimeError(f'{name}: transcript mismatch; inspect {output}') results.append((name, hashlib.sha256(process.stdout).hexdigest())) print('PASS', name, '21 groups; transcript identical', flush=True) return (process.stdout+process.stderr).decode(errors='replace').strip() versions = { 'Python': sys.version.splitlines()[0], 'Julia': execute('version-julia', [executable['julia'], '--version']), 'Rust': execute('version-rust', [executable['rustc'], '--version']), 'Cargo': execute('version-cargo', [executable['cargo'], '--version']), 'Java': execute('version-java', [executable['java'], '-version']).splitlines()[0], } execute('python', [sys.executable, str(root/'verify.py')], compare=True) execute('python-optimized', [sys.executable, '-O', str(root/'verify.py')], compare=True) execute('julia', [executable['julia'], '--startup-file=no', str(root/'verify.jl')], compare=True) execute('julia-optimized', [executable['julia'], '--startup-file=no', '-O3', str(root/'verify.jl')], compare=True) for release in [False, True]: mode = 'release' if release else 'debug' command = [executable['cargo'], 'build', '--offline', '--locked'] if release: command.append('--release') execute('rust-build-'+mode, command, cwd=root/'rust') suffix = '.exe' if os.name == 'nt' else '' binary = output/'rust-target'/mode/('sampling_verification'+suffix) execute('rust-'+mode, [str(binary)], compare=True) classes = output/'java-classes' classes.mkdir(exist_ok=True) compiler = [javac] if javac else [executable['java'], '-m', 'jdk.compiler/com.sun.tools.javac.Main'] execute('java-compile', compiler+['-d', str(classes), str(root/'Verify.java')]) execute('java', [executable['java'], '-cp', str(classes), 'Verify'], compare=True) execute('java-assertions-disabled', [executable['java'], '-da', '-cp', str(classes), 'Verify'], compare=True) report = [ '# Reproduction run', '', datetime.now(timezone.utc).isoformat(), '', 'All eight executions passed 21 check groups and matched `expected.txt` byte for byte.', '', f'Reference transcript: {len(expected)} bytes; SHA-256 `{expected_sha}`.', '', '| Runtime | Version |', '|---|---|', ] report += [f'| {name} | {value} |' for name, value in versions.items()] report += ['', '| Execution | Transcript SHA-256 |', '|---|---|'] report += [f'| {name} | `{digest}` |' for name, digest in results] report += ['', 'The transcript distinguishes exact `VALUE` records from its one `APPROX` record.', 'Rust builds used the bundled dependencies in offline mode with an isolated Cargo cache.', 'Written proofs establish the parameter-wide statements; these runs reproduce their computational checks.', ''] (output/'RUN_REPORT.md').write_text('\n'.join(report)) print('PASS all eight executions; exact reference SHA-256', expected_sha) if __name__ == '__main__': main()