Spaces:
Sleeping
Sleeping
Commit Β·
ad6901d
0
Parent(s):
Initial commit: GraphTestbed v0.1.0
Browse filesKaggle-style scoring server for benchmarking ML/AI agent harnesses on
heterogeneous graph datasets. Pre-launch: works end-to-end against a
local server; HuggingFace dataset publication and hosted API deploy
are pending.
- gtb CLI: fetch / submit / leaderboard / score-local
- Flask scoring API with sqlite leaderboard
- Schema check, 5/day quota, score bucketing to 3dp
- 4 tasks declared: ieee-fraud-detection, arxiv-citation, figraph, ibm-aml
- Two-branch deploy story (main = client, server = scoring API)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- .gitignore +27 -0
- LICENSE +21 -0
- PROTOCOL.md +218 -0
- README.md +180 -0
- datasets/manifest.yaml +166 -0
- graphtestbed/__init__.py +10 -0
- graphtestbed/_manifest.py +40 -0
- graphtestbed/cli.py +52 -0
- graphtestbed/fetch.py +89 -0
- graphtestbed/leaderboard.py +54 -0
- graphtestbed/score_local.py +75 -0
- graphtestbed/submit.py +129 -0
- pyproject.toml +33 -0
- server/api.py +259 -0
- server/deploy.md +115 -0
- server/requirements.txt +5 -0
- server/run_local.sh +34 -0
.gitignore
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Local data caches (downloaded by `gtb fetch`)
|
| 2 |
+
.graphtestbed/
|
| 3 |
+
data/
|
| 4 |
+
**/_hf_cache/
|
| 5 |
+
|
| 6 |
+
# Editor / OS
|
| 7 |
+
.vscode/
|
| 8 |
+
.idea/
|
| 9 |
+
.DS_Store
|
| 10 |
+
|
| 11 |
+
# Python
|
| 12 |
+
__pycache__/
|
| 13 |
+
*.pyc
|
| 14 |
+
*.pyo
|
| 15 |
+
*.egg-info/
|
| 16 |
+
*.egg
|
| 17 |
+
build/
|
| 18 |
+
dist/
|
| 19 |
+
.venv/
|
| 20 |
+
.env
|
| 21 |
+
|
| 22 |
+
# Defensive β these names should never appear in this repo, but if they do
|
| 23 |
+
# (e.g., maintainer running tools/build_dataset_*.py locally), don't commit.
|
| 24 |
+
ground_truth*.csv
|
| 25 |
+
*test_labels*.csv
|
| 26 |
+
private/
|
| 27 |
+
**/private/
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2026 GraphTestbed Maintainers
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
PROTOCOL.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GraphTestbed Protocol
|
| 2 |
+
|
| 3 |
+
The contract between agent harnesses, the public client (`gtb`), and the
|
| 4 |
+
scoring API (`server/api.py`).
|
| 5 |
+
|
| 6 |
+
## 1. Two-branch single-repo layout
|
| 7 |
+
|
| 8 |
+
```
|
| 9 |
+
GraphTestbed (single public repo)
|
| 10 |
+
βββ main branch β what agents `git clone`
|
| 11 |
+
βββ server branch β what the maintainer deploys
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
Branches are **not access control** β they're an organizational split. Both
|
| 15 |
+
are public; both can be cloned by anyone. The actual privacy boundary is:
|
| 16 |
+
|
| 17 |
+
- **Test labels never enter git** (any branch).
|
| 18 |
+
- The scoring server holds GT at `/var/graphtestbed/gt/<task>.csv`,
|
| 19 |
+
populated separately from git at deploy time.
|
| 20 |
+
|
| 21 |
+
## 2. Data layout (per task)
|
| 22 |
+
|
| 23 |
+
### What the agent sees (HuggingFace public dataset)
|
| 24 |
+
|
| 25 |
+
```
|
| 26 |
+
graphtestbed/<task>:
|
| 27 |
+
train_features.csv # labeled
|
| 28 |
+
val_features.csv # labeled
|
| 29 |
+
test_features.csv # NO target column
|
| 30 |
+
description.md
|
| 31 |
+
sample_submission.csv
|
| 32 |
+
<auxiliary>.csv # optional: edges*.csv, train_text.csv, ...
|
| 33 |
+
```
|
| 34 |
+
|
| 35 |
+
### What the server holds privately
|
| 36 |
+
|
| 37 |
+
```
|
| 38 |
+
/var/graphtestbed/gt/<task>.csv
|
| 39 |
+
<id_col>,Label # one row per test entity, with the true label
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
ID column matches `test_features.csv[<id_col>]` 100%.
|
| 43 |
+
|
| 44 |
+
## 3. Submission contract
|
| 45 |
+
|
| 46 |
+
### Format
|
| 47 |
+
|
| 48 |
+
Per-task schema in `datasets/manifest.yaml`:
|
| 49 |
+
|
| 50 |
+
```yaml
|
| 51 |
+
<task>:
|
| 52 |
+
submission_schema:
|
| 53 |
+
id_col: <name>
|
| 54 |
+
pred_col: <name>
|
| 55 |
+
n_rows: <int>
|
| 56 |
+
pred_dtype: float # binary classification
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
CSV must have:
|
| 60 |
+
- Exactly 2 columns: `<id_col>, <pred_col>`
|
| 61 |
+
- Exactly `n_rows` rows
|
| 62 |
+
- ID set 100% matching `test_features.csv[<id_col>]`
|
| 63 |
+
- `<pred_col>` values: float in [0, 1] for binary
|
| 64 |
+
|
| 65 |
+
### Submit
|
| 66 |
+
|
| 67 |
+
```bash
|
| 68 |
+
gtb submit <task> --file <preds.csv> --agent <name>
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
This:
|
| 72 |
+
1. Validates schema **locally** (no API call if malformed).
|
| 73 |
+
2. POSTs `multipart/form-data` to `$GRAPHTESTBED_API/submit` with
|
| 74 |
+
`task=<task>&agent=<name>&file=<csv>`.
|
| 75 |
+
3. Server re-validates schema, checks quota, scores against GT, returns
|
| 76 |
+
metrics JSON.
|
| 77 |
+
4. Client prints metrics + leaderboard rank + remaining quota.
|
| 78 |
+
|
| 79 |
+
## 4. API endpoints
|
| 80 |
+
|
| 81 |
+
### `POST /submit` (multipart)
|
| 82 |
+
|
| 83 |
+
Form fields:
|
| 84 |
+
- `task` (str, required)
|
| 85 |
+
- `agent` (str, required)
|
| 86 |
+
- `file` (CSV, required, β€50 MB)
|
| 87 |
+
|
| 88 |
+
Response 200:
|
| 89 |
+
```json
|
| 90 |
+
{
|
| 91 |
+
"run_id": "8a3f29bce4a1",
|
| 92 |
+
"task": "arxiv-citation",
|
| 93 |
+
"agent": "autopipe-v0.4",
|
| 94 |
+
"primary": 0.689,
|
| 95 |
+
"secondary": {"auc_pr": 0.661, "f1": 0.591},
|
| 96 |
+
"n_rows": 19394,
|
| 97 |
+
"leaderboard_rank": 3,
|
| 98 |
+
"quota_remaining": 4,
|
| 99 |
+
"submitted_at": "2026-04-18T14:23:00"
|
| 100 |
+
}
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
Response 4xx:
|
| 104 |
+
- 400 β missing form fields, malformed CSV
|
| 105 |
+
- 404 β unknown task
|
| 106 |
+
- 422 β schema check failed (returns reason)
|
| 107 |
+
- 429 β quota exceeded
|
| 108 |
+
- 503 β GT not deployed for this task
|
| 109 |
+
|
| 110 |
+
### `GET /leaderboard/<task>`
|
| 111 |
+
|
| 112 |
+
Returns array sorted by `primary` desc, **best per agent** (not all
|
| 113 |
+
submissions):
|
| 114 |
+
```json
|
| 115 |
+
[
|
| 116 |
+
{"agent": "human-baseline", "primary": 0.901, "n_submissions": 1, "first_seen": "..."},
|
| 117 |
+
{"agent": "autopipe-v0.4", "primary": 0.689, "n_submissions": 4, "first_seen": "..."},
|
| 118 |
+
...
|
| 119 |
+
]
|
| 120 |
+
```
|
| 121 |
+
|
| 122 |
+
### `GET /healthz`
|
| 123 |
+
|
| 124 |
+
```json
|
| 125 |
+
{
|
| 126 |
+
"status": "ok",
|
| 127 |
+
"tasks": ["ieee-fraud-detection", ...],
|
| 128 |
+
"gt_present": ["arxiv-citation", "figraph"],
|
| 129 |
+
"quota_per_day": 5,
|
| 130 |
+
"uptime_unix": 1745081234
|
| 131 |
+
}
|
| 132 |
+
```
|
| 133 |
+
|
| 134 |
+
## 5. Anti-leakage rails (lightweight)
|
| 135 |
+
|
| 136 |
+
| Rail | Mechanism |
|
| 137 |
+
|---|---|
|
| 138 |
+
| Test labels not in git | `.gitignore` blocks `ground_truth*`, `private/`. GT lives only on server fs. |
|
| 139 |
+
| Score bucketing | Server rounds to 3 decimals before returning |
|
| 140 |
+
| No per-row feedback | API returns aggregate metrics only |
|
| 141 |
+
| Quota | 5 submissions / day / IP / task by default |
|
| 142 |
+
| Schema check first | Malformed submissions don't burn quota and don't expose GT to scoring |
|
| 143 |
+
|
| 144 |
+
## 6. Reproducibility
|
| 145 |
+
|
| 146 |
+
Every server response includes `run_id`. Server stores in sqlite:
|
| 147 |
+
|
| 148 |
+
```
|
| 149 |
+
run_id, task, agent, primary_metric, secondary_json, submission_sha256,
|
| 150 |
+
n_rows, submitter_ip, submitted_at
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
To audit a leaderboard entry: maintainer queries sqlite by run_id, gets the
|
| 154 |
+
submission CSV from `submissions/<task>/<agent>/<ts>.csv` (the client
|
| 155 |
+
doesn't push these to git automatically β see Β§8 if you want that).
|
| 156 |
+
|
| 157 |
+
## 7. Versioning
|
| 158 |
+
|
| 159 |
+
### Dataset versions
|
| 160 |
+
|
| 161 |
+
`manifest.yaml` pins `(hf_repo, hf_revision, sha256)` per file. To bump:
|
| 162 |
+
1. Push new files to HF as a new revision.
|
| 163 |
+
2. Update `manifest.yaml`'s sha256 fields.
|
| 164 |
+
3. Existing leaderboard entries reference the old data via their `run_id`'s
|
| 165 |
+
stored `submission_sha256`; new submissions use the new data.
|
| 166 |
+
|
| 167 |
+
For breaking changes (different metric, different test rows), add a v2
|
| 168 |
+
task entry: `arxiv-citation-v2`. Don't mutate v1's manifest.
|
| 169 |
+
|
| 170 |
+
### Metric versions
|
| 171 |
+
|
| 172 |
+
Same rule: don't mutate, add `<task>-v2` if metric definition changes.
|
| 173 |
+
|
| 174 |
+
## 8. Optional: client-side submission archiving
|
| 175 |
+
|
| 176 |
+
If you want every submission CSV preserved publicly, add a step to
|
| 177 |
+
`graphtestbed/submit.py` that opens a PR with the CSV under
|
| 178 |
+
`submissions/<task>/<agent>/<ts>.csv` after the API returns. Off by default
|
| 179 |
+
to keep the client simple.
|
| 180 |
+
|
| 181 |
+
## 9. What the agent must NOT assume
|
| 182 |
+
|
| 183 |
+
- **No persistent state** between submissions. Each `/submit` is independent.
|
| 184 |
+
- **No mid-run feedback.** One scorer call per submit, full stop.
|
| 185 |
+
- **No private leaderboard.** Every submission is rate-counted by IP and
|
| 186 |
+
scored β no shadow leaderboard for testing.
|
| 187 |
+
- **`agent` field is your name.** The server takes you at your word; don't
|
| 188 |
+
impersonate.
|
| 189 |
+
|
| 190 |
+
## 10. What the API explicitly does NOT defend against
|
| 191 |
+
|
| 192 |
+
- An agent that downloads upstream data (Kaggle, FiGraph github) and tries
|
| 193 |
+
to recompute test labels. We re-split for time-forward eval, so upstream
|
| 194 |
+
labels don't directly map, but a determined agent could try.
|
| 195 |
+
- An agent that checks out `server` branch to read scoring code. The branch
|
| 196 |
+
is public; reading the scoring logic doesn't leak GT.
|
| 197 |
+
- An agent that runs on a private machine and tries to OCR a maintainer's
|
| 198 |
+
laptop screen. We are not your adversary.
|
| 199 |
+
|
| 200 |
+
If your threat model includes adversarial agents with arbitrary capability,
|
| 201 |
+
this design is wrong; use container-isolated evaluation instead.
|
| 202 |
+
|
| 203 |
+
## 11. Rationale (why this vs the prior GitHub-Actions design)
|
| 204 |
+
|
| 205 |
+
We considered using GitHub Actions + a private GT repo. Rejected because:
|
| 206 |
+
|
| 207 |
+
- Two repos (public + private GT) is more moving parts than one repo + one
|
| 208 |
+
small server.
|
| 209 |
+
- A FastAPI/Flask app on a $5/month VM (or free HF Space) gives us the same
|
| 210 |
+
privacy boundary (GT lives on server fs, not in git).
|
| 211 |
+
- Synchronous scoring (instant response) is a better UX than async PR
|
| 212 |
+
comments.
|
| 213 |
+
- The trust model is "agents are honest within an academic benchmark," not
|
| 214 |
+
"agents are adversaries." Doesn't need physical isolation; needs an API
|
| 215 |
+
contract that prevents accidental leaks.
|
| 216 |
+
|
| 217 |
+
The result: ~200 lines of server code, ~150 lines of client code, deploys
|
| 218 |
+
on free tiers, no maintenance beyond restarting the server if it crashes.
|
README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GraphTestbed
|
| 2 |
+
|
| 3 |
+
> A Kaggle-style scoring server for benchmarking ML/AI agent harnesses on heterogeneous graph datasets.
|
| 4 |
+
|
| 5 |
+
[](https://www.python.org/)
|
| 6 |
+
[](LICENSE)
|
| 7 |
+
[](#status)
|
| 8 |
+
|
| 9 |
+
Build an agent. Submit predictions. Get a score. Test labels live on a server, not in this repo, so your agent can't accidentally cheat. Designed for non-adversarial benchmarking of agent harnesses on real graph data.
|
| 10 |
+
|
| 11 |
+
## Status
|
| 12 |
+
|
| 13 |
+
**Pre-launch.** The code runs end-to-end against a local server, but:
|
| 14 |
+
|
| 15 |
+
- The package isn't on PyPI yet β install from git (see below)
|
| 16 |
+
- The hosted scoring API isn't deployed yet β run the server on your own machine
|
| 17 |
+
- HuggingFace dataset repos aren't published yet β use your own `train/val/test_features.csv` files for now
|
| 18 |
+
|
| 19 |
+
The two paths below β **local dev** (works today) and **hosted submit** (coming) β share the exact same client and server code.
|
| 20 |
+
|
| 21 |
+
## Run it locally (works today)
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
# 1. Install
|
| 25 |
+
pip install git+https://github.com/zhuconv/GraphTestbed
|
| 26 |
+
|
| 27 |
+
# 2. Start the scoring API (terminal A)
|
| 28 |
+
git clone https://github.com/zhuconv/GraphTestbed
|
| 29 |
+
cd GraphTestbed
|
| 30 |
+
GT_DIR=~/path/to/your/ground_truth ./server/run_local.sh
|
| 31 |
+
# β Running on http://localhost:8080
|
| 32 |
+
|
| 33 |
+
# 3. Submit (terminal B)
|
| 34 |
+
export GRAPHTESTBED_API=http://localhost:8080
|
| 35 |
+
gtb submit figraph --file preds.csv --agent my-agent-v1
|
| 36 |
+
# β Scored primary (auc_roc): 0.689 rank: #3
|
| 37 |
+
gtb leaderboard figraph
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
You provide the `ground_truth/<task>.csv` files yourself (one row per test entity, columns `<id_col>,Label`). The CLI never needs to see them.
|
| 41 |
+
|
| 42 |
+
## Tasks
|
| 43 |
+
|
| 44 |
+
| Task | Type | Metric | Test rows |
|
| 45 |
+
| --- | --- | --- | --- |
|
| 46 |
+
| `ieee-fraud-detection` | binary classification | AUC-ROC | ~118k |
|
| 47 |
+
| `arxiv-citation` | binary classification | AUC-ROC | 19,394 |
|
| 48 |
+
| `figraph` | binary anomaly detection | AUC-ROC | 3,596 |
|
| 49 |
+
| `ibm-aml` | binary anomaly detection (preview) | AUC-PR | TBD |
|
| 50 |
+
|
| 51 |
+
## How it works
|
| 52 |
+
|
| 53 |
+
```
|
| 54 |
+
agent βββΊ gtb fetch <task> βββΊ (HuggingFace, when published)
|
| 55 |
+
agent βββΊ gtb submit <file> βββΊ POST /submit
|
| 56 |
+
β
|
| 57 |
+
βΌ
|
| 58 |
+
βββββββββββββββββββββββββββββββββββββββ
|
| 59 |
+
β server (Flask, ~250 LOC) β
|
| 60 |
+
β 1. quota: 5/day/IP/task β
|
| 61 |
+
β 2. schema check β
|
| 62 |
+
β 3. join with GT (local fs only) β
|
| 63 |
+
β 4. metric β round to 3dp β
|
| 64 |
+
β 5. sqlite leaderboard β JSON β
|
| 65 |
+
βββββββββββββββββββββββββββββββββββββββ
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
Ground truth never enters git. It sits on the server's local filesystem, populated separately at deploy time.
|
| 69 |
+
|
| 70 |
+
## CLI
|
| 71 |
+
|
| 72 |
+
```bash
|
| 73 |
+
gtb fetch <task> # download from HF (when published)
|
| 74 |
+
gtb submit <task> --file <csv> --agent <name> # POST to scoring API
|
| 75 |
+
gtb submit ... --dry-run # validate schema, no quota burn
|
| 76 |
+
gtb leaderboard <task> # GET /leaderboard/<task>
|
| 77 |
+
gtb score-local <task> --file <csv> # score against val (no GT needed)
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
`GRAPHTESTBED_API` overrides the server URL. Defaults to `http://localhost:8080`.
|
| 81 |
+
|
| 82 |
+
---
|
| 83 |
+
|
| 84 |
+
<details>
|
| 85 |
+
<summary><b>Submission format</b></summary>
|
| 86 |
+
|
| 87 |
+
Per-task schema in `datasets/manifest.yaml`:
|
| 88 |
+
|
| 89 |
+
```yaml
|
| 90 |
+
arxiv-citation:
|
| 91 |
+
hf_repo: graphtestbed/arxiv-citation
|
| 92 |
+
files:
|
| 93 |
+
train_features: { sha256: ... }
|
| 94 |
+
val_features: { sha256: ... }
|
| 95 |
+
test_features: { sha256: ... } # no Label column
|
| 96 |
+
submission_schema:
|
| 97 |
+
id_col: Paper_ID
|
| 98 |
+
pred_col: Label # float in [0, 1]
|
| 99 |
+
n_rows: 19394
|
| 100 |
+
metric:
|
| 101 |
+
primary: auc_roc
|
| 102 |
+
secondary: [auc_pr, f1]
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
CSV must contain **exactly** `[id_col, pred_col]`, exactly `n_rows` rows, IDs matching `test_features.csv` 100%. Otherwise schema check fails before scoring (no quota burn).
|
| 106 |
+
|
| 107 |
+
Successful output:
|
| 108 |
+
|
| 109 |
+
```
|
| 110 |
+
β Schema OK (rows=19394, sha256=abcdef012345...)
|
| 111 |
+
β Scored (run_id=ab12cd34ef56)
|
| 112 |
+
primary (auc_roc): 0.689
|
| 113 |
+
secondary: {'auc_pr': 0.661, 'f1': 0.591}
|
| 114 |
+
leaderboard rank: #3
|
| 115 |
+
quota remaining today: 4
|
| 116 |
+
```
|
| 117 |
+
</details>
|
| 118 |
+
|
| 119 |
+
<details>
|
| 120 |
+
<summary><b>Trust model</b></summary>
|
| 121 |
+
|
| 122 |
+
This is a **non-adversarial** benchmark. We trust agent authors not to circumvent the contract. The API enforces:
|
| 123 |
+
|
| 124 |
+
- **Test labels not in the repo.** No accidental leak via `pd.concat([train, val, test])`.
|
| 125 |
+
- **Rate limit.** 5 submissions / day / IP / task β enough to debug, not to hill-climb.
|
| 126 |
+
- **Score bucketing.** Metrics rounded to 3dp; on a 19k test set this is ~5Ο per bit, making probing statistically uninformative.
|
| 127 |
+
- **No per-row feedback.** Aggregates only.
|
| 128 |
+
- **Audit trail.** Every submission's sha256 + agent + timestamp lives in sqlite.
|
| 129 |
+
|
| 130 |
+
**What we do _not_ defend against:** anyone reading the `server/` code (it's public, but contains no GT); anyone re-downloading upstream Kaggle / FiGraph data and trying to recompute labels.
|
| 131 |
+
|
| 132 |
+
If you need adversarial guarantees, use a fully sandboxed eval (Docker + `network=none` + private CDN). Wrong tool here.
|
| 133 |
+
</details>
|
| 134 |
+
|
| 135 |
+
<details>
|
| 136 |
+
<summary><b>Repo layout</b></summary>
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
GraphTestbed/
|
| 140 |
+
βββ graphtestbed/ # the gtb CLI package (~400 LOC)
|
| 141 |
+
βββ server/ # the Flask scoring API (~250 LOC)
|
| 142 |
+
β βββ api.py
|
| 143 |
+
β βββ run_local.sh
|
| 144 |
+
β βββ deploy.md
|
| 145 |
+
βββ datasets/manifest.yaml # task β HF location + schema + metric
|
| 146 |
+
βββ PROTOCOL.md # full submission contract
|
| 147 |
+
βββ README.md
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
When the project goes live the `server/` directory will be promoted to its own `server` branch (kept separate so deploy hosts only checkout what they run). For now everything is on `main`.
|
| 151 |
+
|
| 152 |
+
See [`PROTOCOL.md`](PROTOCOL.md) for the full submission contract. See [`server/deploy.md`](server/deploy.md) for hosted deploy.
|
| 153 |
+
</details>
|
| 154 |
+
|
| 155 |
+
<details>
|
| 156 |
+
<summary><b>Adding a new task</b></summary>
|
| 157 |
+
|
| 158 |
+
1. Prepare `train/val/test_features.csv` + `ground_truth.csv` locally. Strip target column from `test_features`.
|
| 159 |
+
2. Push agent-visible files to `huggingface.co/datasets/graphtestbed/<task>` (when HF org is set up).
|
| 160 |
+
3. Place `ground_truth.csv` at `<server>/path/to/gt/<task>.csv`.
|
| 161 |
+
4. Add the task to `datasets/manifest.yaml` with sha256 + schema + metric.
|
| 162 |
+
|
| 163 |
+
CLI and API auto-discover from the manifest. No code changes.
|
| 164 |
+
</details>
|
| 165 |
+
|
| 166 |
+
<details>
|
| 167 |
+
<summary><b>Adding a new agent</b></summary>
|
| 168 |
+
|
| 169 |
+
You don't modify GraphTestbed. You:
|
| 170 |
+
|
| 171 |
+
1. Get data (currently: bring-your-own `test_features.csv`)
|
| 172 |
+
2. Train, predict, write CSV with `<id_col>, <pred_col>` columns
|
| 173 |
+
3. `gtb submit <task> --file preds.csv --agent <name>`
|
| 174 |
+
|
| 175 |
+
That's it. See [`PROTOCOL.md`](PROTOCOL.md) for edge cases.
|
| 176 |
+
</details>
|
| 177 |
+
|
| 178 |
+
## License
|
| 179 |
+
|
| 180 |
+
[MIT](LICENSE). Data: subject to upstream licenses (Kaggle competition rules, FiGraph CC BY-NC 4.0, etc.).
|
datasets/manifest.yaml
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# GraphTestbed dataset manifest.
|
| 2 |
+
#
|
| 3 |
+
# Each entry pins:
|
| 4 |
+
# - HuggingFace repo + revision + per-file sha256 (immutable across runs)
|
| 5 |
+
# - Submission schema (id_col, pred_col, n_rows, dtype)
|
| 6 |
+
# - Metric definition (primary + secondary)
|
| 7 |
+
#
|
| 8 |
+
# To add a task: prepare data β push to HF β fill in this file β run
|
| 9 |
+
# tools/append_leaderboard.py to seed an empty leaderboard YAML.
|
| 10 |
+
#
|
| 11 |
+
# Hashes below are placeholders; populate with `sha256sum train_features.csv`
|
| 12 |
+
# at dataset publish time and re-run the verifier.
|
| 13 |
+
|
| 14 |
+
ieee-fraud-detection:
|
| 15 |
+
hf_repo: graphtestbed/ieee-fraud-detection
|
| 16 |
+
hf_revision: main
|
| 17 |
+
files:
|
| 18 |
+
train_transaction:
|
| 19 |
+
filename: train_transaction.csv
|
| 20 |
+
sha256: TBD
|
| 21 |
+
train_identity:
|
| 22 |
+
filename: train_identity.csv
|
| 23 |
+
sha256: TBD
|
| 24 |
+
test_transaction:
|
| 25 |
+
filename: test_transaction.csv
|
| 26 |
+
sha256: TBD
|
| 27 |
+
test_identity:
|
| 28 |
+
filename: test_identity.csv
|
| 29 |
+
sha256: TBD
|
| 30 |
+
sample_submission:
|
| 31 |
+
filename: sample_submission.csv
|
| 32 |
+
sha256: TBD
|
| 33 |
+
submission_schema:
|
| 34 |
+
id_col: TransactionID
|
| 35 |
+
pred_col: isFraud
|
| 36 |
+
n_rows: 118108 # update after final split
|
| 37 |
+
pred_dtype: float
|
| 38 |
+
metric:
|
| 39 |
+
primary: auc_roc
|
| 40 |
+
secondary: [auc_pr, f1]
|
| 41 |
+
description: |
|
| 42 |
+
Predict the probability that an online transaction is fraudulent.
|
| 43 |
+
Temporal split: last 20% by TransactionDT.
|
| 44 |
+
Origin: Kaggle competition ieee-fraud-detection (Vesta).
|
| 45 |
+
|
| 46 |
+
arxiv-citation:
|
| 47 |
+
hf_repo: graphtestbed/arxiv-citation
|
| 48 |
+
hf_revision: main
|
| 49 |
+
files:
|
| 50 |
+
train_features:
|
| 51 |
+
filename: train_features.csv
|
| 52 |
+
sha256: TBD
|
| 53 |
+
val_features:
|
| 54 |
+
filename: val_features.csv
|
| 55 |
+
sha256: TBD
|
| 56 |
+
test_features:
|
| 57 |
+
filename: test_features.csv
|
| 58 |
+
sha256: TBD
|
| 59 |
+
train_text:
|
| 60 |
+
filename: train_text.csv
|
| 61 |
+
sha256: TBD
|
| 62 |
+
val_text:
|
| 63 |
+
filename: val_text.csv
|
| 64 |
+
sha256: TBD
|
| 65 |
+
test_text:
|
| 66 |
+
filename: test_text.csv
|
| 67 |
+
sha256: TBD
|
| 68 |
+
citations:
|
| 69 |
+
filename: 3Citation.csv
|
| 70 |
+
sha256: TBD
|
| 71 |
+
paper_author:
|
| 72 |
+
filename: 6Paper_Author.csv
|
| 73 |
+
sha256: TBD
|
| 74 |
+
sample_submission:
|
| 75 |
+
filename: sample_submission.csv
|
| 76 |
+
sha256: TBD
|
| 77 |
+
submission_schema:
|
| 78 |
+
id_col: Paper_ID
|
| 79 |
+
pred_col: Label
|
| 80 |
+
n_rows: 19394
|
| 81 |
+
pred_dtype: float
|
| 82 |
+
metric:
|
| 83 |
+
primary: auc_roc
|
| 84 |
+
secondary: [auc_pr, f1]
|
| 85 |
+
description: |
|
| 86 |
+
For each arXiv physics paper, predict whether it will receive β₯1
|
| 87 |
+
citation within 6 months. Temporal split:
|
| 88 |
+
train: submitted before 2021-07-01 (135,857)
|
| 89 |
+
val: 2021-07-01 to 2022-01-01 (19,965)
|
| 90 |
+
test: 2022-01-01 to 2022-07-01 (19,394)
|
| 91 |
+
|
| 92 |
+
figraph:
|
| 93 |
+
hf_repo: graphtestbed/figraph
|
| 94 |
+
hf_revision: main
|
| 95 |
+
files:
|
| 96 |
+
train_features:
|
| 97 |
+
filename: train_features.csv
|
| 98 |
+
sha256: TBD
|
| 99 |
+
val_features:
|
| 100 |
+
filename: val_features.csv
|
| 101 |
+
sha256: TBD
|
| 102 |
+
test_features:
|
| 103 |
+
filename: test_features.csv
|
| 104 |
+
sha256: TBD
|
| 105 |
+
edges_2014:
|
| 106 |
+
filename: edges2014.csv
|
| 107 |
+
sha256: TBD
|
| 108 |
+
edges_2015:
|
| 109 |
+
filename: edges2015.csv
|
| 110 |
+
sha256: TBD
|
| 111 |
+
edges_2016:
|
| 112 |
+
filename: edges2016.csv
|
| 113 |
+
sha256: TBD
|
| 114 |
+
edges_2017:
|
| 115 |
+
filename: edges2017.csv
|
| 116 |
+
sha256: TBD
|
| 117 |
+
edges_2018:
|
| 118 |
+
filename: edges2018.csv
|
| 119 |
+
sha256: TBD
|
| 120 |
+
sample_submission:
|
| 121 |
+
filename: sample_submission.csv
|
| 122 |
+
sha256: TBD
|
| 123 |
+
submission_schema:
|
| 124 |
+
id_col: nodeID
|
| 125 |
+
pred_col: Label
|
| 126 |
+
n_rows: 3596
|
| 127 |
+
pred_dtype: float
|
| 128 |
+
metric:
|
| 129 |
+
primary: auc_roc
|
| 130 |
+
secondary: [auc_pr, f1]
|
| 131 |
+
description: |
|
| 132 |
+
FiGraph anomaly detection on listed companies (~4.7% positive rate).
|
| 133 |
+
Temporal split by Year: train=2014-2016, val=2017, test=2018.
|
| 134 |
+
Upstream: github.com/XiaoguangWang23/FiGraph (CC BY-NC 4.0).
|
| 135 |
+
|
| 136 |
+
ibm-aml:
|
| 137 |
+
hf_repo: graphtestbed/ibm-aml
|
| 138 |
+
hf_revision: main
|
| 139 |
+
files:
|
| 140 |
+
train_transactions:
|
| 141 |
+
filename: train_transactions.csv
|
| 142 |
+
sha256: TBD
|
| 143 |
+
val_transactions:
|
| 144 |
+
filename: val_transactions.csv
|
| 145 |
+
sha256: TBD
|
| 146 |
+
test_transactions:
|
| 147 |
+
filename: test_transactions.csv
|
| 148 |
+
sha256: TBD
|
| 149 |
+
accounts:
|
| 150 |
+
filename: accounts.csv
|
| 151 |
+
sha256: TBD
|
| 152 |
+
sample_submission:
|
| 153 |
+
filename: sample_submission.csv
|
| 154 |
+
sha256: TBD
|
| 155 |
+
submission_schema:
|
| 156 |
+
id_col: transaction_id
|
| 157 |
+
pred_col: is_laundering
|
| 158 |
+
n_rows: TBD
|
| 159 |
+
pred_dtype: float
|
| 160 |
+
metric:
|
| 161 |
+
primary: auc_pr
|
| 162 |
+
secondary: [f1, auc_roc]
|
| 163 |
+
description: |
|
| 164 |
+
IBM Anti-Money Laundering benchmark: predict whether each transaction
|
| 165 |
+
is part of a laundering pattern. Severe class imbalance (<1% positive).
|
| 166 |
+
Temporal split.
|
graphtestbed/__init__.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""GraphTestbed client library + CLI.
|
| 2 |
+
|
| 3 |
+
Public surface:
|
| 4 |
+
gtb fetch <task> # download data from HuggingFace
|
| 5 |
+
gtb submit <task> --file ... # POST to scoring API
|
| 6 |
+
gtb leaderboard <task> # show ranked agents
|
| 7 |
+
gtb score-local <task> --file ... # dry-run score on val (no GT needed)
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
__version__ = "0.1.0"
|
graphtestbed/_manifest.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Load and query datasets/manifest.yaml."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import hashlib
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from typing import Any
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _repo_root() -> Path:
|
| 11 |
+
return Path(__file__).resolve().parents[1]
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def manifest_path() -> Path:
|
| 15 |
+
return _repo_root() / "datasets" / "manifest.yaml"
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def load_manifest() -> dict[str, Any]:
|
| 19 |
+
import yaml
|
| 20 |
+
return yaml.safe_load(manifest_path().read_text())
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def task_config(task: str) -> dict[str, Any]:
|
| 24 |
+
m = load_manifest()
|
| 25 |
+
if task not in m:
|
| 26 |
+
raise KeyError(
|
| 27 |
+
f"Unknown task '{task}'. Known: {sorted(m.keys())}"
|
| 28 |
+
)
|
| 29 |
+
return m[task]
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def sha256_file(path: Path, chunk: int = 1 << 20) -> str:
|
| 33 |
+
h = hashlib.sha256()
|
| 34 |
+
with path.open("rb") as f:
|
| 35 |
+
while True:
|
| 36 |
+
b = f.read(chunk)
|
| 37 |
+
if not b:
|
| 38 |
+
break
|
| 39 |
+
h.update(b)
|
| 40 |
+
return h.hexdigest()
|
graphtestbed/cli.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""`gtb` entry point β dispatches to fetch / submit / leaderboard / score-local.
|
| 2 |
+
|
| 3 |
+
Each subcommand owns its own argparse, so `gtb <cmd> --help` shows the
|
| 4 |
+
full per-command flags.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
COMMANDS = {
|
| 13 |
+
"fetch": ("Download a task's dataset",
|
| 14 |
+
"graphtestbed.fetch:main"),
|
| 15 |
+
"submit": ("Submit predictions to the scoring API",
|
| 16 |
+
"graphtestbed.submit:main"),
|
| 17 |
+
"leaderboard": ("Show leaderboard for a task",
|
| 18 |
+
"graphtestbed.leaderboard:main"),
|
| 19 |
+
"score-local": ("Dry-run scorer against val (no GT needed)",
|
| 20 |
+
"graphtestbed.score_local:main"),
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _print_help() -> None:
|
| 25 |
+
print("Usage: gtb <command> [options]\n")
|
| 26 |
+
print("Commands:")
|
| 27 |
+
width = max(len(c) for c in COMMANDS)
|
| 28 |
+
for cmd, (desc, _) in COMMANDS.items():
|
| 29 |
+
print(f" {cmd:<{width}} {desc}")
|
| 30 |
+
print("\nRun `gtb <command> --help` for command-specific options.")
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main() -> None:
|
| 34 |
+
if len(sys.argv) < 2 or sys.argv[1] in ("-h", "--help"):
|
| 35 |
+
_print_help()
|
| 36 |
+
sys.exit(0)
|
| 37 |
+
|
| 38 |
+
cmd = sys.argv[1]
|
| 39 |
+
if cmd not in COMMANDS:
|
| 40 |
+
print(f"Unknown command: {cmd}\n", file=sys.stderr)
|
| 41 |
+
_print_help()
|
| 42 |
+
sys.exit(2)
|
| 43 |
+
|
| 44 |
+
sys.argv = [f"gtb {cmd}"] + sys.argv[2:]
|
| 45 |
+
module_path, fn_name = COMMANDS[cmd][1].split(":")
|
| 46 |
+
import importlib
|
| 47 |
+
fn = getattr(importlib.import_module(module_path), fn_name)
|
| 48 |
+
fn()
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
main()
|
graphtestbed/fetch.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Download a task's dataset from HuggingFace, verify per-file sha256."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import os
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
from graphtestbed._manifest import sha256_file, task_config
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def cache_dir() -> Path:
|
| 14 |
+
base = os.environ.get("GRAPHTESTBED_CACHE", str(Path.home() / ".graphtestbed" / "data"))
|
| 15 |
+
return Path(base)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def fetch_task(task: str, allow_unverified: bool = False) -> Path:
|
| 19 |
+
"""Download all files for `task` from HF; verify against manifest sha256."""
|
| 20 |
+
try:
|
| 21 |
+
from huggingface_hub import hf_hub_download
|
| 22 |
+
from huggingface_hub.utils import RepositoryNotFoundError
|
| 23 |
+
except ImportError:
|
| 24 |
+
raise SystemExit(
|
| 25 |
+
"Missing dependency: pip install huggingface_hub"
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
cfg = task_config(task)
|
| 29 |
+
out = cache_dir() / task
|
| 30 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 31 |
+
|
| 32 |
+
n_unpinned = 0
|
| 33 |
+
for key, spec in cfg["files"].items():
|
| 34 |
+
try:
|
| 35 |
+
local = hf_hub_download(
|
| 36 |
+
repo_id=cfg["hf_repo"],
|
| 37 |
+
filename=spec["filename"],
|
| 38 |
+
revision=cfg.get("hf_revision", "main"),
|
| 39 |
+
repo_type="dataset",
|
| 40 |
+
cache_dir=str(out / "_hf_cache"),
|
| 41 |
+
)
|
| 42 |
+
except RepositoryNotFoundError:
|
| 43 |
+
raise SystemExit(
|
| 44 |
+
f"\nHuggingFace dataset '{cfg['hf_repo']}' not found.\n"
|
| 45 |
+
f"GraphTestbed is pre-launch; the dataset repos may not be "
|
| 46 |
+
f"published yet.\nFor now, place your own files at:\n"
|
| 47 |
+
f" {out}/{spec['filename']} (and others from the manifest)"
|
| 48 |
+
)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
raise SystemExit(
|
| 51 |
+
f"Failed to download {cfg['hf_repo']}:{spec['filename']}: {e}"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
dest = out / spec["filename"]
|
| 55 |
+
if not dest.exists():
|
| 56 |
+
dest.symlink_to(local)
|
| 57 |
+
|
| 58 |
+
actual = sha256_file(dest)
|
| 59 |
+
expected = spec.get("sha256", "TBD")
|
| 60 |
+
if expected == "TBD":
|
| 61 |
+
n_unpinned += 1
|
| 62 |
+
elif actual != expected:
|
| 63 |
+
msg = (f"sha256 mismatch for {spec['filename']}\n"
|
| 64 |
+
f" expected: {expected}\n"
|
| 65 |
+
f" actual: {actual}")
|
| 66 |
+
if not allow_unverified:
|
| 67 |
+
raise SystemExit("ERROR: " + msg)
|
| 68 |
+
print("WARN: " + msg, file=sys.stderr)
|
| 69 |
+
print(f" OK {spec['filename']} ({actual[:12]}...)")
|
| 70 |
+
|
| 71 |
+
if n_unpinned:
|
| 72 |
+
print(f"\n ({n_unpinned} files have unpinned sha256 in manifest β "
|
| 73 |
+
f"normal during pre-launch)", file=sys.stderr)
|
| 74 |
+
print(f"\nFetched '{task}' to {out}")
|
| 75 |
+
print(f"Submission schema: {cfg['submission_schema']}")
|
| 76 |
+
return out
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def main() -> None:
|
| 80 |
+
ap = argparse.ArgumentParser(prog="gtb fetch")
|
| 81 |
+
ap.add_argument("task")
|
| 82 |
+
ap.add_argument("--allow-unverified", action="store_true",
|
| 83 |
+
help="Continue past sha256 mismatches (for dev use only)")
|
| 84 |
+
args = ap.parse_args()
|
| 85 |
+
fetch_task(args.task, allow_unverified=args.allow_unverified)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
if __name__ == "__main__":
|
| 89 |
+
main()
|
graphtestbed/leaderboard.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fetch the public leaderboard for a task."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
import json
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
API_URL = os.environ.get("GRAPHTESTBED_API", "http://localhost:8080")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def main() -> None:
|
| 15 |
+
ap = argparse.ArgumentParser(prog="gtb leaderboard")
|
| 16 |
+
ap.add_argument("task")
|
| 17 |
+
ap.add_argument("--json", action="store_true",
|
| 18 |
+
help="Print raw JSON instead of a table")
|
| 19 |
+
args = ap.parse_args()
|
| 20 |
+
|
| 21 |
+
try:
|
| 22 |
+
import requests
|
| 23 |
+
except ImportError:
|
| 24 |
+
raise SystemExit("Missing dependency: pip install requests")
|
| 25 |
+
|
| 26 |
+
try:
|
| 27 |
+
resp = requests.get(f"{API_URL}/leaderboard/{args.task}", timeout=10)
|
| 28 |
+
except requests.exceptions.ConnectionError as e:
|
| 29 |
+
raise SystemExit(
|
| 30 |
+
f"Could not reach {API_URL} ({e}). "
|
| 31 |
+
f"Set GRAPHTESTBED_API or start `./server/run_local.sh`."
|
| 32 |
+
)
|
| 33 |
+
if resp.status_code != 200:
|
| 34 |
+
raise SystemExit(f"{resp.status_code}: {resp.text[:200]}")
|
| 35 |
+
rows = resp.json()
|
| 36 |
+
|
| 37 |
+
if args.json:
|
| 38 |
+
print(json.dumps(rows, indent=2))
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
+
if not rows:
|
| 42 |
+
print(f"(no submissions yet for {args.task})")
|
| 43 |
+
return
|
| 44 |
+
|
| 45 |
+
width = max(len("agent"), max(len(r["agent"]) for r in rows))
|
| 46 |
+
print(f" {'rank':>4} {'agent':<{width}} {'primary':>8} "
|
| 47 |
+
f"{'subs':>4} first_seen")
|
| 48 |
+
for i, r in enumerate(rows, 1):
|
| 49 |
+
print(f" {i:>4} {r['agent']:<{width}} {r['primary']:>8.3f} "
|
| 50 |
+
f"{r['n_submissions']:>4} {r['first_seen']}")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
main()
|
graphtestbed/score_local.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Dry-run scoring on val set β useful before submitting.
|
| 2 |
+
|
| 3 |
+
Computes the same metrics the server-side scorer does, against val_features.csv
|
| 4 |
+
(which has labels). Helps you sanity-check your prediction pipeline locally.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
import json
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
import pandas as pd
|
| 15 |
+
|
| 16 |
+
from graphtestbed._manifest import task_config
|
| 17 |
+
from graphtestbed.fetch import cache_dir
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def compute_binary_metrics(y_true, y_score, primary: str, secondary: list[str]) -> dict:
|
| 21 |
+
from sklearn.metrics import (
|
| 22 |
+
average_precision_score, f1_score, roc_auc_score,
|
| 23 |
+
)
|
| 24 |
+
y_true = np.asarray(y_true).astype(int)
|
| 25 |
+
y_score = np.asarray(y_score).astype(float)
|
| 26 |
+
y_pred = (y_score >= 0.5).astype(int)
|
| 27 |
+
funcs = {
|
| 28 |
+
"auc_roc": lambda: float(roc_auc_score(y_true, y_score)),
|
| 29 |
+
"auc_pr": lambda: float(average_precision_score(y_true, y_score)),
|
| 30 |
+
"f1": lambda: float(f1_score(y_true, y_pred)),
|
| 31 |
+
}
|
| 32 |
+
out = {"primary": funcs[primary](), "secondary": {}}
|
| 33 |
+
for s in secondary:
|
| 34 |
+
out["secondary"][s] = funcs[s]()
|
| 35 |
+
return out
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def main() -> None:
|
| 39 |
+
ap = argparse.ArgumentParser(prog="gtb score-local")
|
| 40 |
+
ap.add_argument("task")
|
| 41 |
+
ap.add_argument("--file", type=Path, required=True,
|
| 42 |
+
help="CSV of predictions on val_features.csv")
|
| 43 |
+
args = ap.parse_args()
|
| 44 |
+
|
| 45 |
+
cfg = task_config(args.task)
|
| 46 |
+
s = cfg["submission_schema"]
|
| 47 |
+
val_path = cache_dir() / args.task / "val_features.csv"
|
| 48 |
+
if not val_path.exists():
|
| 49 |
+
raise SystemExit(
|
| 50 |
+
f"Missing {val_path}. Run `gtb fetch {args.task}` first."
|
| 51 |
+
)
|
| 52 |
+
val = pd.read_csv(val_path)
|
| 53 |
+
sub = pd.read_csv(args.file).rename(columns={s["pred_col"]: "_pred"})
|
| 54 |
+
if s["pred_col"] not in val.columns:
|
| 55 |
+
raise SystemExit(
|
| 56 |
+
f"val_features.csv has no '{s['pred_col']}' column β "
|
| 57 |
+
f"can't compute val metrics. (Cols: {list(val.columns)[:10]}...)"
|
| 58 |
+
)
|
| 59 |
+
val_gt = val[[s["id_col"], s["pred_col"]]].rename(
|
| 60 |
+
columns={s["pred_col"]: "_true"})
|
| 61 |
+
merged = val_gt.merge(sub, on=s["id_col"], how="inner")
|
| 62 |
+
if len(merged) != len(val_gt):
|
| 63 |
+
raise SystemExit(
|
| 64 |
+
f"Coverage {len(merged)} / {len(val_gt)} β "
|
| 65 |
+
f"some val IDs missing from your file"
|
| 66 |
+
)
|
| 67 |
+
metrics = compute_binary_metrics(
|
| 68 |
+
merged["_true"], merged["_pred"],
|
| 69 |
+
cfg["metric"]["primary"], cfg["metric"]["secondary"],
|
| 70 |
+
)
|
| 71 |
+
print(json.dumps(metrics, indent=2))
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
main()
|
graphtestbed/submit.py
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Submit predictions to the GraphTestbed scoring API.
|
| 2 |
+
|
| 3 |
+
Validates schema locally first; an obviously-malformed CSV never reaches
|
| 4 |
+
the server (saves you a quota slot).
|
| 5 |
+
|
| 6 |
+
Usage:
|
| 7 |
+
gtb submit <task> --file preds.csv --agent autopipe-v0.4
|
| 8 |
+
gtb submit <task> --file preds.csv --agent autopipe-v0.4 --dry-run
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
import pandas as pd
|
| 20 |
+
|
| 21 |
+
from graphtestbed._manifest import sha256_file, task_config
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
API_URL = os.environ.get("GRAPHTESTBED_API", "http://localhost:8080")
|
| 25 |
+
TIMEOUT_SEC = 60
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def validate_submission(task: str, csv_path: Path) -> dict:
|
| 29 |
+
"""Local schema check; raises SystemExit on failure with a clear reason."""
|
| 30 |
+
cfg = task_config(task)
|
| 31 |
+
s = cfg["submission_schema"]
|
| 32 |
+
|
| 33 |
+
df = pd.read_csv(csv_path)
|
| 34 |
+
|
| 35 |
+
if list(df.columns) != [s["id_col"], s["pred_col"]]:
|
| 36 |
+
raise SystemExit(
|
| 37 |
+
f"Column mismatch.\n"
|
| 38 |
+
f" expected: [{s['id_col']}, {s['pred_col']}]\n"
|
| 39 |
+
f" got: {list(df.columns)}"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
if s.get("n_rows") not in ("TBD", None) and len(df) != s["n_rows"]:
|
| 43 |
+
raise SystemExit(
|
| 44 |
+
f"Row count mismatch: expected {s['n_rows']}, got {len(df)}"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if df[s["id_col"]].duplicated().any():
|
| 48 |
+
raise SystemExit(f"Duplicate IDs in {s['id_col']} column")
|
| 49 |
+
|
| 50 |
+
if s.get("pred_dtype") == "float":
|
| 51 |
+
try:
|
| 52 |
+
preds = df[s["pred_col"]].astype(float)
|
| 53 |
+
except (TypeError, ValueError) as e:
|
| 54 |
+
raise SystemExit(f"pred_col not float-castable: {e}")
|
| 55 |
+
if (preds < 0).any() or (preds > 1).any():
|
| 56 |
+
raise SystemExit("predictions must lie in [0, 1]")
|
| 57 |
+
|
| 58 |
+
return {
|
| 59 |
+
"n_rows": len(df),
|
| 60 |
+
"sha256": sha256_file(csv_path),
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def submit(task: str, csv_path: Path, agent: str, dry_run: bool = False) -> None:
|
| 65 |
+
info = validate_submission(task, csv_path)
|
| 66 |
+
print(f"β Schema OK (rows={info['n_rows']}, sha256={info['sha256'][:12]}...)")
|
| 67 |
+
|
| 68 |
+
if dry_run:
|
| 69 |
+
print(f"\n(dry-run) Would POST to {API_URL}/submit "
|
| 70 |
+
f"as task={task} agent={agent}")
|
| 71 |
+
return
|
| 72 |
+
|
| 73 |
+
try:
|
| 74 |
+
import requests
|
| 75 |
+
except ImportError:
|
| 76 |
+
raise SystemExit("Missing dependency: pip install requests")
|
| 77 |
+
|
| 78 |
+
print(f" β POST {API_URL}/submit task={task} agent={agent}")
|
| 79 |
+
try:
|
| 80 |
+
with csv_path.open("rb") as f:
|
| 81 |
+
resp = requests.post(
|
| 82 |
+
f"{API_URL}/submit",
|
| 83 |
+
data={"task": task, "agent": agent},
|
| 84 |
+
files={"file": (csv_path.name, f, "text/csv")},
|
| 85 |
+
timeout=TIMEOUT_SEC,
|
| 86 |
+
)
|
| 87 |
+
except requests.exceptions.ConnectionError as e:
|
| 88 |
+
raise SystemExit(
|
| 89 |
+
f"\nβ Could not reach {API_URL}\n"
|
| 90 |
+
f" Set GRAPHTESTBED_API to a running server, or start one locally:\n"
|
| 91 |
+
f" GT_DIR=<your-gt-dir> ./server/run_local.sh\n"
|
| 92 |
+
f" ({e})"
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
if resp.status_code >= 400:
|
| 96 |
+
try:
|
| 97 |
+
err = resp.json()
|
| 98 |
+
except ValueError:
|
| 99 |
+
err = {"error": resp.text[:500]}
|
| 100 |
+
print(f"\nβ {resp.status_code} {err.get('error', 'unknown error')}",
|
| 101 |
+
file=sys.stderr)
|
| 102 |
+
sys.exit(1)
|
| 103 |
+
|
| 104 |
+
out = resp.json()
|
| 105 |
+
print()
|
| 106 |
+
print(f"β Scored (run_id={out['run_id']})")
|
| 107 |
+
print(f" primary ({task_config(task)['metric']['primary']}): "
|
| 108 |
+
f"{out['primary']}")
|
| 109 |
+
print(f" secondary: {out['secondary']}")
|
| 110 |
+
print(f" rows: {out['n_rows']}")
|
| 111 |
+
print(f" leaderboard rank: #{out['leaderboard_rank']}")
|
| 112 |
+
print(f" quota remaining today: {out['quota_remaining']}")
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def main() -> None:
|
| 116 |
+
ap = argparse.ArgumentParser(prog="gtb submit")
|
| 117 |
+
ap.add_argument("task")
|
| 118 |
+
ap.add_argument("--file", type=Path, required=True,
|
| 119 |
+
help="Path to submission CSV")
|
| 120 |
+
ap.add_argument("--agent", required=True,
|
| 121 |
+
help="Identifier for this agent (e.g. autopipe-v0.4)")
|
| 122 |
+
ap.add_argument("--dry-run", action="store_true",
|
| 123 |
+
help="Validate schema locally, don't POST")
|
| 124 |
+
args = ap.parse_args()
|
| 125 |
+
submit(args.task, args.file, args.agent, dry_run=args.dry_run)
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if __name__ == "__main__":
|
| 129 |
+
main()
|
pyproject.toml
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "graphtestbed"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Reproducible benchmark harness for ML/AI agents on heterogeneous graph datasets"
|
| 5 |
+
authors = [{ name = "GraphTestbed Maintainers" }]
|
| 6 |
+
license = "MIT"
|
| 7 |
+
readme = "README.md"
|
| 8 |
+
requires-python = ">=3.10"
|
| 9 |
+
keywords = ["benchmark", "graph", "ml", "agent", "evaluation"]
|
| 10 |
+
|
| 11 |
+
[project.urls]
|
| 12 |
+
Homepage = "https://github.com/zhuconv/GraphTestbed"
|
| 13 |
+
Repository = "https://github.com/zhuconv/GraphTestbed"
|
| 14 |
+
Issues = "https://github.com/zhuconv/GraphTestbed/issues"
|
| 15 |
+
dependencies = [
|
| 16 |
+
"huggingface-hub >= 0.20",
|
| 17 |
+
"pandas >= 2.0",
|
| 18 |
+
"pyyaml >= 6.0",
|
| 19 |
+
"requests >= 2.30",
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
[project.optional-dependencies]
|
| 23 |
+
dev = ["scikit-learn >= 1.3"]
|
| 24 |
+
|
| 25 |
+
[project.scripts]
|
| 26 |
+
gtb = "graphtestbed.cli:main"
|
| 27 |
+
|
| 28 |
+
[build-system]
|
| 29 |
+
requires = ["setuptools >= 65", "wheel"]
|
| 30 |
+
build-backend = "setuptools.build_meta"
|
| 31 |
+
|
| 32 |
+
[tool.setuptools]
|
| 33 |
+
packages = ["graphtestbed"]
|
server/api.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""GraphTestbed scoring API.
|
| 2 |
+
|
| 3 |
+
Single-file Flask app. Holds ground_truth files locally, scores submissions,
|
| 4 |
+
returns metrics, appends to leaderboard. No DB, no auth β submitter identity
|
| 5 |
+
is just whatever string the client sends in `agent`.
|
| 6 |
+
|
| 7 |
+
Deployment unit: the `server` branch (or this `server/` subdir on a deploy
|
| 8 |
+
host). Ground-truth files live at $GT_DIR (default /var/graphtestbed/gt/),
|
| 9 |
+
populated separately from git β they MUST NOT be committed.
|
| 10 |
+
|
| 11 |
+
Endpoints:
|
| 12 |
+
POST /submit
|
| 13 |
+
form: task=<task>, agent=<name>, file=<csv>
|
| 14 |
+
β 200 { primary, secondary, n_rows, leaderboard_rank, run_id,
|
| 15 |
+
quota_remaining }
|
| 16 |
+
β 4xx { error }
|
| 17 |
+
|
| 18 |
+
GET /leaderboard/<task>
|
| 19 |
+
β 200 [ { agent, primary, secondary, submitted_at, run_id }, ... ]
|
| 20 |
+
sorted by primary descending
|
| 21 |
+
|
| 22 |
+
GET /healthz
|
| 23 |
+
β 200 { status: "ok", tasks: [...], gt_present: [...] }
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
from __future__ import annotations
|
| 27 |
+
|
| 28 |
+
import datetime as dt
|
| 29 |
+
import hashlib
|
| 30 |
+
import json
|
| 31 |
+
import os
|
| 32 |
+
import sqlite3
|
| 33 |
+
import time
|
| 34 |
+
import uuid
|
| 35 |
+
from pathlib import Path
|
| 36 |
+
|
| 37 |
+
import pandas as pd
|
| 38 |
+
import yaml
|
| 39 |
+
from flask import Flask, jsonify, request
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
GT_DIR = Path(os.environ.get("GT_DIR", "/var/graphtestbed/gt"))
|
| 43 |
+
DB_PATH = Path(os.environ.get("GT_DB", "/var/graphtestbed/leaderboard.db"))
|
| 44 |
+
MANIFEST_PATH = Path(os.environ.get(
|
| 45 |
+
"GT_MANIFEST",
|
| 46 |
+
Path(__file__).resolve().parents[1] / "datasets" / "manifest.yaml",
|
| 47 |
+
))
|
| 48 |
+
QUOTA_PER_DAY = int(os.environ.get("GT_QUOTA", "5"))
|
| 49 |
+
MAX_UPLOAD_BYTES = 50 * 1024 * 1024 # 50 MB hard cap
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
app = Flask(__name__)
|
| 53 |
+
app.config["MAX_CONTENT_LENGTH"] = MAX_UPLOAD_BYTES
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _manifest() -> dict:
|
| 57 |
+
return yaml.safe_load(MANIFEST_PATH.read_text())
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _db() -> sqlite3.Connection:
|
| 61 |
+
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 62 |
+
conn = sqlite3.connect(DB_PATH)
|
| 63 |
+
conn.execute("""
|
| 64 |
+
CREATE TABLE IF NOT EXISTS submissions (
|
| 65 |
+
run_id TEXT PRIMARY KEY,
|
| 66 |
+
task TEXT NOT NULL,
|
| 67 |
+
agent TEXT NOT NULL,
|
| 68 |
+
primary_metric REAL NOT NULL,
|
| 69 |
+
secondary_json TEXT NOT NULL,
|
| 70 |
+
submission_sha256 TEXT NOT NULL,
|
| 71 |
+
n_rows INTEGER NOT NULL,
|
| 72 |
+
submitter_ip TEXT,
|
| 73 |
+
submitted_at TEXT NOT NULL
|
| 74 |
+
)
|
| 75 |
+
""")
|
| 76 |
+
return conn
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def _quota_remaining(task: str, ip: str) -> int:
|
| 80 |
+
"""Count submissions in the last 24h from this IP for this task."""
|
| 81 |
+
conn = _db()
|
| 82 |
+
cutoff = (dt.datetime.now(dt.timezone.utc) - dt.timedelta(days=1)).isoformat()
|
| 83 |
+
n = conn.execute(
|
| 84 |
+
"SELECT COUNT(*) FROM submissions "
|
| 85 |
+
"WHERE task = ? AND submitter_ip = ? AND submitted_at > ?",
|
| 86 |
+
(task, ip, cutoff),
|
| 87 |
+
).fetchone()[0]
|
| 88 |
+
conn.close()
|
| 89 |
+
return max(0, QUOTA_PER_DAY - n)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _score(task: str, sub_df: pd.DataFrame, cfg: dict) -> dict:
|
| 93 |
+
from sklearn.metrics import (
|
| 94 |
+
average_precision_score, f1_score, roc_auc_score,
|
| 95 |
+
)
|
| 96 |
+
schema = cfg["submission_schema"]
|
| 97 |
+
metric = cfg["metric"]
|
| 98 |
+
|
| 99 |
+
gt = pd.read_csv(GT_DIR / f"{task}.csv")[[schema["id_col"], "Label"]]
|
| 100 |
+
sub_renamed = sub_df.rename(columns={schema["pred_col"]: "_pred"})
|
| 101 |
+
merged = gt.merge(sub_renamed, on=schema["id_col"], how="inner")
|
| 102 |
+
if len(merged) != len(gt):
|
| 103 |
+
raise ValueError(
|
| 104 |
+
f"Coverage mismatch: scored {len(merged)} / expected {len(gt)} rows"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
y_true = merged["Label"].astype(int)
|
| 108 |
+
y_score = merged["_pred"].astype(float)
|
| 109 |
+
y_pred = (y_score >= 0.5).astype(int)
|
| 110 |
+
funcs = {
|
| 111 |
+
"auc_roc": lambda: roc_auc_score(y_true, y_score),
|
| 112 |
+
"auc_pr": lambda: average_precision_score(y_true, y_score),
|
| 113 |
+
"f1": lambda: f1_score(y_true, y_pred),
|
| 114 |
+
}
|
| 115 |
+
return {
|
| 116 |
+
"primary": round(float(funcs[metric["primary"]]()), 3),
|
| 117 |
+
"secondary": {
|
| 118 |
+
s: round(float(funcs[s]()), 3) for s in metric["secondary"]
|
| 119 |
+
},
|
| 120 |
+
"n_rows": len(merged),
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
def _validate_schema(sub_df: pd.DataFrame, cfg: dict) -> None:
|
| 125 |
+
s = cfg["submission_schema"]
|
| 126 |
+
if list(sub_df.columns) != [s["id_col"], s["pred_col"]]:
|
| 127 |
+
raise ValueError(
|
| 128 |
+
f"columns must be [{s['id_col']}, {s['pred_col']}], "
|
| 129 |
+
f"got {list(sub_df.columns)}"
|
| 130 |
+
)
|
| 131 |
+
if s.get("n_rows") not in ("TBD", None) and len(sub_df) != s["n_rows"]:
|
| 132 |
+
raise ValueError(
|
| 133 |
+
f"row count {len(sub_df)} != expected {s['n_rows']}"
|
| 134 |
+
)
|
| 135 |
+
if sub_df[s["id_col"]].duplicated().any():
|
| 136 |
+
raise ValueError(f"duplicate IDs in {s['id_col']}")
|
| 137 |
+
if s.get("pred_dtype") == "float":
|
| 138 |
+
try:
|
| 139 |
+
preds = sub_df[s["pred_col"]].astype(float)
|
| 140 |
+
except (TypeError, ValueError) as e:
|
| 141 |
+
raise ValueError(f"pred_col not float-castable: {e}")
|
| 142 |
+
if (preds < 0).any() or (preds > 1).any():
|
| 143 |
+
raise ValueError("predictions must lie in [0, 1]")
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
@app.post("/submit")
|
| 147 |
+
def submit():
|
| 148 |
+
task = request.form.get("task")
|
| 149 |
+
agent = request.form.get("agent")
|
| 150 |
+
file = request.files.get("file")
|
| 151 |
+
ip = request.headers.get("X-Forwarded-For", request.remote_addr or "unknown")
|
| 152 |
+
|
| 153 |
+
if not (task and agent and file):
|
| 154 |
+
return jsonify({"error": "form fields required: task, agent, file"}), 400
|
| 155 |
+
|
| 156 |
+
manifest = _manifest()
|
| 157 |
+
if task not in manifest:
|
| 158 |
+
return jsonify({"error": f"unknown task '{task}'", "known": sorted(manifest)}), 404
|
| 159 |
+
cfg = manifest[task]
|
| 160 |
+
|
| 161 |
+
quota = _quota_remaining(task, ip)
|
| 162 |
+
if quota <= 0:
|
| 163 |
+
return jsonify({
|
| 164 |
+
"error": f"quota exceeded ({QUOTA_PER_DAY}/day per IP per task)",
|
| 165 |
+
"task": task,
|
| 166 |
+
}), 429
|
| 167 |
+
|
| 168 |
+
raw = file.read()
|
| 169 |
+
sub_sha = hashlib.sha256(raw).hexdigest()
|
| 170 |
+
try:
|
| 171 |
+
import io
|
| 172 |
+
sub_df = pd.read_csv(io.BytesIO(raw))
|
| 173 |
+
except Exception as e:
|
| 174 |
+
return jsonify({"error": f"could not parse CSV: {e}"}), 400
|
| 175 |
+
|
| 176 |
+
try:
|
| 177 |
+
_validate_schema(sub_df, cfg)
|
| 178 |
+
except ValueError as e:
|
| 179 |
+
return jsonify({"error": f"schema check failed: {e}"}), 422
|
| 180 |
+
|
| 181 |
+
try:
|
| 182 |
+
scored = _score(task, sub_df, cfg)
|
| 183 |
+
except FileNotFoundError:
|
| 184 |
+
return jsonify({"error": f"ground truth not deployed for task '{task}'"}), 503
|
| 185 |
+
except Exception as e:
|
| 186 |
+
return jsonify({"error": f"scoring failed: {e}"}), 500
|
| 187 |
+
|
| 188 |
+
run_id = uuid.uuid4().hex[:12]
|
| 189 |
+
now = dt.datetime.now(dt.timezone.utc).isoformat()
|
| 190 |
+
conn = _db()
|
| 191 |
+
conn.execute(
|
| 192 |
+
"INSERT INTO submissions VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
| 193 |
+
(run_id, task, agent, scored["primary"],
|
| 194 |
+
json.dumps(scored["secondary"]), sub_sha, scored["n_rows"], ip, now),
|
| 195 |
+
)
|
| 196 |
+
conn.commit()
|
| 197 |
+
|
| 198 |
+
# Rank = how many distinct agents have a strictly better best-score on
|
| 199 |
+
# this task. The just-inserted row contributes to that count only if the
|
| 200 |
+
# SAME agent had a better prior submission (in which case rank doesn't
|
| 201 |
+
# change for them on this submission).
|
| 202 |
+
rank = conn.execute("""
|
| 203 |
+
SELECT COUNT(*) + 1 FROM (
|
| 204 |
+
SELECT agent, MAX(primary_metric) AS best
|
| 205 |
+
FROM submissions
|
| 206 |
+
WHERE task = ?
|
| 207 |
+
GROUP BY agent
|
| 208 |
+
HAVING best > ?
|
| 209 |
+
)
|
| 210 |
+
""", (task, scored["primary"])).fetchone()[0]
|
| 211 |
+
conn.close()
|
| 212 |
+
|
| 213 |
+
return jsonify({
|
| 214 |
+
"run_id": run_id,
|
| 215 |
+
"task": task,
|
| 216 |
+
"agent": agent,
|
| 217 |
+
"primary": scored["primary"],
|
| 218 |
+
"secondary": scored["secondary"],
|
| 219 |
+
"n_rows": scored["n_rows"],
|
| 220 |
+
"leaderboard_rank": rank,
|
| 221 |
+
"quota_remaining": quota - 1,
|
| 222 |
+
"submitted_at": now,
|
| 223 |
+
})
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
@app.get("/leaderboard/<task>")
|
| 227 |
+
def leaderboard(task: str):
|
| 228 |
+
"""Per-agent best submission, sorted by primary metric desc."""
|
| 229 |
+
conn = _db()
|
| 230 |
+
rows = conn.execute("""
|
| 231 |
+
SELECT agent, MAX(primary_metric) as best, COUNT(*) as n_subs,
|
| 232 |
+
MIN(submitted_at) as first_seen
|
| 233 |
+
FROM submissions
|
| 234 |
+
WHERE task = ?
|
| 235 |
+
GROUP BY agent
|
| 236 |
+
ORDER BY best DESC
|
| 237 |
+
""", (task,)).fetchall()
|
| 238 |
+
conn.close()
|
| 239 |
+
return jsonify([
|
| 240 |
+
{"agent": a, "primary": p, "n_submissions": n, "first_seen": f}
|
| 241 |
+
for (a, p, n, f) in rows
|
| 242 |
+
])
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
@app.get("/healthz")
|
| 246 |
+
def healthz():
|
| 247 |
+
manifest = _manifest()
|
| 248 |
+
return jsonify({
|
| 249 |
+
"status": "ok",
|
| 250 |
+
"tasks": sorted(manifest),
|
| 251 |
+
"gt_present": [t for t in manifest if (GT_DIR / f"{t}.csv").exists()],
|
| 252 |
+
"quota_per_day": QUOTA_PER_DAY,
|
| 253 |
+
"uptime_unix": int(time.time()),
|
| 254 |
+
})
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
if __name__ == "__main__":
|
| 258 |
+
port = int(os.environ.get("PORT", "8080"))
|
| 259 |
+
app.run(host="0.0.0.0", port=port)
|
server/deploy.md
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Deploying the GraphTestbed scoring API
|
| 2 |
+
|
| 3 |
+
The scoring server is a single Flask app (`api.py`). Pick any host; the
|
| 4 |
+
canonical setup below uses a small VM but the app is deliberately thin so
|
| 5 |
+
HuggingFace Spaces, fly.io, or render.com all work.
|
| 6 |
+
|
| 7 |
+
## Prerequisites on the host
|
| 8 |
+
|
| 9 |
+
- Python β₯ 3.10
|
| 10 |
+
- `~50 MB` for code + sqlite leaderboard
|
| 11 |
+
- `~5 GB` if hosting all 4 ground-truth CSVs locally
|
| 12 |
+
- Public HTTPS endpoint (a reverse proxy with TLS or a managed service)
|
| 13 |
+
|
| 14 |
+
## Layout on the host
|
| 15 |
+
|
| 16 |
+
```
|
| 17 |
+
/opt/graphtestbed/
|
| 18 |
+
βββ server/ # this directory, deployed from `server` branch
|
| 19 |
+
β βββ api.py
|
| 20 |
+
β βββ requirements.txt
|
| 21 |
+
β βββ deploy.md
|
| 22 |
+
βββ datasets/manifest.yaml # pulled from `main` branch (read-only by api.py)
|
| 23 |
+
βββ .venv/
|
| 24 |
+
|
| 25 |
+
/var/graphtestbed/
|
| 26 |
+
βββ gt/ # NOT IN GIT β copied here separately
|
| 27 |
+
β βββ ieee-fraud-detection.csv
|
| 28 |
+
β βββ arxiv-citation.csv
|
| 29 |
+
β βββ figraph.csv
|
| 30 |
+
β βββ ibm-aml.csv
|
| 31 |
+
βββ leaderboard.db # sqlite, created by api.py on first run
|
| 32 |
+
```
|
| 33 |
+
|
| 34 |
+
## Branch deployment pattern
|
| 35 |
+
|
| 36 |
+
```bash
|
| 37 |
+
# On the host, clone twice into adjacent dirs:
|
| 38 |
+
git clone <repo> /opt/graphtestbed/_main && \
|
| 39 |
+
cd /opt/graphtestbed/_main && \
|
| 40 |
+
cp -r datasets /opt/graphtestbed/
|
| 41 |
+
|
| 42 |
+
git clone -b server <repo> /opt/graphtestbed/_server && \
|
| 43 |
+
cp -r /opt/graphtestbed/_server/server /opt/graphtestbed/
|
| 44 |
+
|
| 45 |
+
# Place ground-truth files (NOT in git):
|
| 46 |
+
sudo mkdir -p /var/graphtestbed/gt
|
| 47 |
+
sudo scp ieee-fraud-detection.csv \
|
| 48 |
+
arxiv-citation.csv \
|
| 49 |
+
figraph.csv \
|
| 50 |
+
ibm-aml.csv \
|
| 51 |
+
host:/var/graphtestbed/gt/
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Run
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
cd /opt/graphtestbed/server
|
| 58 |
+
python -m venv ../.venv && source ../.venv/bin/activate
|
| 59 |
+
pip install -r requirements.txt
|
| 60 |
+
|
| 61 |
+
export GT_DIR=/var/graphtestbed/gt
|
| 62 |
+
export GT_DB=/var/graphtestbed/leaderboard.db
|
| 63 |
+
export GT_MANIFEST=/opt/graphtestbed/datasets/manifest.yaml
|
| 64 |
+
export GT_QUOTA=5
|
| 65 |
+
export PORT=8080
|
| 66 |
+
|
| 67 |
+
# Dev mode:
|
| 68 |
+
python api.py
|
| 69 |
+
|
| 70 |
+
# Production:
|
| 71 |
+
gunicorn --bind 0.0.0.0:8080 --workers 2 api:app
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
Front it with nginx (or use a managed proxy like Cloudflare Tunnel / fly.io's
|
| 75 |
+
built-in TLS). The app speaks plain HTTP on $PORT.
|
| 76 |
+
|
| 77 |
+
## Updating ground truth
|
| 78 |
+
|
| 79 |
+
GT files are append-only: never edit, never delete. To version a dataset, add
|
| 80 |
+
a new task entry like `arxiv-citation-v2` in `datasets/manifest.yaml` (on
|
| 81 |
+
the `main` branch) and place a new GT file `arxiv-citation-v2.csv` on the
|
| 82 |
+
host. Old leaderboard for v1 stays valid; new submissions go to v2.
|
| 83 |
+
|
| 84 |
+
## Healthcheck
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
curl https://<host>/healthz
|
| 88 |
+
# {
|
| 89 |
+
# "status": "ok",
|
| 90 |
+
# "tasks": ["ieee-fraud-detection", "arxiv-citation", "figraph", "ibm-aml"],
|
| 91 |
+
# "gt_present": ["figraph", "arxiv-citation"], # only those uploaded so far
|
| 92 |
+
# "quota_per_day": 5,
|
| 93 |
+
# "uptime_unix": 1745081234
|
| 94 |
+
# }
|
| 95 |
+
```
|
| 96 |
+
|
| 97 |
+
If a task is in `tasks` but missing from `gt_present`, the server will reject
|
| 98 |
+
submissions for it with 503.
|
| 99 |
+
|
| 100 |
+
## Costs
|
| 101 |
+
|
| 102 |
+
- HuggingFace Space (free, sleeps when idle, ~30s cold start): $0
|
| 103 |
+
- fly.io (always-on shared-cpu-1x, 256MB): ~$2/month
|
| 104 |
+
- self-hosted VM (1 vCPU, 1GB): ~$5/month
|
| 105 |
+
|
| 106 |
+
The sqlite leaderboard handles thousands of submissions on commodity hardware.
|
| 107 |
+
If you outgrow it, swap `_db()` for postgres without touching the rest of
|
| 108 |
+
`api.py`.
|
| 109 |
+
|
| 110 |
+
## Backups
|
| 111 |
+
|
| 112 |
+
The leaderboard sqlite at `$GT_DB` is a single file β copy it for backup.
|
| 113 |
+
Submission CSVs themselves are not persisted by the server (only their
|
| 114 |
+
sha256 + agent + timestamp). If you want full submission archival, set up
|
| 115 |
+
your own object store and have `api.py` write to it before scoring.
|
server/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask>=3.0
|
| 2 |
+
pandas>=2.0
|
| 3 |
+
pyyaml>=6.0
|
| 4 |
+
scikit-learn>=1.3
|
| 5 |
+
gunicorn>=21.0
|
server/run_local.sh
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# Start the scoring API on localhost for solo development / self-testing.
|
| 3 |
+
#
|
| 4 |
+
# Usage:
|
| 5 |
+
# GT_DIR=~/graphtestbed-private/ground_truth ./server/run_local.sh
|
| 6 |
+
#
|
| 7 |
+
# Then in another shell:
|
| 8 |
+
# export GRAPHTESTBED_API=http://localhost:8080
|
| 9 |
+
# gtb submit <task> --file preds.csv --agent <name>
|
| 10 |
+
|
| 11 |
+
set -euo pipefail
|
| 12 |
+
|
| 13 |
+
: "${GT_DIR:?Set GT_DIR to a directory containing <task>.csv ground-truth files}"
|
| 14 |
+
|
| 15 |
+
# Sensible defaults for local dev β sqlite in a tmp file, manifest from the
|
| 16 |
+
# repo this script lives in, quota relaxed so debugging doesn't burn it.
|
| 17 |
+
export GT_DB="${GT_DB:-/tmp/gtb_leaderboard.db}"
|
| 18 |
+
export GT_MANIFEST="${GT_MANIFEST:-$(cd "$(dirname "$0")/.." && pwd)/datasets/manifest.yaml}"
|
| 19 |
+
export GT_QUOTA="${GT_QUOTA:-1000}"
|
| 20 |
+
export PORT="${PORT:-8080}"
|
| 21 |
+
|
| 22 |
+
echo "GraphTestbed API (local)"
|
| 23 |
+
echo " GT_DIR: $GT_DIR"
|
| 24 |
+
echo " GT_DB: $GT_DB"
|
| 25 |
+
echo " GT_MANIFEST: $GT_MANIFEST"
|
| 26 |
+
echo " GT_QUOTA: $GT_QUOTA / day / IP / task"
|
| 27 |
+
echo " PORT: $PORT"
|
| 28 |
+
echo
|
| 29 |
+
echo "Healthz: curl http://localhost:$PORT/healthz"
|
| 30 |
+
echo "Submit: GRAPHTESTBED_API=http://localhost:$PORT gtb submit <task> ..."
|
| 31 |
+
echo
|
| 32 |
+
|
| 33 |
+
cd "$(dirname "$0")"
|
| 34 |
+
exec python api.py
|