#!/usr/bin/env python3 """Recompute the finite enumeration in a new directory.""" from __future__ import annotations import argparse from concurrent.futures import ThreadPoolExecutor from pathlib import Path import subprocess import sys PAIRS = [(8, 5), (9, 5), (10, 5), (10, 6), (11, 5), (11, 6), (11, 7)] HERE = Path(__file__).resolve().parent def run_search(binary: Path, cases: Path, stem: Path, part: int, parts: int) -> None: with stem.with_suffix('.txt').open('w') as out, Path(str(stem)+'.err').open('w') as err: subprocess.run([str(binary), str(cases), str(part), str(parts), str(stem.with_suffix('.jsonl'))], stdout=out, stderr=err, check=True) if not Path(str(stem)+'.err').stat().st_size: Path(str(stem)+'.err').unlink() def main() -> None: ap = argparse.ArgumentParser(description=__doc__) ap.add_argument('--output', type=Path, default=Path('recomputed')) ap.add_argument('--workers', type=int, default=4) ap.add_argument('--compiler', default='g++') args = ap.parse_args() if args.workers < 1: ap.error('--workers must be positive') target = args.output.resolve() target.mkdir(parents=True, exist_ok=False) build = target / 'build' build.mkdir() for k, h in PAIRS: binary = build / f'k{k}_h{h}' subprocess.run([args.compiler, '-std=c++17', '-O3', f'-DNUM_COLS={k}', f'-DREMAINDER_H={h}', str(HERE / 'enumerate.cpp'), '-o', str(binary)], check=True) cases = target / f'k{k}_h{h}_cases.txt' subprocess.run([sys.executable, str(HERE / 'generate_cases.py'), str(k), str(h), str(cases)], check=True) count = 4 if (k, h) == (11, 6) else 1 with ThreadPoolExecutor(max_workers=args.workers) as pool: tasks = [pool.submit(run_search, binary, cases, target / (f'k{k}_h{h}_{i}' if count > 1 else f'k{k}_h{h}'), i, count) for i in range(count)] for task in tasks: task.result() print(f'Completed k={k}, h={h}', flush=True) streams = sorted(target.glob('k*.jsonl')) subprocess.run([sys.executable, str(HERE / 'check_certificates.py'), *map(str, streams), '--output', str(target / 'integer_checks.json')], check=True) subprocess.run([sys.executable, str(HERE / 'check_coverage.py'), str(target), '--output', str(target / 'coverage_checks.json')], check=True) if __name__ == '__main__': main()