#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Score candidate values of the UART's FITTED constants on the UART suites. The UART's frame-internal timing has no document (lynx_python.mikey.uart): this script runs the named suites with each candidate and prints the per-suite pass counts, so the choice recorded in docs/validation.md "M6 UART" can be re-made. python -I scripts/m6_uart_fit.py --set RECEIVED=92,96,100 --set DEPTH=2 \ [--row lynx2] [--jobs 3] [uart uart2 uart3] """ from __future__ import annotations import argparse import itertools import sys from concurrent.futures import ProcessPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT / "src")) def job(item): values, suites, row = item from lynx_python import testrom from lynx_python.machine import MACHINES from lynx_python.mikey import uart for key, value in values.items(): setattr(uart, key, value) out = [] for suite in suites: outcome = testrom.run(suite, MACHINES[row]) out.append((suite, outcome.passed, outcome.results)) return values, out def main(argv: list[str]) -> int: parser = argparse.ArgumentParser() parser.add_argument("suites", nargs="*", default=["uart", "uart2", "uart3"]) parser.add_argument("--set", action="append", default=[], metavar="NAME=V1,V2") parser.add_argument("--row", default="lynx2") parser.add_argument("--jobs", type=int, default=3) args = parser.parse_args(argv) names, choices = [], [] for item in args.set: name, values = item.split("=") names.append(name) choices.append([int(v) for v in values.split(",")]) grid = [dict(zip(names, combo, strict=True)) for combo in itertools.product(*choices)] with ProcessPoolExecutor(args.jobs) as pool: for values, out in pool.map(job, [(g, args.suites, args.row) for g in grid]): total = sum(sum(p) for _, p, _ in out) count = sum(len(p) for _, p, _ in out) detail = " ".join( f"{s} {sum(p)}/{len(p)} [{''.join('P' if x else '.' for x in p)}]" for s, p, _ in out ) print(f"{values}: {total}/{count} {detail}", flush=True) return 0 if __name__ == "__main__": sys.exit(main(sys.argv[1:]))