from __future__ import annotations import gzip import hashlib import json from collections import Counter, defaultdict from pathlib import Path ROOT = Path(__file__).resolve().parent def sha256_file(path: Path) -> str: digest = hashlib.sha256() with path.open("rb") as handle: for chunk in iter(lambda: handle.read(4 * 1024 * 1024), b""): digest.update(chunk) return digest.hexdigest() def records(paths: list[Path]): for path in paths: with gzip.open(path, "rt", encoding="utf-8") as handle: for line in handle: yield json.loads(line) def main() -> None: checked = 0 for line in (ROOT / "SHA256SUMS").read_text(encoding="ascii").splitlines(): expected, relative = line.split(" ", 1) path = ROOT / relative if sha256_file(path) != expected: raise RuntimeError(f"checksum mismatch: {relative}") checked += 1 supervised = list(records([ROOT / "data" / "supervised_model_input.jsonl.gz"])) if len(supervised) != 168: raise RuntimeError("supervised row count mismatch") if Counter(row["label"] for row in supervised) != Counter({0: 112, 1: 56}): raise RuntimeError("supervised labels mismatch") if Counter(row["outer_fold"] for row in supervised) != Counter( {0: 39, 1: 30, 2: 45, 3: 27, 4: 27} ): raise RuntimeError("supervised fold counts mismatch") by_match = defaultdict(list) for row in supervised: by_match[row["matched_set_id"]].append(row) if len(row["sequence_ref"]) != 3000 or len(row["sequence_alt"]) != 3000: raise RuntimeError("supervised sequence length mismatch") differences = sum(a != b for a, b in zip(row["sequence_ref"], row["sequence_alt"])) if differences != 1 or row["sequence_ref"][1500] != row["ref"] or row["sequence_alt"][1500] != row["alt"]: raise RuntimeError("supervised centered mutation mismatch") if len(by_match) != 56 or any(len(rows) != 3 or sum(row["label"] for row in rows) != 1 for rows in by_match.values()): raise RuntimeError("supervised matched triplets mismatch") pseudo_paths = sorted((ROOT / "data").glob("pretraining-*.jsonl.gz")) pseudo_count = 0 pseudo_ids = set() for row in records(pseudo_paths): pseudo_count += 1 pseudo_ids.add(row["pseudo_index"]) if len(row["sequence_ref"]) != 3000 or len(row["sequence_alt"]) != 3000: raise RuntimeError("pretraining sequence length mismatch") if row["sequence_ref"][1500] != row["ref"] or row["sequence_alt"][1500] != row["alt"]: raise RuntimeError("pretraining centered mutation mismatch") if sum(a != b for a, b in zip(row["sequence_ref"], row["sequence_alt"])) != 1: raise RuntimeError("pretraining mutation count mismatch") if pseudo_count != 20_000 or pseudo_ids != set(range(20_000)): raise RuntimeError("pretraining inventory mismatch") print(f"PASS: {checked} checksums; 168 supervised rows; 20,000 pretraining rows") if __name__ == "__main__": main()