#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Rung 4: judge the core's multiplies by zayd's hardware-fuzzed model, 10^6 cases per form. Each form runs in its own processes (the cases are split into chunks with distinct seeds). python scripts/multiply_judge.py # 10^6 per form python scripts/multiply_judge.py --count 10000 """ from __future__ import annotations import argparse import os import sys import time from collections import Counter from concurrent.futures import ProcessPoolExecutor from pathlib import Path ROOT = Path(__file__).resolve().parents[1] sys.path[:0] = [str(ROOT / "src"), str(ROOT)] from tests.multiply_judge import FORMS, judge # noqa: E402 CHUNKS = 4 def job(args: tuple[str, int, int]): form, count, seed = args return form, count, *judge(form, count, seed) def main() -> int: parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument("--count", type=int, default=1_000_000) parser.add_argument("--jobs", type=int, default=os.cpu_count()) args = parser.parse_args() start = time.perf_counter() work = [ (form, args.count // CHUNKS, 1000 * index + chunk) for index, form in enumerate(FORMS) for chunk in range(CHUNKS) ] cases, failures = Counter(), Counter() with ProcessPoolExecutor(args.jobs) as pool: for form, count, failed, examples in pool.map(job, work): cases[form] += count failures[form] += failed for line in examples: print(" ", line) for form in FORMS: print(f"{form:10} {cases[form] - failures[form]:,}/{cases[form]:,} agree") print(f"{time.perf_counter() - start:.0f} s wall") return 0 if not sum(failures.values()) else 1 if __name__ == "__main__": sys.exit(main())