Download checks/compare_task_trees.py from HuggingFaceSwarms/collaborative-intelligence-benchmark: direct link, hf CLI and curl.
- Browser
- Download file 3.25 kB
-
https://huggingface.co/datasets/HuggingFaceSwarms/collaborative-intelligence-benchmark/resolve/main/checks/compare_task_trees.py
- Command line
-
hf download hf://datasets/HuggingFaceSwarms/collaborative-intelligence-benchmark/checks/compare_task_trees.py
-
curl -L -o compare_task_trees.py https://huggingface.co/datasets/HuggingFaceSwarms/collaborative-intelligence-benchmark/resolve/main/checks/compare_task_trees.py
3.25 kB
| #!/usr/bin/env python3 | |
| """Compare published task trees against fresh generated dimension trees.""" | |
| import hashlib, json, sys | |
| from collections import Counter | |
| from pathlib import Path | |
| old, generated = map(Path, sys.argv[1:3]) | |
| failures = [] | |
| for dimension in ('sharing', 'tracking', 'initiative', 'takeover'): | |
| root = generated / dimension | |
| rows = json.loads((root / 'manifest.json').read_text())['tasks'] | |
| counts = Counter() | |
| for row in rows: | |
| before, after = old / 'tasks' / row['task_id'], root / row['task_id'] | |
| a = {p.relative_to(before).as_posix(): p for p in before.rglob('*') if p.is_file()} | |
| b = {p.relative_to(after).as_posix(): p for p in after.rglob('*') if p.is_file()} | |
| if a.keys() != b.keys(): failures.append((dimension, row['task_id'], 'file set', sorted(a.keys() ^ b.keys()))) | |
| for name in a.keys() & b.keys(): | |
| x, y = a[name].read_bytes(), b[name].read_bytes() | |
| if x == y: continue | |
| if name in {'environment/team/runtime.json', 'environment/team/runtime.tar.gz', 'tests/runtime.json', 'tests/runtime.tar.gz'}: | |
| counts['runtime files changed'] += 1 | |
| if name.endswith('runtime.json'): | |
| oldfiles = json.loads(x)['files']; newfiles = json.loads(y)['files'] | |
| removed = {f'adapter/collab_harbor/{n}.py' for n in ('legion_config', 'legion_results', 'run_benchmark')} | |
| expected_changed = {'adapter/collab_harbor/runtime-files.json', 'adapter/collab_harbor/scoring.py'} | |
| changed = {k for k in oldfiles.keys() & newfiles.keys() if oldfiles[k] != newfiles[k]} | |
| if oldfiles.keys() - newfiles.keys() != removed or newfiles.keys() - oldfiles.keys() or changed != expected_changed: | |
| failures.append((dimension, row['task_id'], name, 'unexpected archive inventory change')) | |
| elif name == 'environment/team/task.json': | |
| counts['task.json changed (outside runtime files)'] += 1 | |
| x, y = json.loads(x), json.loads(y) | |
| xc, yc = x['effective_code']['components'], y['effective_code']['components'] | |
| allowed = {'team_adapter', 'verifier_adapter', 'team_runtime_distribution', 'verifier_runtime_distribution', 'runtime_distribution'} | |
| changed = {k for k in xc.keys() | yc.keys() if xc.get(k) != yc.get(k)} | |
| if changed != allowed: failures.append((dimension, row['task_id'], name, f'unexpected code identity components: {changed}')) | |
| if x['runtime_distribution']['format'] != y['runtime_distribution']['format']: | |
| failures.append((dimension, row['task_id'], name, 'runtime format changed')) | |
| for key in ('effective_code', 'runtime_distribution'): | |
| x.pop(key, None); y.pop(key, None) | |
| if x != y: failures.append((dimension, row['task_id'], name, 'non-provenance content changed')) | |
| else: failures.append((dimension, row['task_id'], name, 'changed')) | |
| counts['tasks'] += 1 | |
| print(dimension, dict(counts), flush=True) | |
| print('unexpected differences:', len(failures)) | |
| for failure in failures: print(*failure) | |
| sys.exit(bool(failures)) | |