From 25e0460af8be22292b4bebea0efc12d54718a4b6 Mon Sep 17 00:00:00 2001 From: Harenome Ranaivoarivony-Razanajato Date: Thu, 3 Dec 2026 16:13:34 +0100 Subject: [PATCH] feat(compare): count a task once when two lists hold it under different ids A benchmark's labels.json may map tasks one dataset holds of another (copies): the Leaderboard then counts such a task once, as its copy, in scores, N and coverage, at the versions the map was checked at. labels.check refuses a map onto itself, an unknown dataset or version, a unit mapped twice, a second map of one dataset and a chain. Refs #652 --- .../evaluation/label-benchmark/SKILL.md | 17 +++ .../label-benchmark/scripts/public_ids.py | 47 +++++--- app/nullius/leaderboard/labels.py | 74 +++++++++++- app/nullius/leaderboard/projection.py | 48 ++++++-- app/tests/test_leaderboard_labels.py | 110 ++++++++++++++++++ app/ui_tests/test_leaderboard_routes.py | 19 +++ docs/field-guide.md | 8 +- 7 files changed, 288 insertions(+), 35 deletions(-) diff --git a/.agents/skill-library/evaluation/label-benchmark/SKILL.md b/.agents/skill-library/evaluation/label-benchmark/SKILL.md index fbf4a73b1..86243a3b1 100644 --- a/.agents/skill-library/evaluation/label-benchmark/SKILL.md +++ b/.agents/skill-library/evaluation/label-benchmark/SKILL.md @@ -97,6 +97,17 @@ gated download), propose `units.public_ids` in the same diff: the path where it ```bash PYTHONPATH=REPO/app python3 -c 'from nullius.standard.contract import definitions as d; print(d.version_identity(d.get("benchmark", "REF")))' ``` +- `copies`, beside `labels`, when one dataset holds tasks of another: each map names the `dataset` it maps, the + dataset `of` the same tasks, `checked` as above, and `tasks` as `[unit, its unit there]` pairs, same ids included. + The Leaderboard then counts a mapped task once, as its copy, with its copy's labels (step 1). One map + per dataset and version, never onto a dataset that is itself mapped. Under `units.redistribute: false` with no + `units.public_ids`, none. + + ```json + {"schema": 1, "labels": [...], "copies": [ + {"dataset": "lite", "of": "full", "checked": ["IDENTITY"], "tasks": [["1", "7"], ["2", "2"]]} + ]} + ``` - A new version: add its identity, as the command above prints it for the new `REF`, to `checked` only for the tasks whose bytes did not change, and only when the `policy` and whatever else a state is built from or a task is graded by did not change either. Every other task goes through the steps. @@ -120,6 +131,12 @@ through the steps and write its `tasks` rules for both. Either differs (a workfl Datasets with the same task ids, questions and expected answers, differing only in the context around them (a longer history), are the same tasks at another size: take the smallest through the steps and write its `tasks` rules for each. The same tasks in another language: take every language through the steps; a label stands where all agree, for each. +A copy is the same question with the same expected answer, in another dataset or under another id (a lite list of a +full one, an older release kept beside a newer one): map it (`copies`), matched on the task's data, every field but +its id, never on the id alone. A variant (another context size, another language, a corrected answer) is never a +copy: it keeps its own tasks and its own labels. +Where a map is checked at `REF`, it comes before the rules above: label the dataset mapped onto, and write `tasks` +rules for the mapped dataset only for units no map covers or versions no map is checked at. This step decides only a yes, and only from a field of the task's data that anyone can check again. A field whose value, when present and not empty, is the axis's test gives a `tasks` rule over those tasks: a graded check that diff --git a/.agents/skill-library/evaluation/label-benchmark/scripts/public_ids.py b/.agents/skill-library/evaluation/label-benchmark/scripts/public_ids.py index 43d78d3b9..fab192f9e 100644 --- a/.agents/skill-library/evaluation/label-benchmark/scripts/public_ids.py +++ b/.agents/skill-library/evaluation/label-benchmark/scripts/public_ids.py @@ -4,7 +4,7 @@ PYTHONPATH=REPO/app python3 SKILL/scripts/public_ids.py ENTRY Such a benchmark's labels may name tasks only under ``units.public_ids``, the path in the upstream repository where -it publishes the ids, and only ids that are, at each version a rule is ``checked`` at: +it publishes the ids, and only ids that are, at each version a rule or a map of ``copies`` is ``checked`` at: - listed by ``units`` for that dataset (the listing Nullius cached when the skill listed it); - published: the upstream fetched at its pinned commit over HTTPS, with no credential, no user configuration and an empty home (a private repository fails here), and the id found under that path as a tracked file or folder name @@ -36,21 +36,32 @@ def refusals(document, versions, listed, published) -> list: unit = versions[0].get("units") or {} if unit.get("redistribute") is not False: return [] - rules = [r for r in document["labels"] if "tasks" in r] - if rules and not unit.get("public_ids"): + named = _named(document) + if named and not unit.get("public_ids"): return ["units.public_ids: not set, so no task id may be named"] out = [] - for v in sorted({v for r in rules for v in r["checked"]}): - for ds in sorted({r["dataset"] for r in rules if v in r["checked"]}): - ids = {t for r in rules if v in r["checked"] and r["dataset"] == ds for t in r["tasks"]} - there = listed.get((v, ds)) - if there is None: - out.append(f"{v} {ds}: no cached listing; list its units first") - continue - if ids - set(there): - out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed") - if ids - published.get(v, set()): - out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}") + for (v, ds), ids in sorted(named.items()): + there = listed.get((v, ds)) + if there is None: + out.append(f"{v} {ds}: no cached listing; list its units first") + continue + if ids - set(there): + out.append(f"{v} {ds}: {len(ids - set(there))} of {len(ids)} ids not listed") + if ids - published.get(v, set()): + out.append(f"{v} {ds}: {len(ids - published.get(v, set()))} of {len(ids)} ids not published under {unit['public_ids']}") + return out + + +def _named(document) -> dict: + """Every task id the document names, by (version, dataset): its ``tasks`` rules' and both sides of its maps.""" + out = {} + for r in document["labels"]: + for v in r.get("checked", []) if "tasks" in r else []: + out.setdefault((v, r["dataset"]), set()).update(r["tasks"]) + for c in document.get("copies", []): + for v in c["checked"]: + for side, ds in enumerate((c["dataset"], c["of"])): + out.setdefault((v, ds), set()).update(p[side] for p in c["tasks"]) return out @@ -107,13 +118,13 @@ def main(): with open(os.path.join(entry, "labels.json"), encoding="utf-8") as f: document = json.load(f) by = {definitions.version_identity(b): b for b in versions} - rules = [r for r in document.get("labels") or [] if isinstance(r, dict) and "tasks" in r] unit = (versions[0].get("units") or {}) if versions else {} listed, seen = {}, {} if versions and not labels.check(document, versions).problems and unit.get("redistribute") is False and unit.get("public_ids"): - for v in {v for r in rules for v in r["checked"]}: + named = _named(document) + for v in {v for v, _ in named}: b = by[v] - for ds in {r["dataset"] for r in rules if v in r["checked"]}: + for ds in {ds for at, ds in named if at == v}: d = next(x for x in b["datasets"] if x["id"] == ds) try: with open(units.cache_path(b, d, units.option_values(b, ds)), encoding="utf-8") as f: @@ -123,7 +134,7 @@ def main(): where = (b["upstream"]["repository"], b["upstream"]["tested"], unit["public_ids"]) seen[v] = published(*where) out = refusals(document, versions, listed, seen) - ids = sum(len(r["tasks"]) for r in rules if isinstance(r.get("tasks"), list)) + ids = sum(map(len, _named(document).values())) if not labels.check(document, versions).problems else 0 if not out and unit.get("redistribute") is not False: print("units.redistribute is not false in ENTRY: its ids may be named; apply a proposed change first") else: diff --git a/app/nullius/leaderboard/labels.py b/app/nullius/leaderboard/labels.py index 0fb6dcdb4..4fd160bf6 100644 --- a/app/nullius/leaderboard/labels.py +++ b/app/nullius/leaderboard/labels.py @@ -6,6 +6,11 @@ A ``tasks`` rule names the versions its ids were ``checked`` at, as a run records them (``definitions.version_identity``). At another version it counts only when asked (``include``). + +``copies`` maps tasks of one dataset onto the same tasks of another, unit by unit, at the versions ``checked``: +a true copy is the same question with the same expected answer, in another list or under another id. A variant (a +longer context, another language) measures something else and is never mapped. A mapped task is its copy's, labels +included; at another version the map is not applied. A map that does not read is left out alone and said. """ from __future__ import annotations @@ -29,6 +34,7 @@ AXES = CAPABILITIES + DOMAINS UNCHECKED = ("omit", "include") _KEYS = {"dataset", "tasks", "checked", "axes", "not"} +_COPY_KEYS = {"dataset", "of", "checked", "tasks"} @dataclass(frozen=True) @@ -40,10 +46,28 @@ class Rule: checked: frozenset = frozenset() +@dataclass(frozen=True) +class Copies: + dataset: str + of: str # the dataset that holds the same tasks + checked: frozenset + tasks: tuple # (unit, the same task's unit in ``of``) pairs + + @dataclass(frozen=True) class Labels: rules: tuple = () problems: tuple = () + copies: tuple = () + + def same(self, version: str, dataset: str) -> dict: + """The tasks of this whole dataset at this version that are copies, each as (dataset, unit) of its copy.""" + return {unit: (c.of, to) for c in self.copies if c.dataset == dataset and version in c.checked for unit, to in c.tasks} + + def unchecked_copies(self, version: str) -> int: + """How many tasks a map names that no map checked at this version maps, each (dataset, unit) once.""" + mapped = lambda at: {(c.dataset, unit) for c in self.copies if (version in c.checked) == at for unit, _ in c.tasks} + return len(mapped(False) - mapped(True)) def unchecked(self, version: str) -> list: """The ``tasks`` rules not checked at this version.""" @@ -111,11 +135,48 @@ def _rule(rule, shapes, task_ids): return Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset, frozenset(rule["tasks"]), frozenset(rule["checked"])) +def _copy(entry, shapes, task_ids, kept): + """The map, or why it does not read; ``kept`` the maps read before it.""" + if not isinstance(entry, dict): + return "an object" + if set(entry) != _COPY_KEYS: + return f"{', '.join(sorted(_COPY_KEYS))}, and nothing else" + if not task_ids: + return "this benchmark's ids may not be redistributed (units.redistribute, no units.public_ids); no map" + dataset, of = entry["dataset"], entry["of"] + if not (isinstance(dataset, str) and dataset and isinstance(of, str) and of): + return "dataset and of: dataset ids" + if dataset == of: + return "of: a map onto itself" + if not _names(entry["checked"]): + return "checked: the versions these tasks were checked at" + unknown = [v for v in entry["checked"] if v not in shapes] + if unknown: + return f"checked: unknown version {unknown[0]!r}; one of {', '.join(shapes)}" + for v in entry["checked"]: + for d in (dataset, of): + if _whole(d, [shapes[v]]): + return f"{_whole(d, [shapes[v]])}, at {v}" + pairs = entry["tasks"] + if not (isinstance(pairs, list) and pairs and all(isinstance(p, list) and len(p) == 2 and _names(p) for p in pairs)): + return "tasks: [unit, its copy's unit] pairs, never empty" + for side, name in ((0, dataset), (1, of)): + if len({p[side] for p in pairs}) < len(pairs): + return f"tasks: a unit of {name} mapped twice" + for c in kept: + if set(entry["checked"]) & c.checked: + if dataset == c.dataset: + return f"dataset: {dataset} already has a map at a version" + if dataset == c.of or of == c.dataset: + return "of: a chain of maps; map each onto the last" + return Copies(dataset, of, frozenset(entry["checked"]), tuple(map(tuple, pairs))) + + def check(document, versions) -> Labels: """A ``labels.json`` document against its benchmark, ``versions`` the benchmark resolved at each of its versions.""" if not isinstance(document, dict) or document.get("schema") != SCHEMA or not isinstance(document.get("labels"), list) \ - or set(document) != {"schema", "labels"}: - return Labels(problems=(f"{{schema: {SCHEMA}, labels: [...]}} and nothing else",)) + or not isinstance(document.get("copies", []), list) or set(document) - {"copies"} != {"schema", "labels"}: + return Labels(problems=(f"{{schema: {SCHEMA}, labels: [...], copies?: [...]}} and nothing else",)) shapes = {} # each version's whole datasets and its cuts for b in versions: cuts = {d["id"]: d["subset_of"] for d in b.get("datasets") or [] if d.get("subset_of")} @@ -129,7 +190,14 @@ def check(document, versions) -> Labels: rules.append(got) else: problems.append(f"labels[{i}]: {got}") - return Labels(tuple(rules), tuple(problems)) + copies = [] + for i, entry in enumerate(document.get("copies", [])): + got = _copy(entry, shapes, task_ids, copies) + if isinstance(got, Copies): + copies.append(got) + else: + problems.append(f"copies[{i}]: {got}") + return Labels(tuple(rules), tuple(problems), tuple(copies)) def load(benchmarks) -> dict: diff --git a/app/nullius/leaderboard/projection.py b/app/nullius/leaderboard/projection.py index 0ac9cbfbc..55de4e5b1 100644 --- a/app/nullius/leaderboard/projection.py +++ b/app/nullius/leaderboard/projection.py @@ -1,7 +1,8 @@ """Each axis scored over the tasks labelled with it. It reads no file. A task is ``Job.task_id`` with its dataset replaced by the one its list is cut from (``subset_of``), so a cut's -tasks are the whole dataset's. Two versions of a benchmark are two sets of tasks: nothing pools across them, and a +tasks are the whole dataset's, then by its copy's where the labels map it (``labels.Copies``), so one question in two +lists counts once, its own labels and listing aside. Two versions of a benchmark are two sets of tasks: nothing pools across them, and a cell they both reach keeps its rates per version only. Per row, the most recent run of each recorded benchmark version and dataset counts, ties by job id; each other @@ -20,7 +21,8 @@ apart as a cell's rates are, a version with no task it reads there left out: beside the cells, per axis under ``evidence``, in no rate. Coverage is a row's evaluated tasks of an axis over the tasks the labels give it at the versions its own runs record, counted from the listings given; ``labelled`` is None, shown "?", when one of them is -missing, lacks a task any row recorded, or a run records a dataset its version does not declare. +missing, lacks a task any row recorded under that list's own id or a listed copy's task, or a run records a dataset +its version does not declare. """ from __future__ import annotations @@ -88,7 +90,7 @@ def _value(trial, verified): return (0, 0) if verified else None -def _tasks(jobs, whole, axes_of) -> tuple[dict, list, list]: +def _tasks(jobs, task_of, axes_of) -> tuple[dict, list, list]: """One row's tasks by id, the runs they come from and its warnings.""" winners, warnings = select(jobs) tasks = {} @@ -101,7 +103,7 @@ def _tasks(jobs, whole, axes_of) -> tuple[dict, list, list]: for t in same: tid = job.task_id(t) if tid: - groups.setdefault(tid[:2] + (whole(*tid[:3]), tid[3]), []).append(t) + groups.setdefault(task_of(*tid), []).append(t) unresolved = sum(job.task_id(t) is None for t in same) if unresolved: warnings.append(f"{job.job_id}: {unresolved} trials match no task: the task's identity could not be established") @@ -275,6 +277,17 @@ def _base(unchecked, axes, cohort, defined, listings, labels, rows) -> dict: def whole(benchmark, version, dataset): return next((cut for d, cut in defined.get((benchmark, version), ()) if d == dataset), None) or dataset + copied, observed = {}, {} + + def same(benchmark, version, dataset, unit): + """The task's id: its whole dataset's, then its copy's. The unit is kept as its own list recorded it, which its + listing is checked against.""" + dataset = whole(benchmark, version, dataset) + observed.setdefault((benchmark, version), {}).setdefault(dataset, set()).add(unit) + if (benchmark, version, dataset) not in copied: + copied[benchmark, version, dataset] = labels.get(benchmark, none).same(version, dataset) + return (benchmark, version, *copied[benchmark, version, dataset].get(unit, (dataset, unit))) + cache = {} def axes_of(tid): @@ -282,7 +295,7 @@ def axes_of(tid): cache[tid] = labels.get(tid[0], none).axes(*tid[1:], unchecked) return cache[tid] - per_row = {key: _tasks(jobs, whole, axes_of) for key, jobs in rows.items()} + per_row = {key: _tasks(jobs, same, axes_of) for key, jobs in rows.items()} evaluated = {key: {tid for tid, t in tasks.items() if t.resolved is not None} for key, (tasks, _, _) in per_row.items()} # nothing asked: the rows a shown axis can score; one with other tasks only would leave no task shared cohort = (list(dict.fromkeys(cohort)) if cohort is not None else @@ -300,15 +313,16 @@ def holders(tids): n = sum(len(r.tasks) for r in own.unchecked(version)) if n: warnings.append(f"{benchmark} {version}: {n} task labels not checked at this version") + n = own.unchecked_copies(version) + if n: + warnings.append(f"{benchmark} {version}: {n} task copies not checked at this version, counted apart") - recorded = {} - for tasks, runs, _ in per_row.values(): + recorded = observed + for _, runs, _ in per_row.values(): for j in runs: # a run with no task still records its dataset at = (j.identity["benchmark"], j.identity["benchmark_version"]) if j.dataset: recorded.setdefault(at, {}).setdefault(whole(*at, j.dataset), set()) - for tid in tasks: - recorded.setdefault(tid[:2], {}).setdefault(tid[2], set()).add(tid[3]) def labelled(benchmark, version): """How many tasks of one benchmark version the labels give each axis; None where a listing is missing or wrong.""" @@ -321,13 +335,23 @@ def labelled(benchmark, version): counts.update(dict.fromkeys(own.may(version, dataset, unchecked))) for dataset in declared: units = listings.get((benchmark, version, dataset)) - stray = recorded.get((benchmark, version), {}).get(dataset, set()) - set(units or ()) + seen_here = recorded.get((benchmark, version), {}).get(dataset, set()) + copies = own.same(version, dataset) + lost = {} # a listed or recorded copy its copy's listing lacks + for unit in (set(units or ()) | seen_here) & set(copies): + there = listings.get((benchmark, version, copies[unit][0])) + if there is not None and copies[unit][1] not in there: + lost.setdefault(copies[unit][0], set()).add(unit) + for of, missing in sorted(lost.items()): + warnings.append(f"{benchmark} {version} {dataset}: {len(missing)} copies are not in {of}'s listing") + counts.update(dict.fromkeys(own.may(version, dataset, unchecked) | own.may(version, of, unchecked))) + stray = seen_here - set(units or ()) if units is not None and stray: warnings.append(f"{benchmark} {version} {dataset}: {len(stray)} recorded tasks are not in its listing") - if units is None or stray: + if units is None or stray or lost: counts.update(dict.fromkeys(own.may(version, dataset, unchecked))) continue - for unit in set(units): + for unit in set(units) - set(copies): # a copy counts where its copy is listed for a in axes_of((benchmark, version, dataset, unit)): if counts.get(a, 0) is not None: counts[a] = counts.get(a, 0) + 1 diff --git a/app/tests/test_leaderboard_labels.py b/app/tests/test_leaderboard_labels.py index 26c97be50..aea7e548e 100644 --- a/app/tests/test_leaderboard_labels.py +++ b/app/tests/test_leaderboard_labels.py @@ -19,6 +19,10 @@ {"dataset": "retail", "checked": ["v1"], "tasks": ["a", "b"], "axes": ["Safety"]}, {"dataset": "retail", "checked": ["v1"], "tasks": ["b"], "not": ["Execution"]}] GOOD = labels.check({"schema": 1, "labels": RULES}, BENCH) +# two whole lists holding one question: lite's 1 is full's 7 +LISTS = [{"key": "shop", "_version": v, "datasets": [{"id": "full"}, {"id": "lite"}, {"id": "mini", "subset_of": "lite"}, {"id": "other"}], + "units": {"noun": "task", "nouns": "tasks"}} for v in ("v1", "v2")] +COPY = {"dataset": "lite", "of": "full", "checked": ["v1"], "tasks": [["1", "7"], ["2", "8"]]} def run(name, outcomes, dataset="retail", version="v1", later=0, **scores): @@ -96,6 +100,35 @@ def test_the_label_skill_names_only_ids_listed_and_published(self): for got in refused: self.assertTrue(got) self.assertFalse(any(f"'{t}'" in g or f" {t} " in g for g in got for t in "ab"), got) + # a map names the ids of both its lists + closed = [dict(b, units=dict(b["units"], redistribute=False, public_ids="tasks")) for b in LISTS] + copies, seen = {"schema": 1, "labels": [], "copies": [COPY]}, {"v1": {"1", "2", "7", "8"}} + both = {("v1", "lite"): ["1", "2"], ("v1", "full"): ["7", "8"]} + self.assertEqual(script.refusals(copies, closed, both, seen), []) + self.assertEqual(script.refusals(copies, closed, {**both, ("v1", "full"): ["7"]}, seen), ["v1 full: 1 of 2 ids not listed"]) + self.assertEqual(script.refusals(copies, closed, both, {"v1": {"1", "2", "7"}}), ["v1 full: 1 of 2 ids not published under tasks"]) + + def test_a_map_that_does_not_read_is_left_out_alone_and_said(self): + bad = [dict(COPY, of="lite"), dict(COPY, of="nowhere"), dict(COPY, dataset="mini"), dict(COPY, checked=["v9"]), + dict(COPY, tasks=[["1", "7"], ["1", "9"]]), dict(COPY, tasks=[["1", "7"], ["3", "7"]]), dict(COPY, tasks=[]), + dict(COPY, tasks={"1": "7"}), dict(COPY, more=1), dict(COPY, of="other"), + dict(COPY, dataset="full", of="other"), dict(COPY, dataset="other", of="lite"), "lite"] + both = dict(COPY, dataset="other", tasks=[["1", "7"]]) # two lists onto one: no chain + got = labels.check({"schema": 1, "labels": [], "copies": [COPY, both] + bad + [dict(COPY, checked=["v2"], tasks=[["1", "1"]])]}, LISTS) + self.assertEqual([(c.dataset, sorted(c.checked)) for c in got.copies], [("lite", ["v1"]), ("other", ["v1"]), ("lite", ["v2"])]) + self.assertEqual([p.split(": ", 1)[1] for p in got.problems], [ + "of: a map onto itself", "dataset: unknown dataset 'nowhere', at v1", "dataset: mini is cut from lite; name lite, at v1", + "checked: unknown version 'v9'; one of v1, v2", "tasks: a unit of lite mapped twice", "tasks: a unit of full mapped twice", + "tasks: [unit, its copy's unit] pairs, never empty", "tasks: [unit, its copy's unit] pairs, never empty", + "checked, dataset, of, tasks, and nothing else", "dataset: lite already has a map at a version", + "of: a chain of maps; map each onto the last", "of: a chain of maps; map each onto the last", "an object"]) + self.assertEqual([p.split(":")[0] for p in got.problems], [f"copies[{i}]" for i in range(2, len(bad) + 2)]) + closed = [dict(b, units=dict(b["units"], redistribute=False)) for b in LISTS] + self.assertEqual((labels.check({"schema": 1, "labels": [], "copies": [COPY]}, closed).copies, + labels.check({"schema": 1, "labels": [], "copies": [COPY]}, [dict(b, units=dict(b["units"], public_ids="t")) for b in closed]).problems), + ((), ())) + self.assertEqual(labels.check({"schema": 1, "labels": [], "copies": {}}, LISTS).problems, + ("{schema: 1, labels: [...], copies?: [...]} and nothing else",)) def test_a_file_that_does_not_read_labels_nothing(self): import tempfile @@ -275,6 +308,83 @@ def test_a_bad_grade_on_a_trial_with_no_task_leaves_its_run_unmeasured(self): self.assertEqual((row["every"]["axes"]["Shopping"]["n"], row["every"]["pass_k"]["all"], [w.split(": ")[1] for w in row["warnings"]]), (0, None, ["1 trials match no task", "Unsupported score scale"])) + def test_a_copy_counts_once_with_its_copys_labels_across_lists_and_rows(self): + mapped = labels.check({"schema": 1, "copies": [COPY], "labels": [ + {"axes": ["Shopping"]}, {"dataset": "full", "checked": ["v1", "v2"], "tasks": ["7"], "axes": ["Safety"]}]}, LISTS) + rows = {"both": [run("full", {"7": "agent_error", "9": "resolved"}, dataset="full"), run("lite", {"1": "resolved"}, dataset="mini", later=5)], + "lite": [run("only", {"1": "agent_error", "3": "resolved"}, dataset="lite")]} + listings = {("shop", "v1", d): units for d, units in (("full", ["7", "8", "9"]), ("lite", ["1", "2", "3"]), ("other", []))} + project = lambda labelled: projection.project(rows, LISTS, {"shop": labelled}, listings=listings) + got = project(mapped) + both, lite = got["rows"]["both"], got["rows"]["lite"] + # lite's 1 is full's 7: once, the most recent run's attempt, with 7's labels, and shared with a row that ran lite alone + self.assertEqual([(c["n"], c["resolved"]) for c in (both["every"]["axes"]["Shopping"], both["every"]["axes"]["Safety"])], [(2, 1), (1, 1)]) + self.assertEqual((got["n"]["Shopping"], [r["shared"]["axes"]["Safety"]["resolved"] for r in (both, lite)]), (1, [1, 0])) + self.assertEqual([r["coverage"]["Shopping"] for r in (both, lite)], [{"evaluated": 2, "labelled": 4}, {"evaluated": 2, "labelled": 4}]) + self.assertEqual(got["warnings"], []) + apart = project(labels.check({"schema": 1, "labels": [{"axes": ["Shopping"]}]}, LISTS))["rows"]["both"] + self.assertEqual((apart["every"]["axes"]["Shopping"]["n"], apart["coverage"]["Shopping"]["labelled"]), (3, 6)) + # at a version no map was checked at, the lists count apart, and that is said + later = projection.project({"r": [run("next", {"1": "resolved"}, dataset="lite", version="v2"), run("whole", {"7": "resolved"}, dataset="full", version="v2")]}, + LISTS, {"shop": mapped}) + self.assertEqual((later["rows"]["r"]["every"]["axes"]["Shopping"]["n"], later["warnings"]), + (2, ["shop v2: 2 task copies not checked at this version, counted apart"])) + + def test_a_listing_a_map_disagrees_with_leaves_coverage_unknown(self): + mapped = labels.check({"schema": 1, "copies": [COPY], "labels": [{"axes": ["Shopping"]}]}, LISTS) + rows = {"r": [run("lite", {"1": "resolved"}, dataset="lite")]} + listings = {("shop", "v1", "full"): ["7", "8", "9"], ("shop", "v1", "lite"): ["1", "2", "3"], ("shop", "v1", "other"): []} + coverage = lambda **changed: projection.project(rows, LISTS, {"shop": mapped}, listings={ + **listings, **{("shop", "v1", d): u for d, u in changed.items()}}) + self.assertEqual((coverage()["rows"]["r"]["coverage"]["Shopping"], coverage()["warnings"]), ({"evaluated": 1, "labelled": 4}, [])) + # lite's own listing lacks the 1 a run recorded: as without a map + got = coverage(lite=["2", "3"]) + self.assertEqual((got["rows"]["r"]["coverage"]["Shopping"]["labelled"], got["warnings"]), + (None, ["shop v1 lite: 1 recorded tasks are not in its listing"])) + # full's listing lacks 8, the copy of a listed 2 + got = coverage(full=["7", "9"]) + self.assertEqual((got["rows"]["r"]["coverage"]["Shopping"]["labelled"], got["warnings"]), + (None, ["shop v1 lite: 1 copies are not in full's listing"])) + + def test_a_copy_its_copys_listing_lacks_leaves_the_copys_axes_unknown_whatever_its_own_listing(self): + # only full is labelled: lite's own axes are none, so only the copy's can say a listing is wrong + mapped = labels.check({"schema": 1, "copies": [COPY], "labels": [{"dataset": "full", "axes": ["Shopping"]}]}, LISTS) + rows = {"r": [run("lite", {"1": "resolved", "2": "resolved"}, dataset="lite")]} + + def project(**listed): + got = projection.project(rows, LISTS, {"shop": mapped}, listings={ + ("shop", "v1", d): u for d, u in dict({"full": ["7", "8", "9"], "lite": ["1", "2", "3"], "other": []}, **listed).items() if u is not None}) + return got["rows"]["r"]["coverage"]["Shopping"], got["warnings"] + self.assertEqual(project(), ({"evaluated": 2, "labelled": 3}, [])) + lost = "shop v1 lite: 1 copies are not in full's listing" + for listed, said in (({"lite": ["2"], "full": ["7"]}, ["shop v1 lite: 1 recorded tasks are not in its listing", lost]), + ({"lite": None, "full": ["7"]}, [lost]), + ({"full": ["7", "9"]}, [lost])): + self.assertEqual(project(**listed), ({"evaluated": 2, "labelled": None}, sorted(said)), listed) + + def test_a_map_checked_at_each_version_never_says_its_tasks_count_apart(self): + each = labels.check({"schema": 1, "labels": [{"axes": ["Shopping"]}], "copies": [COPY, dict(COPY, checked=["v2"])]}, LISTS) + for version in ("v1", "v2"): + got = projection.project({"r": [run("lite", {"1": "resolved"}, dataset="lite", version=version), + run("full", {"7": "resolved"}, dataset="full", version=version)]}, LISTS, {"shop": each}) + self.assertEqual((got["rows"]["r"]["every"]["axes"]["Shopping"]["n"], got["warnings"]), (1, []), version) + + def test_a_map_reaches_a_reused_projection_as_a_fresh_one(self): + rows = {"r": [run("full", {"7": "resolved"}, dataset="full"), run("lite", {"1": "agent_error"}, dataset="lite", later=5)]} + plain, mapped = (labels.check({"schema": 1, "labels": [{"axes": ["Shopping"]}], **more}, LISTS) for more in ({}, {"copies": [COPY]})) + + listings = {("shop", "v1", "full"): ["9"], ("shop", "v1", "lite"): ["1"], ("shop", "v1", "other"): []} + + def fresh(labelled): + projection._LAST.clear() + return projection.project(rows, LISTS, {"shop": labelled}, listings=listings) + for first, then in ((plain, mapped), (mapped, plain)): + projection.project(rows, LISTS, {"shop": first}, listings=listings) + self.assertEqual(projection.project(rows, LISTS, {"shop": then}, listings=listings), fresh(then)) + self.assertEqual(fresh(mapped)["warnings"], ["shop v1 full: 1 recorded tasks are not in its listing", + "shop v1 lite: 1 copies are not in full's listing"]) + self.assertEqual([fresh(l)["rows"]["r"]["every"]["axes"]["Shopping"]["n"] for l in (plain, mapped)], [2, 1]) + def test_another_rows_version_changes_no_rows_coverage(self): rows = {"A": [run("one", {"a": "resolved"})], "B": [run("two", {"a": "resolved"}, version="v2")]} got = self.project(rows, cohort=["A"], listings={("shop", "v1", "retail"): ["a"]})["rows"] diff --git a/app/ui_tests/test_leaderboard_routes.py b/app/ui_tests/test_leaderboard_routes.py index c40bf1a09..de5d7afe6 100644 --- a/app/ui_tests/test_leaderboard_routes.py +++ b/app/ui_tests/test_leaderboard_routes.py @@ -128,6 +128,25 @@ def test_page_and_command_agree_whatever_is_asked_without_eager_trace_loads(self # one board a request, and no trajectory read for a context that changed self.assertEqual((built.call_count, read.call_count), (2, 1)) + def test_a_copy_counts_once_on_the_page_as_in_the_command(self): + version = definitions.version_identity(definitions.get("benchmark", "gsm8k")) + document = {"schema": 1, "labels": [{"axes": ["Reasoning"]}], + "copies": [{"dataset": "platinum", "of": "test", "checked": [version], "tasks": [["0", "5"]]}]} + loaded = labels.load + self.stack.enter_context(patch.object(labels, "load", lambda benchmarks: dict( + loaded(benchmarks), gsm8k=labels.check(document, [b for b in benchmarks if b["key"] == "gsm8k"])))) + self.run_of("codex", "test", {"5": "agent_error", "6": "resolved"}, "gsm8k", "test") + self.run_of("codex", "platinum", {"0": "resolved"}, "gsm8k", "platinum") + page = self.client.get("/api/leaderboard", query_string={"show_axis": "Reasoning"}).get_json() + output = io.StringIO() + with patch.object(parse, "load_all", return_value=self.jobs), redirect_stdout(output): + self.assertEqual(cli.main(["leaderboard", self.folder, "--json", "--show-axis", "Reasoning"]), 0) + command = json.loads(output.getvalue()) + row, = [r for r in page["rows"] if r["has_runs"]] + self.assertEqual((page["n"]["Reasoning"], row["shared"]["axes"]["Reasoning"]["n"]), (2, 2)) + for part in ("rows", "n", "warnings"): + self.assertEqual(command[part], page[part], part) + def test_runs_of_one_name_in_two_folders_stay_apart_on_the_page_as_in_the_command(self): self.run_of("codex", "same", {"0": "resolved"}, folder="/one", cost_usd=1.0) self.run_of("codex", "same", {"0": "resolved"}, "tau3-bench", "banking_knowledge", folder="/two", cost_usd=3.0) diff --git a/docs/field-guide.md b/docs/field-guide.md index a4bda2e27..cca0a8419 100644 --- a/docs/field-guide.md +++ b/docs/field-guide.md @@ -315,8 +315,12 @@ results do not count. Agent versions and execution setups are separate rows. their axes: capabilities and domains. A rule labels the whole benchmark, one dataset, or listed tasks of one dataset. A rule on listed tasks names the benchmark versions it was checked at; at another version it counts only with -unchecked labels included. A benchmark without labels scores nothing. Each -axis is defined under [Leaderboard axes](#leaderboard-axes); an axis's name on +unchecked labels included. A benchmark without labels scores nothing. +`copies` in `labels.json` maps tasks one dataset holds of another, the same +question and answer under another list or id: such a task counts once, as its +copy, from the most recent run that holds it, in the scores, N and coverage, at +the versions the map was checked at. A variant, another context size or +language, is never mapped and counts apart. Each axis is defined under [Leaderboard axes](#leaderboard-axes); an axis's name on the page, and the command's text, give its definition. **Function.** The scoring function, in the page's *Scoring* dialog and