Datasets:
Download code/build_diagnostics.py from 0721alex/a-plan-is-not-a-path: direct link, hf CLI and curl.
- Browser
- Download file 19.6 kB
-
https://huggingface.co/datasets/0721alex/a-plan-is-not-a-path/resolve/main/code/build_diagnostics.py
- Command line
-
hf download hf://datasets/0721alex/a-plan-is-not-a-path/code/build_diagnostics.py
-
curl -L -o build_diagnostics.py https://huggingface.co/datasets/0721alex/a-plan-is-not-a-path/resolve/main/code/build_diagnostics.py
19.6 kB
| """Build the fixed diagnostic subsets on Molab after main inference. | |
| Anchors use only the frozen main grid and its deterministic references. The | |
| academic W0 baseline is reused rather than generated again. All numerical work | |
| and JSONL generation belong on the same remote machine as the main experiment. | |
| """ | |
| from __future__ import annotations | |
| import copy | |
| import json | |
| from collections import Counter | |
| from itertools import product | |
| from pathlib import Path | |
| from build_core_dev import core_prompt, core_prose | |
| from build_dataset import public_facts | |
| from run_evaluate import oracle, read_jsonl, write_jsonl | |
| PROFILE_IDS = ["holdout_04", "holdout_05", "holdout_08", "holdout_09"] | |
| STATE_NOTE = "请先按实际付款与到账顺序推算可用余额、必须保持的余额和最早短缺时点,再选择路线。" | |
| GAME_NOTICE = ( | |
| "这是完全合成的封闭资源游戏规划题。以下资源数量、补给机会、时间和可用补给均为题目设定," | |
| "请只按给定规则规划。" | |
| ) | |
| GAME_MAPPING = { | |
| "普通公办大学学生及过去科研、英语、联系和申请": "玩家及已完成的过去准备关卡", | |
| "访问邀请及生活资助书O": "已完成的资格与定期补给确认O", | |
| "当前可用现金、人民币元": "当前可用资源、资源点", | |
| "差旅报销登记及报销到账": "延后补给登记及实际补给", | |
| "差旅资助预付及预付到账": "提前补给申请及实际补给", | |
| "证明D1、差旅估算D2": "补给凭据D1、路径估算D2", | |
| "资助书抵扣证明额及连续余额核对P": "资格确认替代部分核对要求及连续资源余额核对P", | |
| "行前手续V": "关卡准入手续V", | |
| "交通预订T": "进入路径预订T", | |
| "到达H及住宿押金": "进入目标关卡H及可返还的资源占用", | |
| "月生活补助、生活费": "定期补给、定期维护消耗", | |
| "退款、不可退费用": "资源返还、不可回收的消耗", | |
| "完成一年访问F": "完成一年挑战F", | |
| "家庭不能追加、没有借款": "无额外补给或临时资源来源", | |
| "真实执行": "按规则执行", | |
| } | |
| def reference_anchors(reference, grid): | |
| best = reference["minimum_initial_cash"] | |
| reimbursement = next(route["minimum_initial_cash"] for route in reference["route_minima"] | |
| if route["route_id"] == "reimbursement") | |
| anchors = { | |
| "below_best": max(value for value in grid if value < best), | |
| "first_at_or_above_best": min(value for value in grid if value >= best), | |
| "last_below_reimbursement": max(value for value in grid if value < reimbursement), | |
| "first_at_or_above_reimbursement": min(value for value in grid if value >= reimbursement), | |
| } | |
| return {"profile_id": reference["profile_id"], "minimum_initial_cash": best, | |
| "reimbursement_minimum_initial_cash": reimbursement, "anchors": anchors, | |
| "world_buffers": list(dict.fromkeys(anchors.values())), | |
| "feasible_buffers": list(dict.fromkeys([ | |
| anchors["first_at_or_above_best"], anchors["first_at_or_above_reimbursement"]]))} | |
| def world_profile(base, world): | |
| profile = copy.deepcopy(base) | |
| profile["id"] = base["id"] + "__" + world | |
| profile["base_profile_id"] = base["id"] | |
| profile["world"] = world | |
| actions = {action["id"]: action for action in profile["actions"]} | |
| if world == "W1": | |
| actions["G_reimburse"]["cash_effects"][0]["offset"] = 40 | |
| actions["G_reimburse"]["label"] = "办理普通差旅支持登记" | |
| actions["G_reimburse"]["cash_effects"][0]["label"] = "普通差旅支持实际到账" | |
| profile["prose_card"] = core_prose(profile).replace( | |
| "普通报销登记G_reimburse", "普通差旅支持登记G_reimburse", 1) | |
| elif world == "W2": | |
| actions["G_advance"]["deps"] = [{"id": "O", "lag": 7}] | |
| for key in ("D1", "D2"): | |
| actions[key]["label"] = "可选免费无效果整理事项" + key | |
| actions[key]["deps"] = [] | |
| actions[key]["earliest"] = 0 | |
| actions[key]["latest"] = profile["horizon_days"] | |
| actions[key].pop("allowed_days", None) | |
| for route in profile["available_routes"]: | |
| if route["id"] == "advance": | |
| route["actions"] = [key for key in route["actions"] if key not in ("D1", "D2")] | |
| old_actions = {action["id"]: action for action in base["actions"]} | |
| dates = lambda key: "或".join(str(day) for day in old_actions[key]["allowed_days"]) | |
| amount = actions["G_advance"]["cash_effects"][0]["amount"] | |
| offset = actions["G_advance"]["cash_effects"][0]["offset"] | |
| old = ( | |
| f"预付方式先在第{dates('D1')}天收集证明D1,免费,须在O之后至少5天;" | |
| f"再在第{dates('D2')}天提交差旅估算D2,免费,须在D1之后至少4天。" | |
| f"最后第{dates('G_advance')}天申请预付G_advance,免费,须在D2之后至少7天;" | |
| f"{amount}元在申请后第{offset}天真正到账。" | |
| ) | |
| new = ( | |
| f"预付方式不再要求证明D1或估算D2,第{dates('G_advance')}天直接申请预付G_advance,免费," | |
| f"须在已经完成的O之后至少7天;{amount}元在申请后第{offset}天真正到账。" | |
| f"D1和D2仅为可选的免费无效果整理事项,可在第0至第{profile['horizon_days']}天内任何整数日办理;" | |
| "它们没有前置步骤,彼此不相互依赖,不提供款项,也不影响任何必需步骤。" | |
| ) | |
| profile["prose_card"] = base["prose_card"].replace(old, new, 1).replace( | |
| "是本届仅有的办理批次,不接受其他日期。", | |
| "有固定批次的步骤只接受列出的日期;可选D1和D2的可办日期另行注明。", 1).replace( | |
| "预付方式的免费前置手续D1和D2也须按通知完成。", | |
| "D1和D2为可选的免费无效果整理事项,不属于预付方式的前置义务。", 1) | |
| else: | |
| raise ValueError("Unknown world: " + world) | |
| return profile | |
| def game_prompt(profile, buffer): | |
| """Authored domain/genre rewrite; score with unchanged academic W0 facts.""" | |
| actions = {action["id"]: action for action in profile["actions"]} | |
| day = lambda key: actions[key]["allowed_days"][0] | |
| dates = lambda key: "或".join(str(value) for value in actions[key]["allowed_days"]) | |
| amount = actions["G_reimburse"]["cash_effects"][0]["amount"] | |
| late_offset = actions["G_reimburse"]["cash_effects"][0]["offset"] | |
| early_offset = actions["G_advance"]["cash_effects"][0]["offset"] | |
| occupied = next(effect["amount"] for effect in actions["H"]["cash_effects"] | |
| if effect["label"] == "住宿押金退回") | |
| refill = next(effect["amount"] for effect in actions["H"]["cash_effects"] | |
| if effect["label"] == "月生活补助实际到账") | |
| maintenance = -next(effect["amount"] for effect in actions["H"]["cash_effects"] | |
| if effect["label"] == "月生活费") | |
| hold = actions["P"].get("hold") | |
| if hold: | |
| proof = ( | |
| "资格与定期补给确认O已替代它覆盖部分的资源余额核对要求," | |
| f"剩余需核对的资源余额仅{hold['amount']}点。第{day('P')}天办理剩余资源余额核对P," | |
| f"不消耗资源,须在O之后至少14天;P当天及之前连续28天," | |
| f"每天的资源余额都须至少{hold['amount']}点。" | |
| ) | |
| proof_stage = "资源余额核对P" | |
| else: | |
| proof = ( | |
| "资格与定期补给确认O已覆盖本实例全部资源余额核对要求,不需要额外资源余额或连续持有资源。" | |
| f"第{day('P')}天核对这份资格与定期补给确认P,不消耗资源,须在O之后至少14天。" | |
| ) | |
| proof_stage = "资格确认核对P" | |
| card = ( | |
| "【玩家来信】我是游戏玩家,已经完成过去的准备关卡,并已取得一年挑战的资格与定期补给确认O。" | |
| "此前准备消耗的资源已经扣除。今天是取得确认后的第0天,我现在要办好剩余关卡手续、" | |
| "实际进入目标关卡并完成一年挑战。题目给的B是今天实际可立即动用的剩余资源;" | |
| "没有额外补给或临时资源来源。\n\n" | |
| "【已确认事实与实例说明】这是完全合成的封闭实例,所有资源数量、机会和本届办理批次都是游戏设定。" | |
| "资格与定期补给确认O是第0天已完成的初始事实,无需重新办理或列入未来日程;" | |
| "确认本身不等于已经实际取得资源。过去准备关卡的消耗已扣除,当前B是扣除之后的实际资源余额," | |
| f"不再扣除那些历史消耗。目标是在第{profile['horizon_days']}天前完成一年挑战。" | |
| "以下所有日期以今天第0天为原点,是本届仅有的办理批次,不接受其他日期。\n\n" | |
| f"【路径补给通知】路径补给有两种互斥方式,数量同为{amount}点,必须选择一种。" | |
| f"延后补给登记G_reimburse仅第{day('G_reimburse')}天办理,不消耗资源,须在已经完成的O之后至少7天;" | |
| f"登记后第{late_offset}天,即第{day('G_reimburse') + late_offset}天,{amount}点才实际取得。" | |
| f"提前补给方式先在第{dates('D1')}天收集补给凭据D1,不消耗资源,须在O之后至少5天;" | |
| f"再在第{dates('D2')}天提交路径估算D2,不消耗资源,须在D1之后至少4天。" | |
| f"最后第{dates('G_advance')}天申请提前补给G_advance,不消耗资源,须在D2之后至少7天;" | |
| f"{amount}点在申请后第{early_offset}天真正取得。G_reimburse和G_advance不能并用。\n\n" | |
| "【关卡准入通知】" + proof + | |
| f"第{day('V')}天办理关卡准入手续V,消耗{actions['V']['cost']}点不可回收,须在P之后至少1天。" | |
| f"第{day('T')}天预订进入路径T,消耗{actions['T']['cost']}点,其中50%可返还,须在V之后至少7天。\n\n" | |
| f"【进入关卡及定期补给通知】第{day('H')}天进入目标关卡H,须在T之后至少7天," | |
| f"当天付出{actions['H']['cost']}点,其中{occupied}点是可返还的资源占用,其余不可回收。" | |
| "定期补给不提前发:进入关卡后第30、60、90、120、150、180、210、240、270、300、330天," | |
| f"每次一早实际取得{refill}点,晚些时候消耗{maintenance}点用于定期维护。" | |
| f"进入关卡后第360天返还{occupied}点资源占用。第{day('F')}天完成挑战F,不消耗资源," | |
| "须在H之后至少365天。\n\n" | |
| f"【未来必须完成的阶段】路径补给G_reimburse或G_advance;{proof_stage};关卡准入手续V;" | |
| "进入路径T;进入关卡H;完成挑战F。提前补给方式不消耗资源的前置手续D1和D2也须按通知完成。" | |
| "除明确实际取得的这些资源外,没有其他补给或临时资源来源;已确认的资格本身不能当作可用资源。" | |
| ) | |
| request = ( | |
| f"截至第0天,我现在能立即动用的资源只有{buffer}点,这已是过去准备消耗扣除后的余额。" | |
| "请仅规划未来步骤,安排能按规则执行并在本实例给定期限内完成一年挑战的计划。" | |
| "给出实际采用的步骤代号与办理日期,选择补给路线和资源付出顺序。若确实无法完成,说明卡点," | |
| "并仍列出当前值得且能够按规则执行的步骤。日期只能从通知列出的本届办理批次中选择," | |
| "满足最短间隔后也不能自行改变日期。逐项列出所选方案全部未来必需步骤,包括不消耗资源的前置手续和核对;" | |
| "不能改名、合并或默认自动完成。先用不超过150字中文说明,再给出一个且仅一个JSON对象," | |
| '格式为{"actions":[{"id":"步骤代号","day":整数日期}],"reason":"简短说明"}。' | |
| "day从今天第0天起算,同日步骤按列出的顺序办理。后续补给在指定日期一早可用," | |
| "后续维护消耗在当天晚些时候付出;步骤当天附带的资源取得和消耗跟随该步骤。" | |
| ) | |
| return GAME_NOTICE + "\n\n" + card + "\n\n" + request | |
| def request_from(base, condition="natural", world="W0", profile_id=None, prompt=None, suffix=None): | |
| row = dict(base) | |
| row.update(base_profile_id=base["profile_id"], world=world, condition=condition, | |
| profile_id=profile_id or base["profile_id"], baseline_id=base["id"]) | |
| row["id"] = (base["id"] + suffix) if suffix else base["id"].removesuffix("__natural") + "__" + condition | |
| if world != "W0": | |
| row["id"] += "__" + world | |
| if prompt is not None: | |
| row["prompt"] = prompt | |
| return row | |
| def main(): | |
| source = Path("data/main_v1") | |
| destination = Path("data/diagnostics_v1") | |
| design = json.loads((source / "design.json").read_text(encoding="utf-8")) | |
| profiles = {profile["id"]: profile for profile in read_jsonl(source / "profiles.jsonl")} | |
| references = {row["profile_id"]: row for row in read_jsonl(source / "oracle.jsonl")} | |
| baseline = {(row["profile_id"], row["B"], row["model"], row["seed"]): row | |
| for row in read_jsonl(source / "requests.jsonl")} | |
| anchors = [reference_anchors(references[key], design["buffers"]) for key in PROFILE_IDS] | |
| diagnostic_profiles = [profiles[key] for key in PROFILE_IDS] | |
| diagnostic_references = [references[key] for key in PROFILE_IDS] | |
| worlds, prompts, modeoff, games = [], [], [], [] | |
| for selection in anchors: | |
| key, profile = selection["profile_id"], profiles[selection["profile_id"]] | |
| for world in ("W1", "W2"): | |
| variant = world_profile(profile, world) | |
| diagnostic_profiles.append(variant) | |
| diagnostic_references.append({"profile_id": variant["id"], "base_profile_id": key, | |
| "world": world, **oracle(variant)}) | |
| for buffer, seed in product(selection["world_buffers"], design["seeds"]): | |
| base = baseline[(key, buffer, "Qwen/Qwen3.5-4B", seed)] | |
| worlds.append(request_from(base, world=world, profile_id=variant["id"], | |
| prompt=core_prompt(variant, buffer))) | |
| for buffer, model, seed in product(selection["feasible_buffers"], design["models"], design["seeds"]): | |
| base = baseline[(key, buffer, model, seed)] | |
| structured = base["prompt"].replace(profile["prose_card"], | |
| json.dumps(public_facts(profile), ensure_ascii=False, indent=2), 1) | |
| prompts.append(request_from(base, condition="structured", prompt=structured)) | |
| prompts.append(request_from(base, condition="natural_state", prompt=base["prompt"] + "\n\n" + STATE_NOTE)) | |
| games.append(request_from(base, condition="domain_game", prompt=game_prompt(profile, buffer))) | |
| if model == "Qwen/Qwen3.5-4B": | |
| row = request_from(base, suffix="__modeoff") | |
| row["thinking_mode"] = "off" | |
| modeoff.append(row) | |
| all_requests = worlds + prompts + modeoff + games | |
| write_jsonl(destination / "profiles.jsonl", diagnostic_profiles) | |
| write_jsonl(destination / "oracle.jsonl", diagnostic_references) | |
| write_jsonl(destination / "anchors.jsonl", anchors) | |
| write_jsonl(destination / "requests_worlds.jsonl", worlds) | |
| write_jsonl(destination / "requests_prompts.jsonl", prompts) | |
| write_jsonl(destination / "requests_4b_off.jsonl", modeoff) | |
| write_jsonl(destination / "requests_domain_game.jsonl", games) | |
| write_jsonl(destination / "requests_native.jsonl", worlds + prompts + games) | |
| write_jsonl(destination / "requests.jsonl", all_requests) | |
| config = { | |
| "version": "diagnostics_v1", "baseline": "data/main_v1/requests.jsonl; reuse main W0 outputs", | |
| "profile_ids": PROFILE_IDS, "anchors": anchors, "seeds": design["seeds"], | |
| "anchor_selection": "pure frozen main-grid and reference thresholds; deduplicate without replacement", | |
| "output_max_tokens": 32768, "context_length": 131072, | |
| "counts": {"worlds": len(worlds), "prompts": len(prompts), "4b_off": len(modeoff), | |
| "domain_game": len(games), "total": len(all_requests)}, | |
| "native_counts_by_model": dict(Counter(row["model"] for row in worlds + prompts + games)), | |
| "W1": "Only same-amount G_reimburse receipt offset170 to40; neutral actual-receipt wording", | |
| "W2": "G_advance depends directly on O with lag7; D1/D2 become optional free no-effect items on any horizon day", | |
| "natural_state_exact_note": STATE_NOTE, | |
| "4b_off": "Same W0 natural prompt, explicit thinking off and official nonthinking sampler; configuration diagnostic", | |
| "domain_game": "Exploratory fixed32 after dev3 over-risk refusal observation; W0 rules and scoring unchanged", | |
| "inference_modes": {"worlds": "4B native on", "prompts": "both native", "4b_off": "4B off", | |
| "domain_game": "both native"}, | |
| "all_generation_and_scoring_location": "Molab RTX PRO 6000", | |
| } | |
| (destination / "design.json").write_text(json.dumps(config, ensure_ascii=False, indent=2), encoding="utf-8") | |
| (destination / "domain_game_mapping.json").write_text( | |
| json.dumps(GAME_MAPPING, ensure_ascii=False, indent=2), encoding="utf-8") | |
| (destination / "change_note.txt").write_text( | |
| "The four profiles and all anchor-selection rules were fixed before main model results. Each pair reuses the " | |
| "corresponding main W0 natural response by profile/B/seed/model. W1 changes receipt time and its necessary " | |
| "neutral wording; W2 removes proof obligations, including the cancelled dates and inter-item dependencies. " | |
| "D1/D2 remain publicly optional, free, no-effect actions with ordinary format and horizon checks, rather than " | |
| "a hidden deleted-action exception. No other future money, timing, hold, exclusion or refund changes. " | |
| "Structured displays the same canonical public facts, including initial O0, without oracle routes or answers. " | |
| "Natural_state appends only the saved exact request to consider resource balances. The 4B off control uses " | |
| "the identical main natural prompt and changes thinking plus its recommended sampler together; it cannot " | |
| "identify a pure thinking-mode effect. Domain_game is the one fixed exploratory addition prompted by an " | |
| "independent reading of dev3 refusals, not by selecting main failures. Its complete narrative is authored as " | |
| "a closed resource game, preserving all numerical facts, IDs, dependencies, choices, receipt offsets, stock " | |
| "holds, refund semantics and output schema. It is scored directly against unchanged academic W0 profiles " | |
| "and references. Domain vocabulary, genre, wording and text length change together, so this contrast cannot " | |
| "identify safety training as a cause. No diagnostic crosses world, prompt, off or game factors, and none is " | |
| "pooled into the main912 native academic results. All outputs, including refusals and parse failures, remain.\n", | |
| encoding="utf-8") | |
| print(json.dumps(config, ensure_ascii=False), flush=True) | |
| if __name__ == "__main__": | |
| main() | |