wip: shield index relations, dev evaluation tasks, Q-063 audit notes
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.
This commit is contained in:
1 parent
2d750a0525
commit
e3fc896a0a
68 files changed
+2132
-37
No files matched your search
+87
@@ -0,0 +1,87 @@
|
||||
#!/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)))
|
||||
@@ -0,0 +1,6 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.air`, a text AIR module.
|
||||
- Entry point: `@main(%in: cap<io.read>, %out: cap<io.write>, %heap: cap<mem.alloc>)`; any return type.
|
||||
- The program is run as `aji run --fuel 800000000 --grant in=io.read --grant out=io.write --grant heap=mem.alloc:16777216 --stdin TEXT main.air`. Standard input is TEXT; the bytes written to standard output appear in the run record's `stdout` field, and the run must end with `"status":"returned"`.
|
||||
- The heap budget is 16777216 bytes of live allocations; the run stops after 800000000 executed instructions. The program may spawn tasks (effect `task.spawn`); the evaluator runs it under several schedule seeds (`--schedule-seed N`), and the output must be the same for each.
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
rec=$(aji run --fuel 800000000 --grant in=io.read --grant out=io.write --grant heap=mem.alloc:16777216 --stdin 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' main.air)
|
||||
got=$(printf '%s' "$rec" | python3 -c 'import json,sys; r=json.load(sys.stdin); print(r.get("stdout","") if r.get("status")=="returned" else "<status "+str(r.get("status"))+">", end="")') || { echo "FAIL: no run record"; echo "$rec"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,6 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.aji`, an `.aji` module.
|
||||
- Entry point: `main(input: cap<io.read>, out: cap<io.write>, heap: cap<mem.alloc>)`; any return type.
|
||||
- The program is run as `aji run --fuel 800000000 --grant input=io.read --grant out=io.write --grant heap=mem.alloc:16777216 --stdin TEXT main.aji`. Standard input is TEXT; the bytes written to standard output appear in the run record's `stdout` field, and the run must end with `"status":"returned"`.
|
||||
- The heap budget is 16777216 bytes of live allocations; the run stops after 800000000 executed instructions. The program may spawn tasks (effect `task.spawn`); the evaluator runs it under several schedule seeds (`--schedule-seed N`), and the output must be the same for each.
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
rec=$(aji run --fuel 800000000 --grant input=io.read --grant out=io.write --grant heap=mem.alloc:16777216 --stdin 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' main.aji)
|
||||
got=$(printf '%s' "$rec" | python3 -c 'import json,sys; r=json.load(sys.stdin); print(r.get("stdout","") if r.get("status")=="returned" else "<status "+str(r.get("status"))+">", end="")') || { echo "FAIL: no run record"; echo "$rec"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "shards"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,5 @@
|
||||
# Interface
|
||||
|
||||
- Cargo package `shards` in this directory; the binary is `target/debug/shards`.
|
||||
- The program reads standard input and writes standard output, as the task describes.
|
||||
- Only the standard library is available (no network, `--offline`).
|
||||
@@ -0,0 +1 @@
|
||||
fn main() {}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' | ./target/debug/shards) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,4 @@
|
||||
# Interface
|
||||
|
||||
- Source: `main.zig`, built with `zig build-exe main.zig` into `./main`.
|
||||
- The program reads standard input and writes standard output, as the task describes.
|
||||
@@ -0,0 +1 @@
|
||||
pub fn main() void {}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
zig build-exe main.zig 2>&1 || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' | ./main) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,53 @@
|
||||
# Task: sharded word count
|
||||
|
||||
Development task (dev set). Its results are not evidence about any language.
|
||||
|
||||
Write a program that counts words in its standard input using several concurrent workers, then merges their results.
|
||||
|
||||
## Input
|
||||
|
||||
The input is a sequence of lines separated by `\n`. If the input ends with `\n`, that final `\n` does not start another line. The input is at most 24 KiB and has at most 2000 lines.
|
||||
|
||||
The first line is always `workers W`, where W is a decimal number with 1 ≤ W ≤ 8 and no leading zeros. Every later line is a **text line**; text lines are numbered from 0. Text lines contain only ASCII characters other than `\n`.
|
||||
|
||||
A **word** is a maximal run of ASCII letters (`A`–`Z`, `a`–`z`) in a text line, converted to lowercase. A word longer than 16 letters counts as its first 16 letters. Every other character separates words. There are at most 2000 distinct words.
|
||||
|
||||
## Concurrency requirement
|
||||
|
||||
The program MUST start W workers (threads or tasks) that run concurrently. Text line k is assigned to worker k mod W. Each worker counts the words of its own lines only. After all workers have finished, the results are merged. The output must not depend on how the workers are scheduled.
|
||||
|
||||
## Output
|
||||
|
||||
1. For each worker i from 0 to W − 1: `worker i lines L words N`, where L is the number of text lines assigned to worker i and N the number of words in them.
|
||||
2. `distinct D`, where D is the number of distinct words in the whole input.
|
||||
3. Up to 10 lines `word count` for the most frequent words: by count, highest first; equal counts in increasing byte order of the word.
|
||||
|
||||
Every output line ends with `\n`. Nothing else is written to standard output.
|
||||
|
||||
## Example
|
||||
|
||||
Input:
|
||||
|
||||
```text
|
||||
workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
```
|
||||
|
||||
Output:
|
||||
|
||||
```text
|
||||
worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
```
|
||||
|
||||
The repository contains a README with the program's interface for this language and a public test script, `sh test.sh`, which must pass. Hidden tests check the requirements above.
|
||||
@@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "shards"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
@@ -0,0 +1,53 @@
|
||||
use std::collections::HashMap;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
fn words(line: &str) -> Vec<String> {
|
||||
line.split(|c: char| !c.is_ascii_alphabetic())
|
||||
.filter(|w| !w.is_empty())
|
||||
.map(|w| w.to_ascii_lowercase().chars().take(16).collect())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut input = String::new();
|
||||
std::io::stdin().read_to_string(&mut input).unwrap();
|
||||
let mut lines: Vec<&str> = input.split('\n').collect();
|
||||
if input.ends_with('\n') {
|
||||
lines.pop();
|
||||
}
|
||||
let w: usize = lines[0]["workers ".len()..].parse().unwrap();
|
||||
let text = &lines[1..];
|
||||
let results: Vec<(usize, usize, HashMap<String, u64>)> = std::thread::scope(|s| {
|
||||
let handles: Vec<_> = (0..w)
|
||||
.map(|i| {
|
||||
s.spawn(move || {
|
||||
let (mut l, mut n, mut m) = (0, 0, HashMap::new());
|
||||
for line in text.iter().skip(i).step_by(w) {
|
||||
l += 1;
|
||||
for word in words(line) {
|
||||
n += 1;
|
||||
*m.entry(word).or_insert(0) += 1;
|
||||
}
|
||||
}
|
||||
(l, n, m)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
handles.into_iter().map(|h| h.join().unwrap()).collect()
|
||||
});
|
||||
let mut out = String::new();
|
||||
let mut total: HashMap<String, u64> = HashMap::new();
|
||||
for (i, (l, n, m)) in results.into_iter().enumerate() {
|
||||
out.push_str(&format!("worker {i} lines {l} words {n}\n"));
|
||||
for (k, v) in m {
|
||||
*total.entry(k).or_insert(0) += v;
|
||||
}
|
||||
}
|
||||
out.push_str(&format!("distinct {}\n", total.len()));
|
||||
let mut top: Vec<(String, u64)> = total.into_iter().collect();
|
||||
top.sort_by(|a, b| b.1.cmp(&a.1).then(a.0.as_bytes().cmp(b.0.as_bytes())));
|
||||
for (k, v) in top.into_iter().take(10) {
|
||||
out.push_str(&format!("{k} {v}\n"));
|
||||
}
|
||||
std::io::stdout().write_all(out.as_bytes()).unwrap();
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Public test: the example from the task statement.
|
||||
cargo build -q --offline || { echo "FAIL: build"; exit 1; }
|
||||
got=$(printf '%s' 'workers 2
|
||||
The cat sat.
|
||||
the CAT, the hat
|
||||
a-b-c
|
||||
' | ./target/debug/shards) || { echo "FAIL: the program exited with an error"; exit 1; }
|
||||
expected=$(printf "%s" 'worker 0 lines 2 words 6
|
||||
worker 1 lines 1 words 4
|
||||
distinct 7
|
||||
the 3
|
||||
cat 2
|
||||
a 1
|
||||
b 1
|
||||
c 1
|
||||
hat 1
|
||||
sat 1
|
||||
')
|
||||
if [ "$got" = "$expected" ]; then echo PASS; else echo "FAIL"; echo "--- expected"; printf '%s' "$expected"; echo "--- got"; printf '%s' "$got"; exit 1; fi
|
||||
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"id": "dev-shards",
|
||||
"version": "1",
|
||||
"set": "dev",
|
||||
"family": "failure-calibration",
|
||||
"prompt": "prompt.md",
|
||||
"languages": {
|
||||
"aji_air": {"workspace": "lang/aji_air", "test": "sh test.sh"},
|
||||
"aji_source": {"workspace": "lang/aji_source", "test": "sh test.sh"},
|
||||
"rust": {"workspace": "lang/rust", "test": "sh test.sh"},
|
||||
"zig": {"workspace": "lang/zig", "test": "sh test.sh"}
|
||||
},
|
||||
"limits": {"tool_calls": 80, "total_tokens": 1500000, "wall_seconds": 1800, "command_timeout": 120},
|
||||
"concurrency": true
|
||||
}
|
||||
Reference in new issue
Block a user