s3-aggregation: 160 tasks from seed 115, role files, grader, oracle, checks
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- README.md +135 -0
- check.py +318 -0
- generate.py +202 -0
- problems.json +34 -0
- roles/agg-p01-n01/slot-01.md +1 -0
- roles/agg-p01-n02/slot-01.md +1 -0
- roles/agg-p01-n02/slot-02.md +1 -0
- roles/agg-p01-n04/slot-01.md +1 -0
- roles/agg-p01-n04/slot-02.md +1 -0
- roles/agg-p01-n04/slot-03.md +1 -0
- roles/agg-p01-n04/slot-04.md +1 -0
- roles/agg-p01-n08/slot-01.md +1 -0
- roles/agg-p01-n08/slot-02.md +1 -0
- roles/agg-p01-n08/slot-03.md +1 -0
- roles/agg-p01-n08/slot-04.md +1 -0
- roles/agg-p01-n08/slot-05.md +1 -0
- roles/agg-p01-n08/slot-06.md +1 -0
- roles/agg-p01-n08/slot-07.md +1 -0
- roles/agg-p01-n08/slot-08.md +1 -0
- roles/agg-p01-n16/slot-01.md +1 -0
- roles/agg-p01-n16/slot-02.md +1 -0
- roles/agg-p01-n16/slot-03.md +1 -0
- roles/agg-p01-n16/slot-04.md +1 -0
- roles/agg-p01-n16/slot-05.md +1 -0
- roles/agg-p01-n16/slot-06.md +1 -0
- roles/agg-p01-n16/slot-07.md +1 -0
- roles/agg-p01-n16/slot-08.md +1 -0
- roles/agg-p01-n16/slot-09.md +1 -0
- roles/agg-p01-n16/slot-10.md +1 -0
- roles/agg-p01-n16/slot-11.md +1 -0
- roles/agg-p01-n16/slot-12.md +1 -0
- roles/agg-p01-n16/slot-13.md +1 -0
- roles/agg-p01-n16/slot-14.md +1 -0
- roles/agg-p01-n16/slot-15.md +1 -0
- roles/agg-p01-n16/slot-16.md +1 -0
- roles/agg-p02-n01/slot-01.md +1 -0
- roles/agg-p02-n02/slot-01.md +1 -0
- roles/agg-p02-n02/slot-02.md +1 -0
- roles/agg-p02-n04/slot-01.md +1 -0
- roles/agg-p02-n04/slot-02.md +1 -0
- roles/agg-p02-n04/slot-03.md +1 -0
- roles/agg-p02-n04/slot-04.md +1 -0
- roles/agg-p02-n08/slot-01.md +1 -0
- roles/agg-p02-n08/slot-02.md +1 -0
- roles/agg-p02-n08/slot-03.md +1 -0
- roles/agg-p02-n08/slot-04.md +1 -0
- roles/agg-p02-n08/slot-05.md +1 -0
- roles/agg-p02-n08/slot-06.md +1 -0
- roles/agg-p02-n08/slot-07.md +1 -0
- roles/agg-p02-n08/slot-08.md +1 -0
README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pretty_name: s3-aggregation
|
| 3 |
+
license: apache-2.0
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
tags:
|
| 7 |
+
- harbor
|
| 8 |
+
- agent-environment
|
| 9 |
+
- multi-agent
|
| 10 |
+
- message-board
|
| 11 |
+
size_categories:
|
| 12 |
+
- n<1K
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# s3-aggregation
|
| 16 |
+
|
| 17 |
+
A [Harbor](https://harborframework.com) environment that measures whether a swarm of agents
|
| 18 |
+
**communicates**: each agent holds one private number, and no agent can solve the task alone. It
|
| 19 |
+
adapts the information-aggregation task of
|
| 20 |
+
[s³: Simple Scaling of Swarms via Cooperative Multi-agent RL](https://arxiv.org/abs/2611.08615)
|
| 21 |
+
([scalingswarms.com](https://scalingswarms.com)) to [Flock](https://github.com/huggingface/flock)
|
| 22 |
+
swarms, whose agents talk over a shared message board. It isn't a replication of the paper: the
|
| 23 |
+
agents are Pi with Flock's board, and the board is what we measure.
|
| 24 |
+
|
| 25 |
+
**This dataset is private for now.**
|
| 26 |
+
|
| 27 |
+
## The task
|
| 28 |
+
|
| 29 |
+
Each of the N agents holds one private integer from 1 to 99, written in English words
|
| 30 |
+
("seventy-three"). The team must list all N numbers in ascending order, keeping equal numbers
|
| 31 |
+
from different agents as separate entries. Each agent shares its number on the board, reads the
|
| 32 |
+
others', keeps one number per participant, writes `/app/answer.json` (a JSON array of N
|
| 33 |
+
integers in ascending order) and stops. The team succeeds if any agent's answer is right. The
|
| 34 |
+
instruction adapts the paper's (Appendix G) to the board and prescribes no protocol beyond that.
|
| 35 |
+
|
| 36 |
+
| | |
|
| 37 |
+
| --- | --- |
|
| 38 |
+
| Problems | 32 (the paper's held-out set size), each 16 integers drawn uniformly from 1 to 99, repeats allowed, from a fixed seed |
|
| 39 |
+
| Tasks | 160: one per problem and team size N ∈ {1, 2, 4, 8, 16}, whose team holds the problem's first N numbers, e.g. `agg-p07-n08` |
|
| 40 |
+
| Image | `python:3.12-slim`, prebuilt and public (no Dockerfile): HF Sandboxes, docker and podman |
|
| 41 |
+
| Agent / verifier timeout | 1800 s / 60 s |
|
| 42 |
+
| Resources | 1 CPU, 1 GB memory per agent |
|
| 43 |
+
|
| 44 |
+
```text
|
| 45 |
+
tasks/agg-pPP-nNN/
|
| 46 |
+
instruction.md the same for every problem of a team size: no number in it
|
| 47 |
+
task.toml
|
| 48 |
+
tests/test.sh the grader
|
| 49 |
+
tests/expected.json the answer: copied in only after the agent is done
|
| 50 |
+
solution/solve.sh an oracle with its own copy of the answer
|
| 51 |
+
roles/agg-pPP-nNN/
|
| 52 |
+
slot-01.md ... "Your private number: seventy-three", one per agent
|
| 53 |
+
problems.json the 32 problems
|
| 54 |
+
generate.py writes problems.json, tasks/ and roles/ from its seed (115)
|
| 55 |
+
check.py the checks that need no model
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
**Private numbers** reach each agent only through its own instructions: Flock's
|
| 59 |
+
`agents.role_files` gives agent `agent-00k` the text of `slot-0k.md` and nothing else. The role
|
| 60 |
+
files live outside the task folders, and a task folder puts nothing in the container while the
|
| 61 |
+
agent works (no `environment/`; `tests/` arrives after the agent is done), so no agent's
|
| 62 |
+
container holds another agent's number.
|
| 63 |
+
|
| 64 |
+
## Reward
|
| 65 |
+
|
| 66 |
+
`tests/test.sh` writes reward **1** to `/logs/verifier/reward.txt` when `/app/answer.json` is
|
| 67 |
+
exactly `tests/expected.json`: a JSON array of the team's integers in ascending order, one per
|
| 68 |
+
agent. Anything else scores **0**: a missing or unreadable file, invalid JSON, `NaN`, a
|
| 69 |
+
non-array, strings, words, floats or booleans, a missing, extra or dropped duplicate number, and
|
| 70 |
+
a wrong order. It writes 0 before it checks anything, so a crash also scores 0, and keeps a copy
|
| 71 |
+
of the answer with the trial's results. Each agent is scored on its own answer; the team
|
| 72 |
+
succeeds if any agent scores 1.
|
| 73 |
+
|
| 74 |
+
## Run it with Flock
|
| 75 |
+
|
| 76 |
+
Flock's [`experiments/s3-aggregation`](https://github.com/huggingface/flock/tree/main/experiments/s3-aggregation)
|
| 77 |
+
writes the spec for one team (the task, its N agents and their role files, the board) and
|
| 78 |
+
`experiments/s3/metrics.py` turns a run into one row per team: success, each agent's reward,
|
| 79 |
+
tokens and board posts, and the message graph's centralization and reciprocity (the paper's
|
| 80 |
+
Appendix M). On HF Sandboxes, with the board on a Space:
|
| 81 |
+
|
| 82 |
+
```sh
|
| 83 |
+
uv run experiments/s3-aggregation/team.py --problem 7 --agents 4 # out/agg-p07-n04/
|
| 84 |
+
uv run flock launch experiments/s3-aggregation/out/agg-p07-n04/spec.yaml
|
| 85 |
+
uv run experiments/s3/metrics.py .flock/agg-p07-n04-<time>/
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Checks
|
| 89 |
+
|
| 90 |
+
The checks that need no model, in one command (`uv` installs Harbor 0.25.0):
|
| 91 |
+
|
| 92 |
+
```sh
|
| 93 |
+
uv run check.py # the Trial on HF Sandboxes (HF_TOKEN, one cpu-basic sandbox)
|
| 94 |
+
uv run check.py --env docker # the Trial in local docker
|
| 95 |
+
uv run check.py --env none # without the Trial
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
1. **Generator:** `generate.py` reproduces `problems.json`, `tasks/` and `roles/` byte for byte;
|
| 99 |
+
another seed gives other problems; 32 problems of 16 integers in 1..99; the words read back
|
| 100 |
+
to their numbers; each task's team is its problem's first N numbers, and each role file holds
|
| 101 |
+
its own slot's number.
|
| 102 |
+
2. **Graders:** on all 160 tasks the oracle scores 1, and wrong, partial, padded, unsorted and
|
| 103 |
+
duplicate-dropping answers score 0; twelve kinds of malformed answer score 0 on one task per
|
| 104 |
+
team size.
|
| 105 |
+
3. **No-cheat, in the files:** a task folder holds only its five files, its instruction is the
|
| 106 |
+
same for every problem of its team size, the answer is only in `tests/` and `solution/`, and
|
| 107 |
+
the role files are outside `tasks/`.
|
| 108 |
+
4. **No-cheat, from inside a Trial:** a probe agent (no model) runs in `agg-p01-n16`'s container
|
| 109 |
+
while "the agent works" and finds no `tests/` or `solution/` and no file holding the answer,
|
| 110 |
+
a role line or a hyphenated number word of the problem; then it writes the answer, the same
|
| 111 |
+
search finds it (a control), and the task's verifier scores it 1.
|
| 112 |
+
|
| 113 |
+
`--env` takes a Harbor environment type or an import path. Harbor 0.25.0's `hf-sandbox` uploads
|
| 114 |
+
`tests/` with the host's file owner, which a sandbox can't take when the host's uid is over
|
| 115 |
+
65535 (some clusters); Flock's `--env flock.harbor.envs:HFSandbox`, with Flock installed, keeps
|
| 116 |
+
no owner.
|
| 117 |
+
|
| 118 |
+
To check the grader alone with Harbor: `harbor run --path tasks/agg-p07-n04 --agent oracle --env hf-sandbox`.
|
| 119 |
+
|
| 120 |
+
## Known limits
|
| 121 |
+
|
| 122 |
+
- **Private for now**, so whatever resolves and downloads the task (Flock's worker, which then
|
| 123 |
+
uploads it into the sandbox) needs a Hub token that can read it. The sandboxes never do.
|
| 124 |
+
- **Roles need Flock.** Harbor alone has no per-agent text: a task run without Flock's
|
| 125 |
+
`agents.role_files` gives the agent no number to share.
|
| 126 |
+
- **The grader can't see the board:** an agent could guess or copy a wrong number and still be
|
| 127 |
+
scored only on its file. The board export in the run directory shows what was said.
|
| 128 |
+
- **One board per team.** The instruction has no run tag, so a reused board's earlier posts
|
| 129 |
+
would read as this team's: give each team a new board (Flock's local board is new each run;
|
| 130 |
+
delete a Space board after its run).
|
| 131 |
+
- **Board rules** are enforced only where Flock's rule proxy runs (docker, podman); on HF
|
| 132 |
+
Sandboxes they are not.
|
| 133 |
+
- **Not the paper's setup:** a message board instead of `message`/`read_messages` tools with
|
| 134 |
+
notifications, an answer file instead of a `####` line, no example message, no token cost in
|
| 135 |
+
the reward, and N = 1 is a solo control rather than a team.
|
check.py
ADDED
|
@@ -0,0 +1,318 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# requires-python = ">=3.12"
|
| 3 |
+
# dependencies = ["harbor==0.25.0"]
|
| 4 |
+
# ///
|
| 5 |
+
"""s3-aggregation's checks that need no model (huggingface/flock#115, section 5):
|
| 6 |
+
|
| 7 |
+
uv run check.py # all of them; the Trial runs on HF Sandboxes (HF_TOKEN)
|
| 8 |
+
uv run check.py --env docker # the Trial in local docker instead
|
| 9 |
+
uv run check.py --env none # skip the Trial
|
| 10 |
+
|
| 11 |
+
1. Generator: generate.py reproduces problems.json, tasks/ and roles/ byte for byte from its
|
| 12 |
+
seed; another seed gives other problems; 32 problems of 16 integers in 1..99; the English
|
| 13 |
+
words read back to their numbers; each task's team is its problem's first N numbers, and each
|
| 14 |
+
role file holds its own slot's number.
|
| 15 |
+
2. Graders: on every task, the oracle (solution/solve.sh) scores 1, and a wrong, partial,
|
| 16 |
+
padded, unsorted or duplicate-dropping answer scores 0; malformed answers (missing, empty, not
|
| 17 |
+
JSON, NaN, an object, strings, words, floats, booleans, nested, a "####" prefix, invalid UTF-8)
|
| 18 |
+
score 0 on one task per team size.
|
| 19 |
+
3. No-cheat, in the files: a task folder holds only instruction.md, task.toml, tests/ and
|
| 20 |
+
solution/; its instruction is the same for every problem of its team size; the answer is only
|
| 21 |
+
in tests/ and solution/; the role files live outside tasks/.
|
| 22 |
+
4. No-cheat, from inside a Trial (`--env`): a probe agent (no model) runs in the task's
|
| 23 |
+
container while "the agent works" and finds no tests/ or solution/ and no file holding the
|
| 24 |
+
answer, a role line or a hyphenated number word of the team (the 16-agent task, so every
|
| 25 |
+
number of the problem); then it writes the answer, the same search finds it (a control),
|
| 26 |
+
and the task's own verifier scores it 1.
|
| 27 |
+
`--env` takes a Harbor environment type or an import path. Harbor 0.25.0's hf-sandbox
|
| 28 |
+
uploads tests/ with the host's file owner, which a sandbox can't take when the host's uid is
|
| 29 |
+
over 65535 (some clusters): use flock's `--env flock.harbor.envs:HFSandbox` there.
|
| 30 |
+
"""
|
| 31 |
+
|
| 32 |
+
import argparse
|
| 33 |
+
import asyncio
|
| 34 |
+
import base64
|
| 35 |
+
import json
|
| 36 |
+
import os
|
| 37 |
+
import shlex
|
| 38 |
+
import subprocess
|
| 39 |
+
import sys
|
| 40 |
+
import tempfile
|
| 41 |
+
from pathlib import Path
|
| 42 |
+
|
| 43 |
+
HERE = Path(__file__).resolve().parent
|
| 44 |
+
sys.path.insert(0, str(HERE))
|
| 45 |
+
import generate as g # noqa: E402
|
| 46 |
+
|
| 47 |
+
TASK_FILES = {"instruction.md", "task.toml", "tests/test.sh", "tests/expected.json",
|
| 48 |
+
"solution/solve.sh"}
|
| 49 |
+
PROBE_TASK = "agg-p01-n16"
|
| 50 |
+
failures: list[str] = []
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def check(ok: bool, what: str) -> None:
|
| 54 |
+
if not ok:
|
| 55 |
+
failures.append(what)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def files(root: Path) -> dict[str, tuple[bytes, bool]]:
|
| 59 |
+
"""Relative path -> (bytes, executable) for the generated files under root."""
|
| 60 |
+
out = {"problems.json": ((root / "problems.json").read_bytes(), False)}
|
| 61 |
+
for folder in ("tasks", "roles"):
|
| 62 |
+
for path in sorted((root / folder).rglob("*")):
|
| 63 |
+
if path.is_file():
|
| 64 |
+
out[str(path.relative_to(root))] = (path.read_bytes(),
|
| 65 |
+
os.access(path, os.X_OK))
|
| 66 |
+
return out
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
VALUES = {w: i for i, w in enumerate(g.ONES) if w} | {
|
| 70 |
+
w: 10 * i for i, w in enumerate(g.TENS) if w}
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def read_words(text: str) -> int:
|
| 74 |
+
"""English words back to a number, independently of generate.words."""
|
| 75 |
+
head, _, tail = text.partition("-")
|
| 76 |
+
return VALUES[head] + (VALUES[tail] if tail else 0)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def check_generator() -> None:
|
| 80 |
+
with tempfile.TemporaryDirectory() as d:
|
| 81 |
+
g.generate(Path(d))
|
| 82 |
+
check(files(Path(d)) == files(HERE), "generate.py does not reproduce the committed files")
|
| 83 |
+
drawn = g.problems()
|
| 84 |
+
check(drawn == g.problems(), "the same seed gave other problems")
|
| 85 |
+
check(drawn != g.problems(g.SEED + 1), "another seed gave the same problems")
|
| 86 |
+
check(len(drawn) == 32 and all(len(p) == 16 and all(type(x) is int and 1 <= x <= 99
|
| 87 |
+
for x in p) for p in drawn),
|
| 88 |
+
"not 32 problems of 16 integers in 1..99")
|
| 89 |
+
check(all(read_words(g.words(n)) == n for n in range(1, 100))
|
| 90 |
+
and len({g.words(n) for n in range(1, 100)}) == 99, "the English words are wrong")
|
| 91 |
+
names = set()
|
| 92 |
+
for p, numbers in enumerate(drawn, 1):
|
| 93 |
+
for n in g.SIZES:
|
| 94 |
+
name = g.task_name(p, n)
|
| 95 |
+
names.add(name)
|
| 96 |
+
team = numbers[:n]
|
| 97 |
+
expected = json.loads((HERE / "tasks" / name / "tests" / "expected.json").read_text())
|
| 98 |
+
check(expected == sorted(team), f"{name}: expected.json is not the first {n} sorted")
|
| 99 |
+
roles = sorted((HERE / "roles" / name).glob("*"))
|
| 100 |
+
check([r.name for r in roles] == [f"slot-{k:02d}.md" for k in range(1, n + 1)],
|
| 101 |
+
f"{name}: not one role file per slot")
|
| 102 |
+
for slot, (path, number) in enumerate(zip(roles, team, strict=False), 1):
|
| 103 |
+
text = path.read_text()
|
| 104 |
+
check(text == f"Your private number: {g.words(number)}\n"
|
| 105 |
+
and read_words(text.split(": ")[1].strip()) == number,
|
| 106 |
+
f"{name}: slot {slot} does not hold its own number")
|
| 107 |
+
check({p.name for p in (HERE / "tasks").iterdir()} == names, "tasks/ has other folders")
|
| 108 |
+
check({p.name for p in (HERE / "roles").iterdir()} == names, "roles/ has other folders")
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def grade(task: Path, answer: bytes | None) -> int:
|
| 112 |
+
"""The task's tests/test.sh on `answer` (None: no file); its reward."""
|
| 113 |
+
with tempfile.TemporaryDirectory() as d:
|
| 114 |
+
path, verifier = Path(d) / "answer.json", Path(d) / "verifier"
|
| 115 |
+
if answer is not None:
|
| 116 |
+
path.write_bytes(answer)
|
| 117 |
+
subprocess.run(["bash", str(task / "tests" / "test.sh")], capture_output=True, timeout=60,
|
| 118 |
+
env={**os.environ, "ANSWER": str(path), "VERIFIER_DIR": str(verifier)},
|
| 119 |
+
check=False)
|
| 120 |
+
return int((verifier / "reward.txt").read_text().strip())
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def oracle(task: Path) -> int:
|
| 124 |
+
with tempfile.TemporaryDirectory() as d:
|
| 125 |
+
path = Path(d) / "app" / "answer.json"
|
| 126 |
+
subprocess.run(["bash", str(task / "solution" / "solve.sh")], capture_output=True,
|
| 127 |
+
timeout=60, env={**os.environ, "ANSWER": str(path)}, check=True)
|
| 128 |
+
return grade(task, path.read_bytes())
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def wrong_answers(team: list[int]) -> dict[str, list]:
|
| 132 |
+
"""The answers that must score 0 for a team (sorted): those that apply to it."""
|
| 133 |
+
last = team[-1] + 1 if team[-1] < 99 else team[-1] - 1
|
| 134 |
+
out = {"wrong": sorted(team[:-1] + [last]), "partial": team[:-1],
|
| 135 |
+
"padded": sorted(team + [team[-1]])}
|
| 136 |
+
if len(set(team)) > 1:
|
| 137 |
+
out["unsorted"] = team[::-1]
|
| 138 |
+
if len(set(team)) < len(team):
|
| 139 |
+
out["duplicate-dropping"] = sorted(set(team))
|
| 140 |
+
return out
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def malformed(team: list[int]) -> dict[str, bytes | None]:
|
| 144 |
+
dump = json.dumps(team).encode()
|
| 145 |
+
return {"missing": None, "empty": b"", "not JSON": b"[1, 2,", "NaN": b"[NaN]",
|
| 146 |
+
"object": json.dumps({"answer": team}).encode(),
|
| 147 |
+
"strings": json.dumps([str(x) for x in team]).encode(),
|
| 148 |
+
"words": json.dumps([g.words(x) for x in team]).encode(),
|
| 149 |
+
"floats": json.dumps([float(x) for x in team]).encode(),
|
| 150 |
+
"booleans": json.dumps([True] * len(team)).encode(),
|
| 151 |
+
"nested": json.dumps([team]).encode(), "#### prefix": b"#### " + dump,
|
| 152 |
+
"invalid UTF-8": b"\xff" + dump}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def check_graders() -> dict[str, int]:
|
| 156 |
+
covered: dict[str, int] = {}
|
| 157 |
+
for task in sorted((HERE / "tasks").iterdir()):
|
| 158 |
+
team = json.loads((task / "tests" / "expected.json").read_text())
|
| 159 |
+
check(oracle(task) == 1, f"{task.name}: the oracle does not score 1")
|
| 160 |
+
cases = {k: json.dumps(v).encode() for k, v in wrong_answers(team).items()}
|
| 161 |
+
if task.name.startswith("agg-p01-"):
|
| 162 |
+
cases |= malformed(team)
|
| 163 |
+
for case, answer in cases.items():
|
| 164 |
+
covered[case] = covered.get(case, 0) + 1
|
| 165 |
+
check(grade(task, answer) == 0, f"{task.name}: a {case} answer does not score 0")
|
| 166 |
+
check(covered.get("duplicate-dropping", 0) > 0, "no task has a duplicate to drop")
|
| 167 |
+
return covered
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def check_files() -> None:
|
| 171 |
+
by_size: dict[int, set[tuple[str, str]]] = {}
|
| 172 |
+
for task in sorted((HERE / "tasks").iterdir()):
|
| 173 |
+
listed = {str(p.relative_to(task)) for p in task.rglob("*") if p.is_file()}
|
| 174 |
+
check(listed == TASK_FILES, f"{task.name}: holds {sorted(listed ^ TASK_FILES)}")
|
| 175 |
+
n = int(task.name.split("-n")[1])
|
| 176 |
+
problem = int(task.name.split("-p")[1][:2])
|
| 177 |
+
toml = (task / "task.toml").read_text().replace(task.name, "TASK").replace(
|
| 178 |
+
f"problem = {problem}\n", "problem = P\n")
|
| 179 |
+
by_size.setdefault(n, set()).add(((task / "instruction.md").read_text(), toml))
|
| 180 |
+
answer = (task / "tests" / "expected.json").read_text().strip()
|
| 181 |
+
holders = {str(p.relative_to(task)) for p in task.rglob("*")
|
| 182 |
+
if p.is_file() and answer in p.read_text()}
|
| 183 |
+
check(holders == {"tests/expected.json", "solution/solve.sh"},
|
| 184 |
+
f"{task.name}: the answer is in {sorted(holders)}")
|
| 185 |
+
check(not any("Your private number:" in (task / f).read_text() for f in TASK_FILES),
|
| 186 |
+
f"{task.name}: a role line is in the task folder")
|
| 187 |
+
check(all(len(v) == 1 for v in by_size.values()),
|
| 188 |
+
"an instruction or task.toml differs between problems of one team size")
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
PROBE_SH = r"""
|
| 192 |
+
mapfile -t secrets < <(printf %s "$1" | base64 -d)
|
| 193 |
+
for d in /tests /solution; do [ -e "$d" ] && echo "visible $d"; done
|
| 194 |
+
args=(); for s in "${secrets[@]}"; do args+=(-e "$s"); done
|
| 195 |
+
search() {
|
| 196 |
+
find / -xdev \( -path /proc -o -path /sys -o -path /dev -o -path /logs \) -prune -o -type f \
|
| 197 |
+
-size -20M -print0 2>/dev/null | xargs -0 -r grep -IlF "$@" 2>/dev/null
|
| 198 |
+
}
|
| 199 |
+
search "${args[@]}" | sed 's/^/holds /'
|
| 200 |
+
mkdir -p /app && printf %s "$2" > /app/answer.json
|
| 201 |
+
search -e "$2" | sed 's/^/control /' # the same search finds the answer once it is written
|
| 202 |
+
"""
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
try:
|
| 206 |
+
from harbor.agents.base import BaseAgent
|
| 207 |
+
|
| 208 |
+
class Probe(BaseAgent):
|
| 209 |
+
"""No model: looks around the container as an agent could while it works, writes
|
| 210 |
+
`probe.json` in its logs dir on the host, then the answer for the verifier."""
|
| 211 |
+
|
| 212 |
+
def __init__(self, *args, secrets=(), answer="", task_instruction="", **kwargs):
|
| 213 |
+
super().__init__(*args, **kwargs)
|
| 214 |
+
self.secrets, self.answer, self.task_instruction = secrets, answer, task_instruction
|
| 215 |
+
|
| 216 |
+
@staticmethod
|
| 217 |
+
def name() -> str:
|
| 218 |
+
return "s3-aggregation-probe"
|
| 219 |
+
|
| 220 |
+
def version(self) -> str:
|
| 221 |
+
return "1"
|
| 222 |
+
|
| 223 |
+
async def setup(self, environment) -> None:
|
| 224 |
+
pass
|
| 225 |
+
|
| 226 |
+
async def run(self, instruction, environment, context) -> None:
|
| 227 |
+
# the secrets travel base64-encoded: a copy of the command in the container would
|
| 228 |
+
# otherwise hold them
|
| 229 |
+
encoded = base64.b64encode("\n".join(self.secrets).encode()).decode()
|
| 230 |
+
result = await environment.exec(
|
| 231 |
+
f"bash -c {shlex.quote(PROBE_SH)} probe {encoded} {shlex.quote(self.answer)}",
|
| 232 |
+
timeout_sec=600)
|
| 233 |
+
lines = (result.stdout or "").splitlines()
|
| 234 |
+
(self.logs_dir / "probe.json").write_text(json.dumps({
|
| 235 |
+
"return_code": result.return_code,
|
| 236 |
+
"visible": [x.split(" ", 1)[1] for x in lines if x.startswith("visible ")],
|
| 237 |
+
"holds": [x.split(" ", 1)[1] for x in lines if x.startswith("holds ")],
|
| 238 |
+
"control": [x.split(" ", 1)[1] for x in lines if x.startswith("control ")],
|
| 239 |
+
"instruction_is_the_task_text":
|
| 240 |
+
instruction.strip() == self.task_instruction.strip(),
|
| 241 |
+
}, indent=1))
|
| 242 |
+
except ImportError: # `--env none` needs no Harbor
|
| 243 |
+
Probe = None
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
async def check_trial(env: str, jobs: Path) -> dict:
|
| 247 |
+
from harbor.models.trial.config import (
|
| 248 |
+
AgentConfig,
|
| 249 |
+
EnvironmentConfig,
|
| 250 |
+
TaskConfig,
|
| 251 |
+
TrialConfig,
|
| 252 |
+
)
|
| 253 |
+
from harbor.trial.trial import Trial
|
| 254 |
+
|
| 255 |
+
task, roles = HERE / "tasks" / PROBE_TASK, HERE / "roles" / PROBE_TASK
|
| 256 |
+
answer = (task / "tests" / "expected.json").read_text().strip()
|
| 257 |
+
lines = [p.read_text().strip() for p in sorted(roles.glob("slot-*.md"))]
|
| 258 |
+
hyphenated = sorted({w for line in lines if "-" in (w := line.split(": ")[1])})
|
| 259 |
+
secrets = [answer, answer.replace(" ", ""), "Your private number:", *lines, *hyphenated]
|
| 260 |
+
environment = (EnvironmentConfig(import_path=env) if ":" in env else
|
| 261 |
+
EnvironmentConfig(type=env, kwargs={"flavor": "cpu-basic", "job_timeout": 900}
|
| 262 |
+
if env == "hf-sandbox" else {}))
|
| 263 |
+
if ":" in env and "Sandbox" in env:
|
| 264 |
+
environment.kwargs = {"flavor": "cpu-basic", "job_timeout": 900}
|
| 265 |
+
config = TrialConfig(
|
| 266 |
+
task=TaskConfig(path=task), trial_name=f"probe-{PROBE_TASK}", trials_dir=jobs,
|
| 267 |
+
agent=AgentConfig(import_path="__main__:Probe", kwargs={
|
| 268 |
+
"secrets": secrets, "answer": answer,
|
| 269 |
+
"task_instruction": (task / "instruction.md").read_text()}),
|
| 270 |
+
environment=environment)
|
| 271 |
+
trial = await Trial.create(config)
|
| 272 |
+
result = await trial.run()
|
| 273 |
+
probe_file = jobs / config.trial_name / "agent" / "probe.json"
|
| 274 |
+
probe = json.loads(probe_file.read_text()) if probe_file.is_file() else None
|
| 275 |
+
rewards = result.verifier_result.rewards if result.verifier_result else None
|
| 276 |
+
error = result.exception_info.exception_message if result.exception_info else None
|
| 277 |
+
check(probe is not None and probe["return_code"] == 0, f"Trial: the probe did not run ({error})")
|
| 278 |
+
if probe is not None:
|
| 279 |
+
check(not probe["visible"], f"Trial: visible while the agent works: {probe['visible']}")
|
| 280 |
+
check(not probe["holds"], f"Trial: files hold the team's numbers: {probe['holds']}")
|
| 281 |
+
check("/app/answer.json" in probe["control"],
|
| 282 |
+
f"Trial: the search did not find the written answer ({probe['control']})")
|
| 283 |
+
check(probe["instruction_is_the_task_text"], "Trial: the instruction is not the task's")
|
| 284 |
+
check(rewards == {"reward": 1.0}, f"Trial: the verifier gave {rewards} ({error})")
|
| 285 |
+
return {"probe": probe, "rewards": rewards, "searched_for": len(secrets)}
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
def main() -> int:
|
| 289 |
+
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
| 290 |
+
parser.add_argument("--env", default="hf-sandbox",
|
| 291 |
+
help="Harbor environment type or import path for the Trial; none: skip")
|
| 292 |
+
parser.add_argument("--jobs-dir", type=Path, default=None,
|
| 293 |
+
help="keep the Trial's files here (default: a temporary directory)")
|
| 294 |
+
args = parser.parse_args()
|
| 295 |
+
check_generator()
|
| 296 |
+
print(f"1. generator: {len(failures)} failures")
|
| 297 |
+
before = len(failures)
|
| 298 |
+
covered = check_graders()
|
| 299 |
+
print(f"2. graders: {len(failures) - before} failures; zero-score cases checked: {covered}")
|
| 300 |
+
before = len(failures)
|
| 301 |
+
check_files()
|
| 302 |
+
print(f"3. no-cheat (files): {len(failures) - before} failures")
|
| 303 |
+
if args.env != "none":
|
| 304 |
+
before = len(failures)
|
| 305 |
+
with tempfile.TemporaryDirectory() as d:
|
| 306 |
+
jobs = args.jobs_dir or Path(d)
|
| 307 |
+
jobs.mkdir(parents=True, exist_ok=True)
|
| 308 |
+
report = asyncio.run(check_trial(args.env, jobs))
|
| 309 |
+
print(f"4. no-cheat (Trial on {args.env}, {PROBE_TASK}): {len(failures) - before} "
|
| 310 |
+
f"failures; {json.dumps(report)}")
|
| 311 |
+
for failure in failures:
|
| 312 |
+
print("FAIL:", failure)
|
| 313 |
+
print("all checks passed" if not failures else f"{len(failures)} checks failed")
|
| 314 |
+
return 1 if failures else 0
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
if __name__ == "__main__":
|
| 318 |
+
sys.exit(main())
|
generate.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Regenerate s3-aggregation from its seed: `python generate.py` (Python 3.10+, no dependencies).
|
| 2 |
+
|
| 3 |
+
Writes `problems.json`, `tasks/` and `roles/` next to this file, replacing what is there:
|
| 4 |
+
- 32 problems, each 16 integers drawn uniformly from 1 to 99 (repeats allowed), from SEED;
|
| 5 |
+
- one task per problem and team size N in SIZES, `agg-pPP-nNN`, whose team holds the problem's
|
| 6 |
+
first N numbers;
|
| 7 |
+
- one role file per agent of each task, `roles/<task>/slot-NN.md`, outside the task folders, so
|
| 8 |
+
an agent's container never holds another agent's number.
|
| 9 |
+
|
| 10 |
+
check.py checks that this reproduces the committed files byte for byte.
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
import json
|
| 14 |
+
import random
|
| 15 |
+
import shutil
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
|
| 18 |
+
SEED = 115 # huggingface/flock#115
|
| 19 |
+
PROBLEMS = 32 # the paper's held-out set size
|
| 20 |
+
NUMBERS = 16 # per problem; a team of N holds the first N
|
| 21 |
+
SIZES = (1, 2, 4, 8, 16)
|
| 22 |
+
LOW, HIGH = 1, 99
|
| 23 |
+
IMAGE = "python:3.12-slim" # public and prebuilt: HF Sandboxes need one, docker and podman too
|
| 24 |
+
|
| 25 |
+
ONES = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
|
| 26 |
+
"eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
|
| 27 |
+
"eighteen", "nineteen"]
|
| 28 |
+
TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
|
| 29 |
+
|
| 30 |
+
HERE = Path(__file__).resolve().parent
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def words(n: int) -> str:
|
| 34 |
+
"""1..99 in English words, e.g. 73 -> "seventy-three"."""
|
| 35 |
+
if not LOW <= n <= HIGH:
|
| 36 |
+
raise ValueError(f"{n} is outside {LOW}..{HIGH}")
|
| 37 |
+
if n < 20:
|
| 38 |
+
return ONES[n]
|
| 39 |
+
return TENS[n // 10] + (f"-{ONES[n % 10]}" if n % 10 else "")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def problems(seed: int = SEED) -> list[list[int]]:
|
| 43 |
+
rng = random.Random(seed)
|
| 44 |
+
return [[rng.randint(LOW, HIGH) for _ in range(NUMBERS)] for _ in range(PROBLEMS)]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def task_name(problem: int, n: int) -> str:
|
| 48 |
+
"""`problem` counts from 1."""
|
| 49 |
+
return f"agg-p{problem:02d}-n{n:02d}"
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def instruction(n: int) -> str:
|
| 53 |
+
if n == 1:
|
| 54 |
+
return """# Sort the team's private numbers
|
| 55 |
+
|
| 56 |
+
You are the only agent on this team, solving a private-information number sorting task. You
|
| 57 |
+
hold one private integer from 1 to 99, written in English words. It is in your instructions,
|
| 58 |
+
under "Your private number".
|
| 59 |
+
|
| 60 |
+
Write `/app/answer.json` (create `/app` if needed): a JSON array holding your number's numeric
|
| 61 |
+
value, as digits. Then stop.
|
| 62 |
+
"""
|
| 63 |
+
return f"""# Sort the team's private numbers
|
| 64 |
+
|
| 65 |
+
You are on a team of {n} agents solving a private-information number sorting task. Each agent
|
| 66 |
+
holds one private integer from 1 to 99, written in English words. Yours is in your instructions,
|
| 67 |
+
under "Your private number". You know only your own number, and the others don't know it unless
|
| 68 |
+
you tell them.
|
| 69 |
+
|
| 70 |
+
The team must find all {n} numbers and list their numeric values in ascending order. Keep equal
|
| 71 |
+
numbers from different agents as separate entries: each agent's number appears once in the list,
|
| 72 |
+
even when another agent holds the same value.
|
| 73 |
+
|
| 74 |
+
1. Share your number with the team on the message board.
|
| 75 |
+
2. Read the board for the other participants' numbers. Note which participant each number came
|
| 76 |
+
from, so that a number posted more than once is counted once.
|
| 77 |
+
3. Once you have one number from every participant, yourself included, write `/app/answer.json`
|
| 78 |
+
(create `/app` if needed): a JSON array of the {n} integers, as digits, in ascending order.
|
| 79 |
+
Then stop.
|
| 80 |
+
|
| 81 |
+
Any agent may write the full answer, and the team succeeds if at least one agent's answer is
|
| 82 |
+
correct. Your instructions name the other participants and explain the board's tools.
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def task_toml(problem: int, n: int) -> str:
|
| 87 |
+
return f"""schema_version = "1.4"
|
| 88 |
+
|
| 89 |
+
[task]
|
| 90 |
+
name = "HuggingFaceSwarms/{task_name(problem, n)}"
|
| 91 |
+
version = "0.1.0"
|
| 92 |
+
description = "s3-aggregation: {n} agents each hold a private number; the team lists them all in ascending order."
|
| 93 |
+
keywords = ["multi-agent", "message-board", "s3", "aggregation"]
|
| 94 |
+
|
| 95 |
+
[metadata]
|
| 96 |
+
problem = {problem}
|
| 97 |
+
agents = {n}
|
| 98 |
+
seed = {SEED}
|
| 99 |
+
|
| 100 |
+
[agent]
|
| 101 |
+
timeout_sec = 1800
|
| 102 |
+
|
| 103 |
+
[environment]
|
| 104 |
+
# Prebuilt and public, with no Dockerfile: HF Sandboxes need one, and docker and podman use it
|
| 105 |
+
# too. Nothing task-specific is in the container: each agent's number reaches it only through
|
| 106 |
+
# its own instructions (the flock role file), and tests/ arrive only when the agent is done.
|
| 107 |
+
docker_image = "{IMAGE}"
|
| 108 |
+
cpus = 1
|
| 109 |
+
memory_mb = 1024
|
| 110 |
+
|
| 111 |
+
[verifier]
|
| 112 |
+
timeout_sec = 60
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
TEST_SH = r"""#!/bin/bash
|
| 117 |
+
# Reward 1 if /app/answer.json is exactly expected.json: a JSON array of the team's integers in
|
| 118 |
+
# ascending order, one per agent (equal numbers kept). Anything else scores 0: a missing or
|
| 119 |
+
# unreadable file, invalid UTF-8 or JSON, NaN or Infinity, a non-array, strings, floats or
|
| 120 |
+
# booleans, a missing, extra or dropped duplicate number, and a wrong order. The script writes 0
|
| 121 |
+
# before it checks anything, so a crash of the check also leaves reward 0, and keeps a copy of
|
| 122 |
+
# the answer with the trial's results. ANSWER, EXPECTED and VERIFIER_DIR override the paths, to
|
| 123 |
+
# test the grader locally.
|
| 124 |
+
answer=${ANSWER:-/app/answer.json}
|
| 125 |
+
expected=${EXPECTED:-$(dirname "$0")/expected.json}
|
| 126 |
+
verifier=${VERIFIER_DIR:-/logs/verifier}
|
| 127 |
+
mkdir -p "$verifier"
|
| 128 |
+
echo 0 > "$verifier/reward.txt"
|
| 129 |
+
cp "$answer" "$verifier/answer.json" 2>/dev/null || true
|
| 130 |
+
ANSWER="$answer" EXPECTED="$expected" VERIFIER_DIR="$verifier" python3 - <<'PY' || true
|
| 131 |
+
import json
|
| 132 |
+
import os
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def reject_constant(name):
|
| 136 |
+
raise ValueError(f"{name} is not JSON")
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def load(path):
|
| 140 |
+
with open(path, "rb") as stream:
|
| 141 |
+
return json.loads(stream.read().decode("utf-8"), parse_constant=reject_constant)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
try:
|
| 145 |
+
answer, expected = load(os.environ["ANSWER"]), load(os.environ["EXPECTED"])
|
| 146 |
+
valid = (
|
| 147 |
+
isinstance(answer, list)
|
| 148 |
+
and all(type(x) is int for x in answer) # not bool, float or str
|
| 149 |
+
and answer == expected
|
| 150 |
+
)
|
| 151 |
+
except Exception: # missing file, invalid UTF-8 or JSON, NaN, RecursionError
|
| 152 |
+
valid = False
|
| 153 |
+
if valid:
|
| 154 |
+
with open(os.path.join(os.environ["VERIFIER_DIR"], "reward.txt"), "w") as stream:
|
| 155 |
+
stream.write("1")
|
| 156 |
+
print("reward:", 1 if valid else 0)
|
| 157 |
+
PY
|
| 158 |
+
"""
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def solve_sh(answer: list[int]) -> str:
|
| 162 |
+
return f"""#!/bin/bash
|
| 163 |
+
# Oracle: the team's answer from its own copy (not tests/), to validate the grader.
|
| 164 |
+
answer=${{ANSWER:-/app/answer.json}}
|
| 165 |
+
mkdir -p "$(dirname "$answer")"
|
| 166 |
+
echo '{json.dumps(answer)}' > "$answer"
|
| 167 |
+
"""
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def role(number: int) -> str:
|
| 171 |
+
return f"Your private number: {words(number)}\n"
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def write(path: Path, text: str, mode: int = 0o644) -> None:
|
| 175 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 176 |
+
path.write_text(text, encoding="utf-8")
|
| 177 |
+
path.chmod(mode)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def generate(root: Path = HERE, seed: int = SEED) -> None:
|
| 181 |
+
for folder in ("tasks", "roles"):
|
| 182 |
+
shutil.rmtree(root / folder, ignore_errors=True)
|
| 183 |
+
drawn = problems(seed)
|
| 184 |
+
rows = ",\n".join(f' "p{i:02d}": {json.dumps(numbers)}' for i, numbers in enumerate(drawn, 1))
|
| 185 |
+
write(root / "problems.json", f'{{"seed": {seed}, "problems": {{\n{rows}\n}}}}\n')
|
| 186 |
+
for p, numbers in enumerate(drawn, 1):
|
| 187 |
+
for n in SIZES:
|
| 188 |
+
team, name = numbers[:n], task_name(p, n)
|
| 189 |
+
task = root / "tasks" / name
|
| 190 |
+
write(task / "instruction.md", instruction(n))
|
| 191 |
+
write(task / "task.toml", task_toml(p, n))
|
| 192 |
+
write(task / "tests" / "test.sh", TEST_SH, 0o755)
|
| 193 |
+
write(task / "tests" / "expected.json", json.dumps(sorted(team)) + "\n")
|
| 194 |
+
write(task / "solution" / "solve.sh", solve_sh(sorted(team)), 0o755)
|
| 195 |
+
for slot, number in enumerate(team, 1):
|
| 196 |
+
write(root / "roles" / name / f"slot-{slot:02d}.md", role(number))
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
if __name__ == "__main__":
|
| 200 |
+
generate()
|
| 201 |
+
print(f"{PROBLEMS} problems x {len(SIZES)} team sizes = {PROBLEMS * len(SIZES)} tasks "
|
| 202 |
+
f"(seed {SEED})")
|
problems.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{"seed": 115, "problems": {
|
| 2 |
+
"p01": [37, 26, 15, 69, 15, 43, 97, 71, 38, 87, 82, 37, 88, 44, 62, 8],
|
| 3 |
+
"p02": [71, 71, 19, 20, 6, 37, 23, 63, 95, 76, 32, 22, 24, 19, 68, 28],
|
| 4 |
+
"p03": [19, 81, 89, 55, 2, 92, 26, 68, 43, 78, 32, 83, 92, 36, 77, 30],
|
| 5 |
+
"p04": [33, 53, 48, 71, 25, 62, 87, 90, 44, 24, 97, 77, 79, 52, 95, 74],
|
| 6 |
+
"p05": [87, 93, 96, 57, 40, 25, 68, 84, 18, 79, 43, 66, 33, 71, 70, 82],
|
| 7 |
+
"p06": [76, 23, 8, 85, 11, 54, 78, 35, 4, 5, 18, 7, 66, 38, 54, 89],
|
| 8 |
+
"p07": [49, 36, 38, 48, 54, 22, 88, 8, 66, 25, 16, 78, 9, 42, 86, 2],
|
| 9 |
+
"p08": [37, 71, 88, 44, 66, 68, 24, 35, 56, 70, 76, 70, 64, 92, 84, 23],
|
| 10 |
+
"p09": [40, 67, 65, 43, 60, 66, 14, 18, 88, 81, 8, 20, 14, 68, 31, 63],
|
| 11 |
+
"p10": [69, 5, 19, 12, 79, 51, 63, 32, 96, 25, 4, 56, 12, 86, 58, 75],
|
| 12 |
+
"p11": [12, 98, 75, 78, 67, 84, 25, 11, 40, 23, 94, 74, 16, 4, 74, 42],
|
| 13 |
+
"p12": [2, 50, 95, 12, 99, 30, 15, 31, 45, 44, 31, 33, 24, 95, 79, 11],
|
| 14 |
+
"p13": [42, 78, 48, 61, 47, 56, 2, 2, 23, 82, 62, 25, 85, 68, 60, 93],
|
| 15 |
+
"p14": [84, 29, 53, 49, 44, 25, 59, 39, 96, 72, 78, 1, 37, 51, 45, 11],
|
| 16 |
+
"p15": [37, 29, 57, 18, 49, 79, 50, 62, 53, 30, 43, 30, 78, 82, 27, 40],
|
| 17 |
+
"p16": [38, 63, 30, 63, 51, 78, 58, 81, 2, 18, 88, 10, 58, 35, 92, 16],
|
| 18 |
+
"p17": [40, 10, 95, 31, 99, 77, 90, 70, 43, 2, 78, 34, 76, 38, 70, 40],
|
| 19 |
+
"p18": [72, 16, 84, 86, 1, 59, 2, 59, 47, 43, 83, 66, 7, 42, 74, 79],
|
| 20 |
+
"p19": [37, 41, 62, 88, 34, 10, 69, 65, 29, 81, 35, 71, 87, 98, 22, 67],
|
| 21 |
+
"p20": [44, 73, 45, 74, 97, 81, 73, 58, 65, 68, 31, 5, 61, 49, 96, 29],
|
| 22 |
+
"p21": [57, 34, 71, 68, 19, 82, 73, 99, 18, 72, 39, 16, 76, 50, 64, 43],
|
| 23 |
+
"p22": [4, 41, 89, 71, 5, 23, 27, 15, 31, 74, 10, 8, 22, 88, 76, 77],
|
| 24 |
+
"p23": [20, 55, 45, 1, 84, 81, 30, 79, 51, 7, 16, 69, 52, 3, 96, 35],
|
| 25 |
+
"p24": [95, 82, 5, 50, 95, 38, 87, 89, 39, 37, 67, 10, 87, 92, 39, 92],
|
| 26 |
+
"p25": [33, 22, 18, 88, 46, 73, 2, 6, 21, 19, 6, 3, 21, 73, 57, 21],
|
| 27 |
+
"p26": [21, 20, 4, 1, 36, 12, 37, 66, 47, 2, 97, 77, 28, 75, 22, 94],
|
| 28 |
+
"p27": [99, 74, 86, 15, 14, 95, 83, 47, 96, 56, 12, 88, 60, 7, 84, 6],
|
| 29 |
+
"p28": [58, 38, 67, 70, 33, 12, 77, 93, 7, 24, 53, 94, 8, 92, 15, 63],
|
| 30 |
+
"p29": [23, 22, 45, 82, 92, 89, 38, 56, 43, 12, 63, 84, 76, 68, 6, 12],
|
| 31 |
+
"p30": [21, 65, 74, 74, 43, 41, 53, 87, 43, 89, 43, 61, 65, 3, 97, 36],
|
| 32 |
+
"p31": [25, 23, 4, 36, 82, 28, 51, 3, 2, 39, 27, 50, 16, 76, 63, 14],
|
| 33 |
+
"p32": [65, 80, 85, 43, 86, 61, 58, 89, 65, 76, 31, 67, 8, 91, 91, 42]
|
| 34 |
+
}}
|
roles/agg-p01-n01/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n02/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n02/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty-six
|
roles/agg-p01-n04/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n04/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty-six
|
roles/agg-p01-n04/slot-03.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: fifteen
|
roles/agg-p01-n04/slot-04.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: sixty-nine
|
roles/agg-p01-n08/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n08/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty-six
|
roles/agg-p01-n08/slot-03.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: fifteen
|
roles/agg-p01-n08/slot-04.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: sixty-nine
|
roles/agg-p01-n08/slot-05.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: fifteen
|
roles/agg-p01-n08/slot-06.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: forty-three
|
roles/agg-p01-n08/slot-07.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: ninety-seven
|
roles/agg-p01-n08/slot-08.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p01-n16/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n16/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty-six
|
roles/agg-p01-n16/slot-03.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: fifteen
|
roles/agg-p01-n16/slot-04.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: sixty-nine
|
roles/agg-p01-n16/slot-05.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: fifteen
|
roles/agg-p01-n16/slot-06.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: forty-three
|
roles/agg-p01-n16/slot-07.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: ninety-seven
|
roles/agg-p01-n16/slot-08.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p01-n16/slot-09.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-eight
|
roles/agg-p01-n16/slot-10.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: eighty-seven
|
roles/agg-p01-n16/slot-11.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: eighty-two
|
roles/agg-p01-n16/slot-12.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p01-n16/slot-13.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: eighty-eight
|
roles/agg-p01-n16/slot-14.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: forty-four
|
roles/agg-p01-n16/slot-15.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: sixty-two
|
roles/agg-p01-n16/slot-16.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: eight
|
roles/agg-p02-n01/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n02/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n02/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n04/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n04/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n04/slot-03.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: nineteen
|
roles/agg-p02-n04/slot-04.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty
|
roles/agg-p02-n08/slot-01.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n08/slot-02.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: seventy-one
|
roles/agg-p02-n08/slot-03.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: nineteen
|
roles/agg-p02-n08/slot-04.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty
|
roles/agg-p02-n08/slot-05.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: six
|
roles/agg-p02-n08/slot-06.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: thirty-seven
|
roles/agg-p02-n08/slot-07.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: twenty-three
|
roles/agg-p02-n08/slot-08.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Your private number: sixty-three
|