Skip to main content
ClaudeWave
Skill570 repo starsupdated 2mo ago

light-experiment-coding

>-

Install in Claude Code
Copy
git clone --depth 1 https://github.com/Light0305/Light-skills /tmp/light-experiment-coding && cp -r /tmp/light-experiment-coding/skills/light-experiment-coding ~/.claude/skills/light-experiment-coding
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# 实验编码(stage 6)

任务不是“写出能跑的 notebook”,而是把上游冻结计划逐行实现成**可证伪、可复跑、可审计**的实验。优先级:

1. 不改研究问题;
2. 不让评估信息进入训练;
3. 能用固定环境与 seed 真复跑;
4. 保留足够 raw evidence,让 result-analysis 自己重算;
5. 代码整洁和速度服从以上约束。

先完整阅读 [`references/experiment-coding-resource-map.md`](references/experiment-coding-resource-map.md)。工具机制见
[`references/tools.md`](references/tools.md),TDD/调试红旗见
[`references/tdd_redflags.md`](references/tdd_redflags.md) 与
[`references/debug_protocol.md`](references/debug_protocol.md)。

## 入口:冻结输入

开始写码前读取并 hash:

- question / estimand;
- experiment matrix 每一行和 fair-comparison 常量;
- pre-registration 及 provenance;
- failure-tree report:每条 hypothesis 的 success/failure/inconclusive 分支、guardrail/counter-metric、kill criterion 与 amendment policy;
- data fixed revision、raw/curated SHA256、lineage、split ID、`split_leakage` evidence;
- result-analysis 对 raw run、predictions、metrics、failures、provenance 的消费契约;
- 当前 git commit 与 dirty state。

primary outcome、comparison family、exclusion、stopping 已冻结。若实现证明计划不可行,带最小复现和影响返回
research-plan,停下让人决策;不得改 config 默认值静默漂移。

## 实现顺序

### 1. 建立最小可运行项目

优先复制 [`assets/project-scaffold/`](assets/project-scaffold/):

- `uv.lock` + `pyproject.toml`:`uv sync --locked --extra dev`;
- `configs/experiment.schema.json`:每个 matrix row 的机读配置;
- `experiment_contracts.py`:data/model/metric/preprocessing 最小接口;
- `reproducibility.py`:运行期 seed helper;
- CI/pre-commit/debug 资产。

遵循现有仓库框架和配置格式;不要为一个实验引入付费 IDE、云追踪或私有 key。MLflow/DVC 可选,普通本地文件必须能完成
核心闭环。不可用资源明确写 `UNAVAILABLE:原因`,不假装通过。

### 2. 测试先行

在实现 preprocessing/train/eval 前:

1. 写 gold test,验证人工可算的小答案;
2. 写 property test(Hypothesis),验证范围、有限性、对称/单调等不变量;
3. 写 metamorphic test,验证置换/等价变换后的输出关系;
4. 写 train-only-fit 测试,记录 transformer 只收到训练折;
5. 亲眼看新测试因缺实现或真实 bug 失败,再写最小实现使其通过。

浮点断言用 `pytest.approx` / `assert_allclose(rtol, atol)`。先声明 device、dtype、mixed precision 和容差;NaN/Inf
默认 fail。不要测“随机训练一定达到某个漂亮数”,测确定性边界和可重算事实。

### 3. 防泄漏实现

- holdout:先 split,再仅用 train `fit/fit_transform`,test 只 `transform`;
- CV/调参:预处理器与模型放进 sklearn `Pipeline`,每折只 fit training fold;
- 患者/用户/牧场等实体用 group-aware split,不得跨 train/test;
- 目标编码、特征选择、PCA、imputation 同样只在训练折 fit;
- 数据件复核直接复用 data-engineering `split_leakage`,不重造。

`review_gate` 只识别静态形态,会漏/误报;领域语义仍要人工核对。指标异常好,先查 leakage。

### 4. 控制随机性与数值边界

分开两个目的:

- `fixed_repro`:固定一个 seed,在同代码/data/config/environment 下做两次独立运行;
- `randomness_estimation`:按预注册 seed 列表做多次运行,估计算法随机性。

多 seeds 不是患者/实体样本量,绝不拿 seed 数替代功效分析 n。

按实际使用覆盖 `PYTHONHASHSEED`(当前进程须启动前设)、`random`、NumPy、框架 RNG、CUDA、cuDNN、
deterministic algorithms、DataLoader generator/worker。记录 device/dtype/AMP、线程数、worker 数、排序键和已知
非确定算子。换 seed 应可变但可追溯;同 seed 一致也只支持同环境契约,不外推跨 release/platform/hardware bitwise 保证。

### 5. 每个 run 保留 raw bundle

从 [`templates/run_manifest.template.json`](templates/run_manifest.template.json) 生成
`light.run_manifest.v3`;说明见 [`templates/run_manifest.md`](templates/run_manifest.md)。
`termination` 只说明进程为何停止,`completion` 才记录矩阵行 oracle 是否真的通过;
timeout / max iterations / cancel 一律不得冒充完成。

每个 matrix row × config × seed × attempt 独立目录,至少保存:

- config schema 校验后的快照;
- code commit/dirty/diff 与代码文件 hash;
- data/input SHA256、source revision、split ID;
- environment(Python/包/OS/CPU/GPU/CUDA/线程);
- argv 数组、stdout、stderr、exit code;
- 每折/每实体 raw metrics、patient/entity-level predictions;
- test evidence;
- failed run 的 failure artifact。

失败 run 不删除,不覆盖成成功。禁止只交 summary CSV;result-analysis 必须能从 raw evidence 重算。

## 门控与 checkpoint

按此顺序真跑并记录 exit code:

```bash
python scripts/experiment_execution_contract.py --spec experiment_execution_contract.json \
  --report execution_contract_findings.json --json-out execution_contract_report.json
python scripts/review_gate.py src/ --json
python scripts/seed_audit.py src/train.py src/reproducibility.py
python scripts/repro_gate.py --spec repro_spec.json --report repro_findings.json
python scripts/run_artifact_check.py --manifest runs/EXP-01/run-a/manifest.json
python scripts/run_artifact_check.py --compare \
  runs/EXP-01/run-a/manifest.json runs/EXP-01/run-b/manifest.json
python ../light-orchestrator/scripts/run_checkpoint.py \
  --file .light/passport.yaml --stage 6 --findings repro_findings.json --write --ts <ISO-8601>
```

`experiment_execution_contract.py` 消费 `light.experiment_execution_contract.v1`(模板见 [`templates/experiment-execution-contract.example.json`](templates/experiment-execution-contract.example.json),故意 fail-closed):核 `as_of`、frozen scope/evaluator/budget、failure-tree handoff、matrix/DAG、run status/termination/failure class、partial checkpoint/resume command、环境与 cache provenance、repro level 分层、远程/付费执行授权。**timeout/OOM/preempted/max-iterations 不得写 completed**;`frozen_at` 与远程授权 `approved_at` 不得来自未来;`decision=NOT_READY/UNKNOWN` 本身阻断推进;run 必须绑定冻结 `matrix_rows` 中的 row,且每个 row 必须绑定 `failure_tree_refs`(hypothesis_ids、branch_action_ids、适用的 guardrail_ids);新增实验行要先回 research-plan 修订;completed run 若上游要求 guardrail,`completion` 必须留下 `guardrail_evidence_artifacts`,否则不得交 result-analysis;实际 walltime/cost/compute_units 与远程预计成本不得静默超过冻结预算,超限必须有预算覆盖授权;`PARTIAL/RESUMABLE` 必须有 checkpoint SHA 和 resume command;请求 `CLEAN_ENV_RERUN/CROSS_PLATFORM/INDEPENDENT_REIMPLEMENTATION` 必须有对应证据;远程/付费/HPC 运行在 `user_authorization=APPROVED` 前不得 `RUN_READY`。

stage 6 的 canonical critical 只有:

- `leakage`;
- `reproducible`。

float/security 在研究 checkpoint 按 spec 为 warn;`review_gate` 可作为独立交付阻断门,不得借此扩大 checkpoint critical 面。
stage-6 门失败就在本阶段修,**不伪造 `ROUTES[6]` 出边**。

同固定 seed 两次必须是独立 run dir;`run_artifact_check.py` 先核 matrix/config/env/code/input 身份和
`started_at/ended_at` 时间轴(带时区、不倒序、不来自未来),再比较 predictions/raw_metrics hashes。
静态 seed/leakage 门 + 同 seed pair 都通过,仍只是一组有边界的证据。

## 交 result-analysis 与 7→6

交付全部 completed/failed runs、coverage、manifests、predictions、raw metrics、logs、test evidence 和 canonical findings。
不要在 stage 6 替 result-analysis 选择性丢 run 或先写结论。

只有 result-analysis 产出**真实实现 bug 或不可复现 root cause**时,orchestrator 才可:

```bash
python ../light-orchestrator/scripts/reroute.py \
  --findings result_findings.json --stage 7 --passport .light/passport.yaml
```

reroute 只给建议。**落
light-backend-codingSkill

后端代码编写、逻辑强、安全性高、可读性好、版本控制、代码审查。当任务需要写实验代码、模型代码、数据处理代码、可视化代码、后端接口或系统逻辑时使用。要求逻辑清晰、安全、可读、可维护、便于复现/扩展/部署。支持 Git 版本管理、代码审查、注释规范、README、依赖管理、环境配置、运行说明与项目结构整理。

light-citationSkill

Verify scholarly references and claim-citation support for Light stage 10. Use when auditing a manuscript, claim map, bibliography, DOI/arXiv/PMID/ISBN/URL, BibTeX/CSL, citekeys, chimeric or fabricated citations, retraction/correction alerts, or preparing a canonical citation registry for typesetting. Builds provenance-preserving inventories, confirms metadata with independent authoritative sources, distinguishes CONFIRMED/CONFIRMED-MISSING/UNAVAILABLE/UNRESOLVED, records Crossref update direction, and emits the citation gate plus delivery artifacts.

light-competitionSkill

竞赛与项目申报材料辅助。当用户做统计建模、数学建模、互联网+、挑战杯、大创、创新创业、科研训练等项目时使用。辅助写申报书、项目计划书、商业计划书、路演 PPT、答辩稿、项目摘要、技术路线、创新点、可行性分析、市场分析、研究基础、预期成果、经费预算、团队分工。用于非论文投稿场景,可与论文/软著/专利/PPT 联动。

light-consistencySkill

>-

light-data-engineeringSkill

>-

light-figure-drawingSkill

从顶会大牛角度进行专业绘图与组图。当用户需要把规划好的图实际画出来时使用。按情况用 Python(matplotlib/seaborn/plotly/altair)、R(ggplot2)、MATLAB、Visio、Origin、LaTeX/TikZ、Illustrator、PowerPoint 等。审美统一、专业清晰、配色合理、字体规范、线条清楚、高分辨率,适合直接投稿。不仅画图,还从论文表达角度判断怎么排、怎么组、怎么标注、怎么突出重点。

light-figure-planningSkill

根据论文内容规划应该做哪些图、哪些表、插在哪里、各起什么作用。当用户需要论文图表规划时使用。图表不限于统计图,也包括数据集真实效果图、模型输出示例、案例展示、可解释性可视化等。规划框架图、技术路线图、数据集示意图、模型结构图、算法流程图、结果对比/消融/敏感性图、真实效果图、统计表/对比表等,以审稿人标准判断哪些必做、哪些冗余。

light-file-readingSkill

>-