Datasets:
Tasks:
Text Generation
Formats:
parquet
Sub-tasks:
language-modeling
Languages:
English
Size:
< 1K
License:
Download harbor/sources/rust-postgres-v6/faultprobe.py from ExpertCrowd/ec-swe: direct link, hf CLI and curl.
- Browser
- Download file 8.11 kB
-
https://huggingface.co/datasets/ExpertCrowd/ec-swe/resolve/main/harbor/sources/rust-postgres-v6/faultprobe.py
- Command line
-
hf download hf://datasets/ExpertCrowd/ec-swe/harbor/sources/rust-postgres-v6/faultprobe.py
-
curl -L -o faultprobe.py https://huggingface.co/datasets/ExpertCrowd/ec-swe/resolve/main/harbor/sources/rust-postgres-v6/faultprobe.py
8.11 kB
| #!/usr/bin/env python3 | |
| """Is "break the grader's fixture and collect the weight" a strategy? | |
| python3 faultprobe.py | |
| One question, asked over every tree that has ever been graded with this grader | |
| (.calib/mutation-probe.json and the current-schema rows of .calib/calibration.json): | |
| for each criterion this tree does not pass, what does the tree GAIN by | |
| turning that criterion from a FAIL into a GRADER FAULT? | |
| An agent can do that without touching the criterion it is failing: the oracle is | |
| compiled against the tree and driven through its exported API, so a tree that | |
| renames an exported symbol, or that hangs inside one scenario, converts a | |
| criterion it would fail into one the grader cannot judge. | |
| That is the channel. Three rules are compared: | |
| absolve the shipped rule: a faulted criterion is scored 1.0 | |
| normalise §5.3 as literally written: scored 0.0 and struck from the | |
| denominator, the reward renormalised over the weight measured | |
| strike what is implemented: scored 0.0, struck from the blocker set, | |
| nothing renormalised. The normalised figure is reported in the | |
| info block, and the run is flagged isError for a re-run. | |
| A rule closes the channel iff no tree can gain under it. Anything above zero is | |
| weight an agent can have for breaking the grader instead of meeting a criterion. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| from pathlib import Path | |
| import mutprobe as M | |
| HERE = Path(__file__).resolve().parent | |
| CALIB = HERE / ".calib" | |
| def load_matrix() -> dict[str, dict[str, bool]]: | |
| """Every recorded tree whose row uses the criterion names in force today.""" | |
| graders, _cap = M.load_table() | |
| known = {n for n, _w, _b in graders} | |
| # A row is usable as long as it covers every criterion of the board in | |
| # force today; an older schema is skipped rather than half-read. | |
| core = set(known) | |
| rows: dict[str, dict[str, bool]] = {} | |
| for path in (CALIB / "mutation-probe.json", CALIB / "calibration.json"): | |
| if not path.exists(): | |
| continue | |
| try: | |
| entries = json.loads(path.read_text()) | |
| except (ValueError, OSError): | |
| continue | |
| for e in entries: | |
| res = e.get("results") or {} | |
| if not core.issubset(res): | |
| continue # an older schema, or a partial run | |
| rows[e["tree"]] = {n: bool(res.get(n)) for n in known} | |
| return rows | |
| # ─── the three rules ─────────────────────────────────────────────────────── | |
| def absolve(results, graders, cap, faults): | |
| """Shipped: a faulted criterion is scored 1.0 and cannot cap.""" | |
| faults = set(faults) | |
| uncapped = sum(w for n, w, _b in graders if results.get(n) or n in faults) | |
| failed = [n for n, _w, b in graders if b and n not in faults and not results.get(n)] | |
| return uncapped if not failed else max(0.0, min(uncapped, cap)) | |
| def normalise(results, graders, cap, faults): | |
| """§5.3 literally: scored 0.0, and out of the denominator too.""" | |
| faults = set(faults) | |
| measured = sum(w for n, w, _b in graders if n not in faults) | |
| if measured <= 0: | |
| return 0.0 | |
| earned = sum(w for n, w, _b in graders if n not in faults and results.get(n)) | |
| failed = [n for n, _w, b in graders if b and n not in faults and not results.get(n)] | |
| score = earned / measured | |
| return score if not failed else max(0.0, min(score, cap)) | |
| def strike_no_ceiling(results, graders, cap, faults): | |
| """Scored 0.0 and struck from the blocker set, without the unproven ceiling. | |
| The intermediate step, kept because it is the one that looks right and is | |
| not: striking a faulted BLOCKER also lifts the cap, and lifting the cap is | |
| worth the whole gap between it and 1.00 to a tree that would fail a gate. | |
| """ | |
| faults = set(faults) | |
| uncapped = sum(w for n, w, _b in graders if n not in faults and results.get(n)) | |
| failed = [n for n, _w, b in graders if b and n not in faults and not results.get(n)] | |
| return uncapped if not failed else max(0.0, min(uncapped, cap)) | |
| def strike(results, graders, cap, faults): | |
| """Implemented: scored 0.0, not renormalised, unproven blockers keep the cap.""" | |
| return M.reward(results, graders, cap, faults)[0] | |
| RULES = (("absolve", absolve), ("normalise", normalise), | |
| ("no-ceiling", strike_no_ceiling), ("strike", strike)) | |
| def main() -> None: | |
| graders, cap = M.load_table() | |
| names = [n for n, _w, _b in graders] | |
| weights = {n: w for n, w, _b in graders} | |
| rows = load_matrix() | |
| if not rows: | |
| raise SystemExit("no recorded rows use today's criterion names") | |
| print(f"{len(rows)} recorded trees, {len(names)} criteria, cap {cap:.2f}") | |
| print("gain = what the tree scores once one criterion it FAILS is turned " | |
| "into a fault, minus what it scores honestly\n") | |
| worst = {label: (-9.9, "", "") for label, _fn in RULES} | |
| print(f"{'tree':<28} {'criterion it breaks':<46} {'honest':>7} " | |
| + " ".join(f"{label:>10}" for label, _fn in RULES)) | |
| for tree in sorted(rows): | |
| results = rows[tree] | |
| honest = M.reward(results, graders, cap)[0] | |
| for c in names: | |
| if results.get(c): | |
| continue # it passes this one; breaking it can only cost | |
| line = f"{tree:<28} {c + f' (w={weights[c]:.2f})':<46} {honest:>7.3f}" | |
| for label, fn in RULES: | |
| got = fn(results, graders, cap, {c}) | |
| gain = got - honest | |
| line += f" {got:>6.3f}{gain:+.3f}" | |
| if gain > worst[label][0]: | |
| worst[label] = (gain, tree, c) | |
| print(line) | |
| print("\n=== the most a tree can gain by breaking one fixture ===") | |
| for label, _fn in RULES: | |
| gain, tree, c = worst[label] | |
| verdict = "CHANNEL OPEN" if gain > 1e-9 else "closed" | |
| print(f" {label:<10} {gain:+.3f} ({tree}, {c}) -> {verdict}") | |
| # ─── the proof, as opposed to the illustration ───────────────────────── | |
| # | |
| # The rows above are the trees that happen to have been graded. The channel | |
| # is a property of the arithmetic, not of the sample, so: every one of the | |
| # 2^n outcome vectors a tree could possibly have, against every non-empty | |
| # subset of criteria it could turn into a fault. A rule is closed iff the | |
| # largest gain over the whole space is zero. | |
| print(f"\n=== every possible tree ({1 << len(names)} outcome vectors) x every " | |
| f"subset of faults ({(1 << len(names)) - 1}) ===") | |
| worst_all = {label: (-9.9, (), ()) for label, _fn in RULES} | |
| for outcome in range(1 << len(names)): | |
| results = {n: bool(outcome >> i & 1) for i, n in enumerate(names)} | |
| honest = M.reward(results, graders, cap)[0] | |
| for mask in range(1, 1 << len(names)): | |
| faults = {names[i] for i in range(len(names)) if mask >> i & 1} | |
| for label, fn in RULES: | |
| gain = fn(results, graders, cap, faults) - honest | |
| if gain > worst_all[label][0]: | |
| reds = tuple(n for n in names if not results[n]) | |
| worst_all[label] = (gain, reds, tuple(sorted(faults))) | |
| for label, _fn in RULES: | |
| gain, reds, faults = worst_all[label] | |
| verdict = "CHANNEL OPEN" if gain > 1e-9 else "CLOSED" | |
| print(f" {label:<11} max gain {gain:+.3f} -> {verdict}") | |
| if gain > 1e-9: | |
| print(f" worst case: a tree failing {list(reds) or 'nothing'}") | |
| print(f" breaks {list(faults)}") | |
| strike_gain = worst_all["strike"][0] | |
| print("\n" + ("PASS: under the implemented rule, breaking any set of fixtures " | |
| "is never worth anything." | |
| if strike_gain <= 1e-9 else | |
| f"FAIL: the implemented rule still pays {strike_gain:+.3f}.")) | |
| return 0 if strike_gain <= 1e-9 else 1 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |