Skip to content
Closed
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
9 changes: 6 additions & 3 deletions .agents/skills/flag-tasks/scripts/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def spot(args):
run = seen.setdefault(ref.key, {}).setdefault(path, [0, 0])
run[0] += float(t.reward) >= 1
run[1] += 1
where.setdefault(ref.key, (ref.name, t.dir))
# what an import finds it by: its exact identity, else a raw unit as such, else its name
exact = {"id": ref.key} if ref.shared and ref.key != ref.name else {"unit": True} if t.unit else {}
where.setdefault(ref.key, (ref.name, t.dir, exact))
if not seen:
sys.exit("no attempt with a reward: nothing to count")
if len(datasets) > 1:
Expand All @@ -81,7 +83,7 @@ def spot(args):
with open(os.path.join(where[task][1], "result.json"), encoding="utf-8") as fh:
task_id = json.load(fh).get("task_id") or {}
cases.append({"task": where[task][0], "group": groups[task], "runs": list(seen[task].values()),
"task_folder": task_id.get("path")})
"task_folder": task_id.get("path"), **where[task][2]})
write(args.out, "cases.json", cases)
write(args.out, "for-readers.json", for_readers(cases))
count = Counter(groups.values())
Expand Down Expand Up @@ -196,7 +198,8 @@ def merge(args):
if agree:
lead = next(v for v in agree if flat(v["category"]) == categories[0])
flags.append({"task": task, "kind": result, "category": categories[0],
"evidence": f"{flat(lead['evidence'])} ({len(agree)} of {len(votes)})"})
"evidence": f"{flat(lead['evidence'])} ({len(agree)} of {len(votes)})",
**{k: case[k] for k in ("id", "unit") if k in case}})
said = "; ".join(f"{v['reader']}: {v['verdict']}" for v in votes)
rows.append((task, case["group"], result, ", ".join(categories), said, votes))
order = {k: i for i, k in enumerate(("third", "contested", "flawed", "ambiguous", "undecided", "unread", "fair"))}
Expand Down
4 changes: 2 additions & 2 deletions app/nullius/compare/comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ def n_differing(self) -> int:
def task_key(selection: SelectedRun, trial: Trial) -> tuple:
"""A task's identity across columns: its recorded dataset and its name. Missing dataset identities cannot
prove that identical short names refer to the same task; a per-column sentinel keeps their rows apart.
A standard trial adds its own key (``parse.task_ref``): its exact identity, else one of its job alone."""
A standard trial adds its own key (``parse.task_ref``): its exact identity, else one of its column alone."""
ref = parse.task_ref(selection.job, trial)
return (selection.job.dataset or f"[unidentified:{selection.value}]", ref.name,
None if ref.key == ref.name else (ref.key, ref.shared))
None if ref.key == ref.name else (ref.key if ref.shared else (ref.key, selection.value), ref.shared))


def build(selected: Sequence[SelectedRun], cohort: str = "whole", set_aside: frozenset = frozenset()) -> Comparison:
Expand Down
36 changes: 19 additions & 17 deletions app/nullius/compare/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
def flag_filter(selected, exclude=()) -> dict:
"""The flag filters of a comparison: one list of tasks set aside in every column, the union of the runs'
accepted flags of the kinds in ``exclude``, keyed as the comparison keys a task (`comparison.task_key`). A flag
counts only on the task version it names, and a task is set aside only when every column holding it ran the
same version; otherwise it stays, and is named in `differ` with the tasks the runs flag differently.
`flagged` counts each kind over all runs, for the switches; `unreadable` names runs whose file is broken."""
counts only on the trials it applies to (`failure_analysis.holds`), and a task is set aside only when all its
trials, in every column, ran the same version; otherwise it stays, and is named in `differ` with the tasks the
runs flag differently. `flagged` counts each kind over all runs, for the switches; `unreadable` names runs whose
file is broken."""
on = [k for k in failure_analysis.KINDS if k in exclude]
runs, unreadable = [], [] # per run: {task key: version}, {task key: kind}
runs, unreadable = [], [] # per run: its trials and their keys, {task key: kind}, its keys
for selection in selected:
job = selection.job
try:
Expand All @@ -22,21 +23,22 @@ def flag_filter(selected, exclude=()) -> dict:
analysis = failure_analysis.Analysis()
unreadable.append(job.job_id)
analysis = failure_analysis.for_job(job, analysis)
versions = failure_analysis.task_versions(job, analysis.flags) if analysis.flags else {}
tasks = {} # each task of the job to its comparison keys: one per identity it ran
for t in job.trials:
tasks.setdefault(failure_analysis.task_of(t), set()).add(comparison.task_key(selection, t))
kinds = {key: kind for kind in failure_analysis.KINDS
for task in analysis.set_aside([kind], versions) & set(tasks) for key in tasks[task]}
runs.append((selection, tasks, kinds, set().union(*tasks.values())))
versions = failure_analysis.trial_versions(job, analysis.flags) if analysis.flags else {}
trials, kinds = [(t, comparison.task_key(selection, t)) for t in job.trials], {}
for t, key in trials:
flag = analysis.flags.get(failure_analysis.task_of(t))
if flag is not None and flag.status == "accepted" and failure_analysis.holds(flag, t, versions):
kinds[key] = flag.kind
runs.append((selection, trials, kinds, {key for _, key in trials}))
flagged_keys = set().union(*(kinds for _, _, kinds, _ in runs))
# the versions every column holding a flagged task ran, read once per run for those tasks
# the versions the trials of a flagged task ran in every column, read once per run for its tasks
ran = {}
for selection, tasks, _, _ in runs:
names = {task for task, keys in tasks.items() if keys & flagged_keys}
for task, version in failure_analysis.task_versions(selection.job, names).items():
for key in tasks[task]:
ran.setdefault(key, set()).add(version)
for selection, trials, _, _ in runs:
flagged = [(t, key) for t, key in trials if key in flagged_keys]
versions = failure_analysis.trial_versions(selection.job, {failure_analysis.task_of(t) for t, _ in flagged})
for t, key in flagged:
if t.trial_name in versions:
ran.setdefault(key, set()).add(versions[t.trial_name])
holders = {key: [r for r in runs if key in r[3]] for key in flagged_keys}
differ = sorted(key[1] for key in flagged_keys
if len(ran.get(key, set())) > 1 or len({kinds.get(key) for _, _, kinds, _ in holders[key]}) > 1)
Expand Down
Loading