flow: 消融到收尾、轮末解封、一轮接一轮与研究结束(任务书 17 第二块)
- ⑬–⑱:listCells 从采纳决定和冻结协议现算(不写记录);explanation 有消融才开 阶段;selectCells 照 CellRuleInput 拼输入(余额当时现算、decisionSeed 版本 2), 写种类 cells 的决定,没选中的格不另写事件;消融实现/核验按第几次编号 (r<轮>-ablationImplementation-1、verification-1、-2……从账本数),重做从上一次 这一格代码接着改,次数用完写 cellNotRunEvent 不跑不扣次;cannotRun 传 null 不核验 不运行不扣次;alsoOff 用 sharedSettings 沿用同设置的第一格;消融运行一个接一个跑, 用途 ablation,登记/扣次/恢复与正向同一入口,恢复时指标缺失策略覆盖为只记缺失 (方法.md 第五部分);settle 拼 SettleInput 调 settleAblation,结算与 chooseBet 的 bet 决定写在同一事务;wrapUp 阶段关闭后,本轮选中的每个候选在同一个事务里解封 作者自评(取最后一版提案的封存)。 - 一轮接一轮:每轮开头用 runBalance 现算余额,余额为 0 不开新轮;走到 export 停下, 原因"导出还没写"。去掉 roundsNext 里 step.id !== "listCells" 的临时写法。 - 消融中发现由 materials 的 Board.baselineOf 从结算输出读出,flow 不另写采纳记录 (已核实 materials 已实现)。 - 测试 +14:下一步分支 8 条(含收尾关闭后才解封、余额 0 走到导出停、关掉消融时 解释照方法停下)、消融步骤 6 条(选格输入逐字段手拼对账、结算四种结局、同设置 沿用、解封取最后一版封存);npm run check 通过,npm test 472 条通过。 - 全新上下文审阅一轮(只看消融重做循环、登记扣次恢复、选格/结算/押的因子输入、 解封时机、下一轮与结束条件):没有会污染账本的问题;采纳一条小修(删掉未用的 导入),其余笔记照列不改。 flow 1302 → 1662 行(上限 3500),materials 未动(1930 行)。
This commit is contained in:
@@ -266,7 +266,9 @@ function roundOne(last: "proposal" | "dedupe" | "firstPrediction" | "critique" |
|
||||
]),
|
||||
response: () => stage(book, "r1-response", "response", [["researcher-1", "response", "r1-c1", null], ["researcher-2", "unification", "r1-c2", null]]),
|
||||
freezeProtocol: () => {
|
||||
for (const candidate of C) book.add("protocol", { candidate, protocol: { round: 1, baseline: "base", proposals: [] } });
|
||||
// r1-c1 一个因子(采纳它不做消融),r1-c2 两个因子(采纳它走 ⑬–⑰)。
|
||||
book.add("protocol", { candidate: "r1-c1", protocol: { round: 1, baseline: "base", proposals: [], factors: [{}] } });
|
||||
book.add("protocol", { candidate: "r1-c2", protocol: { round: 1, baseline: "base", proposals: [], factors: [{}, {}] } });
|
||||
},
|
||||
secondPrediction: () => stage(book, "r1-secondPrediction", "secondPrediction", R.flatMap((a) => C.map((c) => [a, "secondPrediction", c, null] as [string, SubmissionKind, string, null]))),
|
||||
selectBatch: () => book.add("decision", { decision: "batch", round: 1, rule: "bestExpected", ruleVersion: 1, params: null, seed: "s", input: null, output: { chosen: ["r1-c1"] } }),
|
||||
@@ -494,12 +496,190 @@ test("正向串行:上次未启动起新编号;已登记未结束必须先
|
||||
book.add("decision", { decision: "adopt", round: 1, rule: "adopt", ruleVersion: 1, params: null, seed: null, input: null, output: { adopted: null } });
|
||||
const after = new Board(book.records);
|
||||
assert.ok(after.runs().filter((r) => r.plan.purpose === "forward").every((r) => after.runPublic(r)));
|
||||
assert.deepEqual(nextStep(book.records), { do: "halt", reason: "消融还没写(任务书 17)", objects: [] });
|
||||
// 没有采纳:不开解释阶段,直接开收尾(方法.md 4.3 ⑫)。
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-wrapUp", stage: "wrapUp", round: 1, roster: R });
|
||||
});
|
||||
|
||||
test("采纳只有一个因子的候选也统一在 listCells 停下,不擅自开收尾", () => {
|
||||
test("采纳只有一个因子的候选:不做消融,直接开收尾(方法.md 4.3 ⑫)", () => {
|
||||
const book = firstVerification(batchTwo(1), true, true);
|
||||
for (const c of C) recordForward(book, c, 1, "valid");
|
||||
book.add("decision", { decision: "adopt", round: 1, rule: "adopt", ruleVersion: 1, params: null, seed: null, input: null, output: { adopted: C[0]! } });
|
||||
assert.deepEqual(nextStep(book.records), { do: "halt", reason: "消融还没写(任务书 17)", objects: [] });
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-wrapUp", stage: "wrapUp", round: 1, roster: R });
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ⑬–⑱:消融到收尾、轮末解封、下一轮和研究结束(任务书 17 第 2.2、2.3 节)。预期动作手写,不调模型、Jev 或 Docker。
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const ADOPTED = "r1-c2"; // 两个因子:p1、p2
|
||||
const CELL1 = "r1-c2-p1";
|
||||
const CELL2 = "r1-c2-p2";
|
||||
|
||||
/** 采纳了两个因子的 r1-c2。 */
|
||||
function adoptedBook(): Book {
|
||||
const book = firstVerification(batchTwo(1), true, true);
|
||||
for (const c of C) recordForward(book, c, 1, "valid");
|
||||
return book.add("decision", { decision: "adopt", round: 1, rule: "adopt", ruleVersion: 1, params: null, seed: null, input: null, output: { adopted: ADOPTED } });
|
||||
}
|
||||
|
||||
/** 解释阶段:开、三人各交一份、关。 */
|
||||
function explained(book: Book): Book {
|
||||
return stage(book, "r1-explanation", "explanation", R.map((a) => [a, "explanation", null, null]));
|
||||
}
|
||||
|
||||
/** 选格决定。 */
|
||||
function cellsChosen(book: Book, chosen: string[]): Book {
|
||||
return book.add("decision", { decision: "cells", round: 1, rule: "valueMinusCost", ruleVersion: 1, params: null, seed: "s2", input: null, output: { chosen } });
|
||||
}
|
||||
|
||||
/** 一次消融实现阶段:subs 是 [格, cannotRun, alsoOff]。 */
|
||||
function implStage(book: Book, n: number, subs: Array<[string, string | null, string[]?]>): Book {
|
||||
const stageId = `r1-ablationImplementation-${n}`;
|
||||
book.open(stageId, "ablationImplementation", 1, subs.map(([cell]) => `experimenter-${cell}`));
|
||||
for (const [cell, cannotRun, alsoOff] of subs) {
|
||||
book.add("submission", { stageId, author: `experimenter-${cell}`, kind: "ablationImplementation", target: cell, item: null, version: 1, content: { alsoOff: alsoOff ?? [], cannotRun, concerns: "无" }, jev: null });
|
||||
}
|
||||
return book.add("stageClose", { stageId });
|
||||
}
|
||||
|
||||
/** 一次消融核验阶段:subs 是 [格, [因子, 关没关]]。 */
|
||||
function verStage(book: Book, n: number, subs: Array<[string, Array<[string, boolean]>]>): Book {
|
||||
const stageId = `r1-ablationVerification-${n}`;
|
||||
book.open(stageId, "ablationVerification", 1, subs.map(([cell]) => `verifier-${cell}`));
|
||||
for (const [cell, offs] of subs) {
|
||||
book.add("submission", { stageId, author: `verifier-${cell}`, kind: "ablationVerification", target: cell, item: null, version: 1, content: { factors: offs.map(([factor, off]) => ({ factor, off, where: "initial.py:1" })) }, jev: null });
|
||||
}
|
||||
return book.add("stageClose", { stageId });
|
||||
}
|
||||
|
||||
/** 一次消融运行:没启动,或启动了、判分算数。 */
|
||||
function recordAblation(book: Book, cell: string, n: number, ending: "valid" | "notStarted"): Book {
|
||||
const run = `r1-ablation-${cell}-${n}`;
|
||||
book.add("runPlanned", { run, purpose: "ablation", round: 1, object: cell, definition });
|
||||
if (ending === "notStarted") return book.add("runResult", { run, process: { ending, reason: "Docker 未启动" }, judged: null });
|
||||
book.add("runStarted", { run });
|
||||
return book.add("runResult", { run, process: exited, judged: judged(1.2, "main") });
|
||||
}
|
||||
|
||||
test("采纳多因子改法:先开解释阶段,每人一个任务、没有对象;关闭后选格", () => {
|
||||
const book = adoptedBook();
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-explanation", stage: "explanation", round: 1, roster: R });
|
||||
book.open("r1-explanation", "explanation", 1, R);
|
||||
assert.deepEqual(nextStep(book.records), { do: "dispatch", stageId: "r1-explanation", tasks: R.map((actor) => ({ actor, kind: "explanation", object: null })) });
|
||||
for (const a of R) book.sub("r1-explanation", a, "explanation", null, null);
|
||||
assert.deepEqual(nextStep(book.records), { do: "closeStage", stageId: "r1-explanation" });
|
||||
book.add("stageClose", { stageId: "r1-explanation" });
|
||||
assert.deepEqual(nextStep(book.records), { do: "selectCells", round: 1 });
|
||||
});
|
||||
|
||||
test("选格做完:每格固定一位实验员;交了跑不起来的格不核验、不运行,没启动的下次起新编号", () => {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-ablationImplementation-1", stage: "ablationImplementation", round: 1, roster: [`experimenter-${CELL1}`, `experimenter-${CELL2}`] });
|
||||
implStage(book, 1, [[CELL1, null], [CELL2, "离了 p2 跑不起来"]]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-ablationVerification-1", stage: "ablationVerification", round: 1, roster: [`verifier-${CELL1}`] });
|
||||
verStage(book, 1, [[CELL1, [["p1", true], ["p2", false]]]]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "ablationRun", round: 1, cell: CELL1, run: `r1-ablation-${CELL1}-1` });
|
||||
recordAblation(book, CELL1, 1, "notStarted");
|
||||
assert.deepEqual(nextStep(book.records), { do: "ablationRun", round: 1, cell: CELL1, run: `r1-ablation-${CELL1}-2` });
|
||||
recordAblation(book, CELL1, 2, "valid");
|
||||
assert.deepEqual(nextStep(book.records), { do: "settle", round: 1 });
|
||||
});
|
||||
|
||||
test("核验不通过:退回原实验员重做,只重验重做的格;次数用完写不跑事件,不登记运行", () => {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
implStage(book, 1, [[CELL1, null], [CELL2, null]]);
|
||||
verStage(book, 1, [[CELL1, [["p1", false], ["p2", false]]], [CELL2, [["p1", false], ["p2", true]]]]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-ablationImplementation-2", stage: "ablationImplementation", round: 1, roster: [`experimenter-${CELL1}`] });
|
||||
implStage(book, 2, [[CELL1, null]]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-ablationVerification-2", stage: "ablationVerification", round: 1, roster: [`verifier-${CELL1}`] });
|
||||
verStage(book, 2, [[CELL1, [["p1", false], ["p2", false]]]]);
|
||||
const next = nextStep(book.records);
|
||||
assert.equal(next.do, "cellNotRun");
|
||||
if (next.do !== "cellNotRun") throw new Error("应写不跑事件");
|
||||
assert.equal(next.cell, CELL1);
|
||||
assert.match(next.reason, /第 2 次核验仍不通过,修复次数上限 1 已用完/);
|
||||
book.add("event", { event: "cellNotRun", reason: next.reason, objects: [next.cell] });
|
||||
// p1 不跑不扣次;只跑 p2。
|
||||
assert.deepEqual(nextStep(book.records), { do: "ablationRun", round: 1, cell: CELL2, run: `r1-ablation-${CELL2}-1` });
|
||||
});
|
||||
|
||||
test("几格实际关掉的因子完全相同:沿用第一格,不重复跑", () => {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
implStage(book, 1, [[CELL1, null, ["p2"]], [CELL2, null, ["p1"]]]);
|
||||
verStage(book, 1, [[CELL1, [["p1", true], ["p2", true]]], [CELL2, [["p1", true], ["p2", true]]]]);
|
||||
// 两格实际关的都是 {p1, p2}:只跑第一格。
|
||||
assert.deepEqual(nextStep(book.records), { do: "ablationRun", round: 1, cell: CELL1, run: `r1-ablation-${CELL1}-1` });
|
||||
recordAblation(book, CELL1, 1, "valid");
|
||||
assert.deepEqual(nextStep(book.records), { do: "settle", round: 1 });
|
||||
});
|
||||
|
||||
test("全部交跑不起来:不核验、不运行,直接结算", () => {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
implStage(book, 1, [[CELL1, "跑不起来一"], [CELL2, "跑不起来二"]]);
|
||||
assert.deepEqual(nextStep(book.records), { do: "settle", round: 1 });
|
||||
});
|
||||
|
||||
/** 结算和押的因子写完、收尾关闭、解封也写完的账本(余额还有 8 次)。 */
|
||||
function afterWrapUp(): Book {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
implStage(book, 1, [[CELL1, null], [CELL2, null]]);
|
||||
verStage(book, 1, [[CELL1, [["p1", true], ["p2", false]]], [CELL2, [["p1", false], ["p2", true]]]]);
|
||||
recordAblation(book, CELL1, 1, "valid");
|
||||
recordAblation(book, CELL2, 1, "valid");
|
||||
book.add("settlement", { round: 1, result: { candidate: ADOPTED, input: null, output: null } });
|
||||
book.add("decision", { decision: "bet", round: 1, rule: "chooseBet", ruleVersion: 1, params: null, seed: null, input: null, output: null });
|
||||
return stage(book, "r1-wrapUp", "wrapUp", R.map((a) => [a, "wrapUp", null, null]));
|
||||
}
|
||||
|
||||
test("结算和押的因子写完:开收尾;收尾关闭后解封本轮选中的全部候选,然后开下一轮", () => {
|
||||
const book = cellsChosen(explained(adoptedBook()), ["p1", "p2"]);
|
||||
implStage(book, 1, [[CELL1, null], [CELL2, null]]);
|
||||
verStage(book, 1, [[CELL1, [["p1", true], ["p2", false]]], [CELL2, [["p1", false], ["p2", true]]]]);
|
||||
recordAblation(book, CELL1, 1, "valid");
|
||||
assert.deepEqual(nextStep(book.records), { do: "ablationRun", round: 1, cell: CELL2, run: `r1-ablation-${CELL2}-1` });
|
||||
recordAblation(book, CELL2, 1, "valid");
|
||||
assert.deepEqual(nextStep(book.records), { do: "settle", round: 1 });
|
||||
book.add("settlement", { round: 1, result: { candidate: ADOPTED, input: null, output: null } });
|
||||
book.add("decision", { decision: "bet", round: 1, rule: "chooseBet", ruleVersion: 1, params: null, seed: null, input: null, output: null });
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r1-wrapUp", stage: "wrapUp", round: 1, roster: R });
|
||||
stage(book, "r1-wrapUp", "wrapUp", R.map((a) => [a, "wrapUp", null, null]));
|
||||
// 收尾关闭后:解封本轮选批选中的 r1-c1、r1-c2;还有一个没解封就继续。
|
||||
assert.deepEqual(nextStep(book.records), { do: "unsealChosen", round: 1 });
|
||||
book.add("unseal", { candidate: "r1-c1", seals: [1] });
|
||||
assert.deepEqual(nextStep(book.records), { do: "unsealChosen", round: 1 });
|
||||
book.add("unseal", { candidate: "r1-c2", seals: [2] });
|
||||
// 余额还有(已扣 5 次):开第 2 轮。
|
||||
assert.deepEqual(nextStep(book.records), { do: "openStage", stageId: "r2-proposal", stage: "proposal", round: 2, roster: R });
|
||||
});
|
||||
|
||||
test("余额为 0:不开下一轮,走到导出停下,原因写明", () => {
|
||||
const book = afterWrapUp();
|
||||
book.add("unseal", { candidate: "r1-c1", seals: [1] });
|
||||
book.add("unseal", { candidate: "r1-c2", seals: [2] });
|
||||
// 已扣 5 次(基线 1、正向 2、消融 2):把冻结配置的运行次数改成 5,余额为 0。
|
||||
const record = book.records.find((r) => r.kind === "config")!;
|
||||
const study = record.content as unknown as StudyRecord;
|
||||
study.config = { ...fullConfig(), runs: 5 } as unknown as Json;
|
||||
assert.deepEqual(nextStep(book.records), { do: "halt", reason: "导出还没写", objects: [] });
|
||||
});
|
||||
|
||||
test("配置关掉消融、又采纳了多因子改法:先记按配置跳过,再在解释停下", () => {
|
||||
const book = firstVerification(batchTwo(1), true, true);
|
||||
for (const c of C) recordForward(book, c, 1, "valid");
|
||||
book.add("decision", { decision: "adopt", round: 1, rule: "adopt", ruleVersion: 1, params: null, seed: null, input: null, output: { adopted: ADOPTED } });
|
||||
// 冻结的配置改为关掉消融:配置和步骤清单一起换(步骤清单在研究开始时冻结)。
|
||||
const config = fullConfig();
|
||||
if (config.flow.preset !== "full") throw new Error("测试配置应是完整流程");
|
||||
// 配置关掉消融时不写 cellRule(它只有开着消融才用得到)。
|
||||
config.flow.ablation = { enabled: false };
|
||||
const record = book.records.find((r) => r.kind === "config")!;
|
||||
const study = record.content as unknown as StudyRecord;
|
||||
study.config = config as unknown as Json;
|
||||
study.steps = stepList(config) as unknown as Json;
|
||||
const reason = "配置关掉了消融";
|
||||
assert.deepEqual(nextStep(book.records), { do: "skip", step: "r1-listCells", reason });
|
||||
book.add("event", { event: "skippedByConfig", reason, objects: ["r1-listCells"] });
|
||||
const next = nextStep(book.records);
|
||||
assert.equal(next.do, "halt");
|
||||
assert.match((next as { reason: string }).reason, /不交三个数的解释还没写/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user