Melikshah/Operational-Harm / scripts /41_assist_build.py
Melikshah's picture
download
raw
2.26 kB
import hashlib
import json
from collections import Counter
import opharm
from opharm.bench import assist
from opharm.paths import BENCH, RESULTS
OUT = BENCH / "assist"
def write(name, rows):
path = OUT / f"{name}.jsonl"
path.write_text("".join(json.dumps(r) + "\n" for r in rows))
return hashlib.sha256(path.read_bytes()).hexdigest()
def main():
OUT.mkdir(exist_ok=True)
parts = assist.build()
parts["pilot"] = assist.pilot()
parts["a2u"] = assist.extra_arms()
parts["a3"] = assist.extra_arms(arms=("A3",))
parts["rep_dev"] = assist.replication()
files = {name: {"sha256": write(name, rows), "n": len(rows),
"by_arm": dict(Counter(f"{r['rule']}.{r['arm']}" for r in rows))} for name, rows in parts.items()}
sks = assist.cohort()
m = assist.marks()
info = {
"files": files,
"cohort": {"split": "heldout", "skeletons": len(sks), "templates": sorted({s["template"] for s in sks}),
"bp_clean_templates": sorted({s["template"] for s in sks if assist.bp_clean(m[s["template"]])}),
"think_skeletons": len(assist.think_skeletons(sks)), "replication_dev_skeletons": len({r["skeleton"] for r in parts["rep_dev"]})},
"wording": {"verdict": assist.VERDICT, "verdict_unambiguous": assist.VERDICT_U, "condition": assist.CONDITION,
"condition_conjunction": assist.CONDITION_CJ, "important": assist.IMPORTANT, "environment": assist.ENVIRONMENT,
"balanced": assist.BALANCED, "policy_all": assist.POLICY_ALL, "policy_conj": assist.POLICY_CONJ,
"questions": assist.QUESTIONS, "queues": assist.QUEUES, "verbs": assist.VERB, "outage": assist.OUTAGE},
"sources": {"instances": hashlib.sha256((BENCH / "instances.jsonl").read_bytes()).hexdigest(),
"skeletons": hashlib.sha256((BENCH / "skeletons.jsonl").read_bytes()).hexdigest(),
"variants_trg": hashlib.sha256((BENCH / "variants_trg.jsonl").read_bytes()).hexdigest()},
}
(RESULTS / "assist_instances.json").write_text(json.dumps(info, indent=1))
print(json.dumps({k: (v["n"], v["by_arm"]) for k, v in files.items()}, indent=1))
if __name__ == "__main__":
main()

Xet Storage Details

Size:
2.26 kB
·
Xet hash:
abb376e49538aba7af0b500ab006f0941e5ef51f8c5e7b61cd2e136532de5e2b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.