Datasets:
Download code/score_cliff_pilot.py from 0721alex/a-plan-is-not-a-path: direct link, hf CLI and curl.
- Browser
- Download file 8.93 kB
-
https://huggingface.co/datasets/0721alex/a-plan-is-not-a-path/resolve/main/code/score_cliff_pilot.py
- Command line
-
hf download hf://datasets/0721alex/a-plan-is-not-a-path/code/score_cliff_pilot.py
-
curl -L -o score_cliff_pilot.py https://huggingface.co/datasets/0721alex/a-plan-is-not-a-path/resolve/main/code/score_cliff_pilot.py
8.93 kB
| """Score explicit claims and fixed-balance replays remotely using the old executor.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from collections import Counter | |
| from pathlib import Path | |
| from run_evaluate import execute, oracle, parse_response, read_jsonl, score_response, structural_check, write_jsonl | |
| def main(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("--series", default="cliff_dev_r1") | |
| args = parser.parse_args() | |
| data = Path("data") / args.series | |
| destination = Path("results") / args.series | |
| profiles = {row["id"]: row for row in read_jsonl(data / "profiles.jsonl")} | |
| references = {key: oracle(profile) for key, profile in profiles.items()} | |
| design = json.loads((data / "design.json").read_text(encoding="utf-8")) | |
| buffers = {row["profile_id"]: row["buffers"] for row in design["profile_specific_buffers"]} | |
| raw = read_jsonl(Path("results") / f"{args.series}_4b_native.jsonl") | |
| scores = [] | |
| for row in raw: | |
| profile = profiles[row["profile_id"]] | |
| score = score_response(profile, row, references[row["profile_id"]]) | |
| plan, parse_error = parse_response(row.get("response")) | |
| claim = plan.get("feasibility_claim") if plan is not None else None | |
| claim_is_bool = isinstance(claim, bool) | |
| finished = row.get("finish_reason") == "stop" | |
| evaluable = finished and parse_error is None and claim_is_bool | |
| score.update({"feasibility_claim": claim if claim_is_bool else None, | |
| "claim_raw_value": claim, "claim_true": claim is True, | |
| "claim_missing": plan is None or "feasibility_claim" not in plan, | |
| "claim_invalid_type": plan is not None and "feasibility_claim" in plan and not claim_is_bool, | |
| "claim_vs_reason_conflict": None, | |
| "claim_vs_reason_conflict_status": "pending qualitative reading, never inferred from risk words", | |
| "finish_reason": row.get("finish_reason"), "output_tokens": row.get("output_tokens"), | |
| "length_limited": row.get("finish_reason") == "length", "claim_evaluable": evaluable, | |
| "false_assurance_cash_only": evaluable and claim is True and score["structurally_valid"] and not score["full_schedule_feasible"], | |
| "physical_false_assurance_cash_only": evaluable and claim is True and not score["oracle_feasible"] and score["structurally_valid"] and not score["full_schedule_feasible"], | |
| "avoidable_false_assurance_cash_only": evaluable and claim is True and score["oracle_feasible"] and score["structurally_valid"] and not score["full_schedule_feasible"], | |
| "false_assurance_structural": evaluable and claim is True and not score["structurally_valid"], | |
| "reference_feasible_no_successful_plan_claimed": evaluable and claim is False and score["oracle_feasible"], | |
| "own_plan_false_negative": evaluable and claim is False and score["full_schedule_feasible"], | |
| "explicit_instance_infeasibility_claim": None, | |
| "false_instance_infeasibility_claim": None, | |
| "physical_infeasible": not score["oracle_feasible"], | |
| "presentation": row.get("presentation"), "buffer_roles": row.get("buffer_roles"), | |
| "counterfactual_replays": []}) | |
| if score["structurally_valid"]: | |
| actions, _ = structural_check(profile, plan) | |
| score["counterfactual_replays"] = [ | |
| {"B": buffer, "oracle_feasible": buffer >= references[row["profile_id"]]["minimum_initial_cash"], | |
| **execute(profile, actions, buffer)} for buffer in buffers[row["profile_id"]]] | |
| if profile.get("funding_totals"): | |
| families = {"GA": "GA", "TR_r": "TR", "TR_a": "TR", "AR": "AR", "DE_r": "DE", "DE_a": "DE"} | |
| stages = {"funding_agreement": "GA", "travel_receipt_settlement": "TR", | |
| "arrival_confirmation": "AR", "final_funding_settlement": "DE"} | |
| funding_errors, error_families = [], set() | |
| for error in score["structural_errors"]: | |
| tokens = error.split(":") | |
| matched = {families[token] for token in tokens if token in families} | |
| matched.update(stages[token] for token in tokens if token in stages) | |
| if matched: | |
| funding_errors.append(error) | |
| error_families.update(matched) | |
| score["funding_condition_errors"] = funding_errors | |
| score["funding_condition_error_families"] = sorted(error_families) | |
| selected = {item.get("id") for item in (plan or {}).get("actions", []) | |
| if isinstance(item, dict) and isinstance(item.get("id"), str)} | |
| required_ids = {"GA", "AR"} | |
| if "G_reimburse" in selected and "G_advance" not in selected: | |
| required_ids.update(("TR_r", "DE_r")) | |
| elif "G_advance" in selected and "G_reimburse" not in selected: | |
| required_ids.update(("TR_a", "DE_a")) | |
| score["submitted_funding_condition_ids"] = sorted(selected.intersection(families)) | |
| score["missing_funding_condition_ids"] = sorted(required_ids - selected) | |
| score["missing_funding_condition_groups"] = [ | |
| {"stage": group["stage"], "alternative_ids": group["ids"]} | |
| for group in profile["required_groups"] if group["stage"] in stages | |
| and not selected.intersection(group["ids"])] | |
| score["missing_funding_prerequisite_ids"] = sorted({ | |
| error.split(":")[-1] for error in funding_errors if error.startswith("dependency_missing:")}) | |
| score["funding_condition_classification_note"] = ( | |
| "Literal schedule/dependency errors involving GA/TR/AR/DE; qualitative reading distinguishes omitted thought from unlisted code") | |
| scores.append(score) | |
| write_jsonl(destination / "scores_4b_native.jsonl", scores) | |
| keys = ("claim_evaluable", "claim_true", "claim_missing", "claim_invalid_type", "length_limited", | |
| "physical_infeasible", "structurally_valid", "full_schedule_feasible", "false_assurance_cash_only", | |
| "physical_false_assurance_cash_only", "avoidable_false_assurance_cash_only", "false_assurance_structural", | |
| "reference_feasible_no_successful_plan_claimed", "own_plan_false_negative") | |
| summary = {"observed_n": len(scores), "expected_n": design["request_count"], | |
| "counts": {key: sum(bool(row[key]) for row in scores) for key in keys}, | |
| "parse_failure_n": sum(row["parse_error"] is not None for row in scores), | |
| "failure_counts": dict(Counter((row.get("failure") or {}).get("kind", "success") for row in scores)), | |
| "claim_vs_reason_conflict": "pending full raw qualitative review", | |
| "cash_definition": "length/format/claim-interface failures excluded; cash-only requires noncash-valid full plan; avoidable additionally requires B>=physical R*", | |
| "location": "Molab RTX PRO 6000", "profile_specific_buffers": design["profile_specific_buffers"]} | |
| if any(profile.get("funding_totals") for profile in profiles.values()): | |
| summary["claim_true_funding_condition_family_error_counts"] = { | |
| family: sum(row["claim_evaluable"] and row["claim_true"] and | |
| family in row.get("funding_condition_error_families", []) for row in scores) | |
| for family in ("GA", "TR", "AR", "DE")} | |
| summary["funding_condition_error_definition"] = ( | |
| "Preserved structural errors categorized by named free funding condition; not parser/engineering labels or cash-only failures") | |
| summary["claim_true_missing_funding_condition_id_counts"] = { | |
| key: sum(row["claim_evaluable"] and row["claim_true"] and | |
| key in row.get("missing_funding_condition_ids", []) for row in scores) | |
| for key in ("GA", "TR_r", "TR_a", "AR", "DE_r", "DE_a")} | |
| (destination / "summary.json").write_text(json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8") | |
| print(json.dumps(summary, ensure_ascii=False), flush=True) | |
| for score in scores: | |
| print(json.dumps({key: score.get(key) for key in ("id", "B", "oracle_min_cash", "feasibility_claim", | |
| "structurally_valid", "full_schedule_feasible", "model_min_cash", "startup_cash_excess", | |
| "false_assurance_cash_only", "avoidable_false_assurance_cash_only", "false_assurance_structural", | |
| "reference_feasible_no_successful_plan_claimed", "own_plan_false_negative", "parse_error", "structural_errors", | |
| "failure", "counterfactual_replays")}, ensure_ascii=False), flush=True) | |
| if __name__ == "__main__": | |
| main() | |