Verifier borrow/provenance work, new phase3 shield_index conformance cases, dev-intervals/dev-lru/dev-shards tasks with evaluate.py harness, and agent skill/hook config.
88 lines
3.0 KiB
Python
Executable File
88 lines
3.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Evaluator for dev-shards (dev set; public).
|
|
|
|
Besides the output, two gates cover the concurrency requirement:
|
|
uses_concurrency the source starts threads or tasks (a coarse static check);
|
|
hidden for Aji, every hidden case runs under three schedule seeds.
|
|
|
|
usage: evaluator.py WORKSPACE LANGUAGE TASK_DIR -> JSON verdict on stdout
|
|
"""
|
|
import collections
|
|
import os
|
|
import random
|
|
import re
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
import devlib # noqa: E402
|
|
|
|
WORD = re.compile(r"[A-Za-z]+")
|
|
SPAWN = {
|
|
"aji_air": r"\btask\.spawn\b",
|
|
"aji_source": r"\btask\.spawn\b",
|
|
"rust": r"thread::(spawn|scope)|\.spawn\(",
|
|
"zig": r"Thread\.spawn|std\.Thread",
|
|
}
|
|
|
|
|
|
def model(text):
|
|
lines = text.split("\n")
|
|
if text.endswith("\n"):
|
|
lines.pop()
|
|
w = int(lines[0].split(" ")[1])
|
|
per = [[0, 0] for _ in range(w)]
|
|
counts = collections.Counter()
|
|
for k, line in enumerate(lines[1:]):
|
|
words = [m.lower()[:16] for m in WORD.findall(line)]
|
|
per[k % w][0] += 1
|
|
per[k % w][1] += len(words)
|
|
counts.update(words)
|
|
out = [f"worker {i} lines {l} words {n}" for i, (l, n) in enumerate(per)]
|
|
out.append(f"distinct {len(counts)}")
|
|
out += [f"{word} {c}" for word, c in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0].encode()))[:10]]
|
|
return "".join(o + "\n" for o in out)
|
|
|
|
|
|
def gen(rng, w, n, vocab):
|
|
words = ["".join(rng.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(rng.randint(1, 20))) for _ in range(vocab)]
|
|
lines = [f"workers {w}"]
|
|
for _ in range(n):
|
|
parts = []
|
|
for _ in range(rng.randint(0, 6)):
|
|
word = rng.choice(words) if rng.random() < 0.8 else rng.choice(words[:5])
|
|
if rng.random() < 0.2:
|
|
word = word.upper() if rng.random() < 0.5 else word.capitalize()
|
|
parts.append(word)
|
|
parts.append(rng.choice([" ", " ", ", ", ". ", "-", " ", "1", "'", "\t", "_"]))
|
|
lines.append("".join(parts))
|
|
return "\n".join(lines) + ("\n" if rng.random() < 0.8 else "")
|
|
|
|
|
|
def case(text):
|
|
return (text, model(text))
|
|
|
|
|
|
PUBLIC = [case("workers 2\nThe cat sat.\nthe CAT, the hat\na-b-c\n")]
|
|
|
|
rng = random.Random(20261009)
|
|
HIDDEN = [
|
|
case("workers 1\n"),
|
|
case("workers 8\nalpha\n\n...\nBeta beta\n"),
|
|
case("workers 3\nabcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopXYZ\nx1y2z3\n"),
|
|
case("workers 4\nb a\na b\nc\nb\n"),
|
|
case(gen(rng, 2, 50, 12)),
|
|
case(gen(rng, 5, 400, 80)),
|
|
case(gen(rng, 8, 600, 600)),
|
|
case(gen(rng, 7, 550, 1500)),
|
|
case("workers 6\n" + "".join(rng.choice(["a", "b b", "", "C", "d.e"]) + "\n" for _ in range(1990))),
|
|
]
|
|
|
|
|
|
def gates(ws, lang):
|
|
return {"uses_concurrency": devlib.source_matches(ws, lang, SPAWN)}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
devlib.evaluate(devlib.Spec("shards", heap=16 << 20, fuel=800_000_000, public=PUBLIC, hidden=HIDDEN,
|
|
extra_gates=gates, schedule_seeds=(0, 1, 2)))
|