AELYRAITH-III / check_exported.py
PureOne's picture
Publish AELYRAITH III research and agent support release
33e9f46 verified
Raw History Blame Contribute Delete
1.55 kB
"""Check exported rational certificates without invoking the compiler."""
import json
from pathlib import Path
import sympy as sp
from src.continuation import ExteriorCertificate, Ratio
ROOT = Path(__file__).resolve().parent
def matrix(rows):
return sp.Matrix([[sp.Rational(value) for value in row] for row in rows])
def ratio(record):
return Ratio(matrix(record['beta']), matrix(record['alpha']), tuple(record['word']))
def main() -> None:
records = json.loads((ROOT/'results'/'exact_certificates.json').read_text())
for record in records:
n = int(record['n'])
seeds = tuple(ratio(row) for row in record['seeds'])
ratios = [ratio(row) for row in record['ratios']]
branches = (matrix(record['A']), matrix(record['B']))
cert = ExteriorCertificate(
normalizer=matrix(record['normalizer']),
readouts=tuple(seed.numerator for seed in seeds), seeds=seeds,
branches=branches, ratios=ratios, R=matrix(record['R']),
transports=[matrix(H) for H in record['H']],
depth=max((len(r.word) for r in ratios), default=0))
if not cert.verify():
raise AssertionError(f'Failed certificate at n={n}')
if cert.normalizer*(branches[0]+branches[1]) != cert.normalizer:
raise AssertionError(f'Failed instrument normalization at n={n}')
print(f'n={n}: seed coverage, provenance, row integrity, positivity, '
'transport, and normalization all pass.')
if __name__ == '__main__':
main()