interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / research / om-bench / bench / benchlib.py

96 lines · 3454 bytes Raw Blame History
1"""om-bench (#653) task framework: family records, oracles and seeded input generators.
2
3Independent oracle code written by OmegaEval. Candidate lanes (OmegaIntent, OmegaMind, OmegaCorpus)
4never edit this file or the sealed families. Python here is a verification oracle outside the
5delivered Omega build closure (disclosed in CONTRACT.md section 9).
6"""
7import hashlib, hmac, os, random
8
9# Private sealed material (held-out families, keys, opaque-id key) lives outside the repository.
10SEALED = os.environ.get("OMB_SEALED", os.path.expanduser("~/handoffs/OmegaEval/sealed"))
11OPAQUE_KEY = os.path.join(SEALED, "opaque.key")
12
13
14def opaque(split, tid):
15 """Public name of a task. Train/dev ids are public; sealed ids are an HMAC-SHA256 under a private key,
16 so a reader cannot recover a sealed family name by hashing guesses."""
17 if split in ("train", "dev") or tid.startswith(("zz-", "ctl-")):
18 return tid
19 key = open(OPAQUE_KEY, "rb").read().strip()
20 return split + ":" + hmac.new(key, tid.encode(), hashlib.sha256).hexdigest()[:10]
21
22M64 = 1 << 64
23
24COMMON_IO = (
25 "Input arrives on standard input as ASCII text of at most 65536 bytes. Unless the task says "
26 "otherwise, numbers are unsigned decimal integers below 2^64 with no sign and no leading zeros, "
27 "separated by single spaces, and every input line ends with one newline byte (10). Write the "
28 "answer to standard output exactly as specified, each output line ending with one newline byte. "
29 "Exit with status 0 unless the task says otherwise. Write nothing to standard output that the task "
30 "does not ask for."
31)
32
33
34class Task:
35 def __init__(self, family, vid, statement, oracle, examples, hidden):
36 self.family = family
37 self.vid = vid
38 self.statement = statement
39 self.oracle = oracle
40 self.examples = examples
41 self.hidden = hidden
42
43 @property
44 def tid(self):
45 return f"{self.family}.{self.vid}"
46
47
48def b(s):
49 return s.encode("ascii") if isinstance(s, str) else s
50
51
52def line(*vals):
53 return (" ".join(str(v) for v in vals) + "\n").encode("ascii")
54
55
56def lines(rows):
57 return b"".join(line(*r) if isinstance(r, (list, tuple)) else line(r) for r in rows)
58
59
60def ints(inp):
61 return [int(t) for t in inp.split()]
62
63
64def out(*vals):
65 return line(*vals), 0
66
67
68def rng_for(tid, salt="v1"):
69 return random.Random(f"om-bench-653/{salt}/{tid}")
70
71
72def numlist(rng, n_lo, n_hi, v_hi):
73 n = rng.randint(n_lo, n_hi)
74 return line(*[rng.randint(0, v_hi) for _ in range(n)])
75
76
77def text_lines(rng, n_lines, alphabet, max_len, min_len=0):
78 rows = []
79 for _ in range(n_lines):
80 k = rng.randint(min_len, max_len)
81 rows.append("".join(rng.choice(alphabet) for _ in range(k)))
82 return ("\n".join(rows) + "\n").encode("ascii")
83
84
85def words_line(rng, n_lo, n_hi, alphabet="abcdefghijklmnopqrstuvwxyz", wmax=8):
86 n = rng.randint(n_lo, n_hi)
87 ws = ["".join(rng.choice(alphabet) for _ in range(rng.randint(1, wmax))) for _ in range(n)]
88 return (" ".join(ws) + "\n").encode("ascii")
89
90
91def mk(family, vid, statement, oracle, examples, gen, boundary=(), n_random=6):
92 """examples: visible inputs; gen(rng) -> one hidden input; boundary: fixed hidden inputs."""
93 tid = f"{family}.{vid}"
94 rng = rng_for(tid)
95 hidden = [b(x) for x in boundary] + [gen(rng) for _ in range(n_random)]
96 return Task(family, vid, statement, oracle, [b(x) for x in examples], hidden)