Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/nullius/catalogue/benchmarks/osworld2/standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,35 @@
{
"id": "offline36",
"label": "Offline, no services",
"subset_of": "test_v2",
"summary": "36 offline tasks that need no service; some install from PyPI in the VM.",
"units": 36
},
{
"id": "no_services63",
"label": "No hosted services",
"subset_of": "test_v2",
"summary": "The 63 tasks that need no service hosted for them: Offline, no services and 27 that need the LLM grader, the simulated user or the public internet. No mock website, GitLab or proxy.",
"units": 63
},
{
"id": "websites35",
"label": "Mock website tasks",
"subset_of": "test_v2",
"summary": "The 35 tasks that need the mock websites and no GitLab or proxy: OSWorld-web served on this machine, its suffix given as Website host suffix. 2 of them use Overleaf and run one at a time.",
"units": 35
},
{
"id": "websites98",
"label": "No GitLab or proxy",
"subset_of": "test_v2",
"summary": "No hosted services and Mock website tasks: the 98 tasks that need no GitLab or proxy.",
"units": 98
},
{
"id": "test_v2_offline_no_internet",
"label": "Offline",
"subset_of": "test_v2",
"summary": "The upstream's offline list; some tasks need GitLab, a proxy or the mock websites.",
"path": "evaluation_examples/test_v2_offline_no_internet.json",
"sha256": "a14975fe0972530993d634d380ba574ecbd19b730d14716a392efe02faa62257",
Expand Down
2 changes: 2 additions & 0 deletions app/nullius/catalogue/benchmarks/terminal-bench/standard.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
{
"id": "small",
"label": "Eight tasks that build fast",
"subset_of": "full",
"units": 8,
"environment": "task"
},
{
"id": "offline",
"label": "Every task whose reference solution downloads nothing",
"subset_of": "full",
"units": 51,
"environment": "task"
},
Expand Down
145 changes: 145 additions & 0 deletions app/nullius/leaderboard/labels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
"""A benchmark's task labels: the ``labels.json`` beside its definition, read and checked rule by rule.

A rule gives axes to the whole benchmark, to one dataset, or to the listed ``tasks`` of one dataset. A task's axes
are the union of its rules' ``axes`` minus their ``not``, so the order of the rules changes nothing. A rule that
does not read is left out alone and said in ``problems``: the definition is never touched, and the benchmark runs.

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``).
"""
from __future__ import annotations

import json
import os
from dataclasses import dataclass

from nullius.standard.contract import definitions
from . import configuration

FILE = "labels.json"
SCHEMA = 1
# The board's axes, and four it does not show yet. The label skill's definitions.json names the same ones.
CAPABILITIES = configuration.CAPABILITIES + ("Reasoning", "Abstention", "Exactness")
DOMAINS = configuration.DOMAINS + ("Coding",)
FAMILIES = {"capabilities": CAPABILITIES, "domains": DOMAINS}
AXES = CAPABILITIES + DOMAINS
UNCHECKED = ("omit", "include")
_KEYS = {"dataset", "tasks", "checked", "axes", "not"}


@dataclass(frozen=True)
class Rule:
axes: frozenset = frozenset()
drop: frozenset = frozenset() # its ``not``
dataset: str = "" # "": every dataset
tasks: frozenset | None = None # None: every task
checked: frozenset = frozenset()


@dataclass(frozen=True)
class Labels:
rules: tuple = ()
problems: tuple = ()

def unchecked(self, version: str) -> list:
"""The ``tasks`` rules not checked at this version."""
return [r for r in self.rules if r.tasks is not None and version not in r.checked]

def may(self, version: str, dataset: str | None = None, unchecked: str = "omit") -> frozenset:
"""Every axis a rule can give a task of this dataset at this version; None is any dataset."""
return frozenset().union(*(r.axes for r in self.rules if (dataset is None or r.dataset in ("", dataset))
and (r.tasks is None or unchecked == "include" or version in r.checked)))

def axes(self, version: str, dataset: str, unit: str, unchecked: str = "omit") -> frozenset:
"""One task's axes; ``dataset`` is the one its list is cut from."""
hit = [r for r in self.rules if r.dataset in ("", dataset)
and (r.tasks is None or (unit in r.tasks and (unchecked == "include" or version in r.checked)))]
return frozenset().union(*(r.axes for r in hit)) - frozenset().union(*(r.drop for r in hit))


def _names(value) -> bool:
return isinstance(value, list) and bool(value) and all(isinstance(x, str) and x for x in value)


def _whole(dataset, shapes) -> str:
"""Why none of these versions, each its (whole datasets, cuts), has this whole dataset; "" when one has."""
if any(dataset in wholes for wholes, _ in shapes):
return ""
cut = next((cuts[dataset] for _, cuts in shapes if dataset in cuts), "")
return f"dataset: {dataset} is cut from {cut}; name {cut}" if cut else f"dataset: unknown dataset {dataset!r}"


def _rule(rule, shapes, task_ids):
"""The rule, or why it does not read."""
if not isinstance(rule, dict):
return "an object"
if set(rule) - _KEYS:
return f"unknown key {sorted(set(rule) - _KEYS)[0]!r}"
for key in ("axes", "not"):
if key in rule and not _names(rule[key]):
return f"{key}: a list of axis names, never empty"
unknown = [a for a in rule.get(key, []) if a not in AXES]
if unknown:
return f"{key}: unknown axis {unknown[0]!r}"
if "axes" not in rule and "not" not in rule:
return "axes or not: at least one"
dataset = rule.get("dataset", "")
if "dataset" in rule and not (isinstance(dataset, str) and dataset):
return "dataset: a dataset id"
if "dataset" in rule and _whole(dataset, shapes.values()):
return _whole(dataset, shapes.values())
if "tasks" not in rule:
return "checked: only with tasks" if "checked" in rule else Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset)
if not task_ids:
return "tasks: this benchmark's ids may not be redistributed (units.redistribute); dataset rules only"
if not _names(rule["tasks"]):
return "tasks: a list of task ids, never empty"
if not dataset:
return "tasks: only with a dataset"
if not _names(rule.get("checked")):
return "checked: the versions these tasks were checked at"
unknown = [v for v in rule["checked"] if v not in shapes]
if unknown:
return f"checked: unknown version {unknown[0]!r}; one of {', '.join(shapes)}"
for v in rule["checked"]:
if _whole(dataset, [shapes[v]]):
return f"{_whole(dataset, [shapes[v]])}, at {v}"
return Rule(frozenset(rule.get("axes", [])), frozenset(rule.get("not", [])), dataset, frozenset(rule["tasks"]), frozenset(rule["checked"]))


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",))
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")}
shapes[definitions.version_identity(b)] = ({d["id"] for d in b.get("datasets") or []} - set(cuts), cuts)
task_ids = all((b.get("units") or {}).get("redistribute") is not False for b in versions)
rules, problems = [], []
for i, rule in enumerate(document["labels"]):
got = _rule(rule, shapes, task_ids)
if isinstance(got, Rule):
rules.append(got)
else:
problems.append(f"labels[{i}]: {got}")
return Labels(tuple(rules), tuple(problems))


def load(benchmarks) -> dict:
"""Each benchmark's labels by its key, from ``definitions.load("benchmark", every=True)``; a benchmark with no
``labels.json`` labels nothing."""
by_key = {}
for b in benchmarks:
by_key.setdefault(b["key"], []).append(b)
out = {}
for key, versions in by_key.items():
try:
with open(os.path.join(versions[0]["_here"], FILE), encoding="utf-8") as f:
out[key] = check(json.load(f), versions)
except FileNotFoundError:
out[key] = Labels()
except (OSError, ValueError, RecursionError) as error:
out[key] = Labels(problems=(str(error),))
return out
Loading
Loading