Exp run

From Chanw-research/claude-code-paper-writing · View interactive version

Exp run is an AI agent skill from the GitHub repository Chanw-research/claude-code-paper-writing. 实验执行全流程:准备代码 → 部署运行 → 监控状态 → 收集结果,支持三种运行模式

How to use this skill

Skill file

/exp-run

执行 wiki/experiments/ 中已规划的实验。

三种运行模式,适应不同场景:

- 默认(deploy):仅 Phase 1-2,部署后立即返回,适合需要数小时/天的实验。

- --collect:仅 Phase 3-4,检查已部署实验是否完成,完成则收集结果(--check 为 alias)。

- --full:完整 Phase 1-4,适合几分钟内即可完成的本地快速实验。

推荐流程:/exp-run <slug> 部署 → /exp-status 监控 → /exp-run <slug> --collect 收集。

Inputs

Outputs

Wiki Interaction

Reads

Writes

Graph edges created

Workflow

前置:确认工作目录为 wiki 项目根(包含 wiki/、raw/、tools/ 的目录)。


Deploy 模式(默认,status == planned)

Phase 1: 准备(Prepare)

  1. 读取实验页面:
  1. 加载实现上下文:
  1. 编写实验代码,统一写入 experiments/code/{slug}/:
  1. 可选 Review LLM code review(--review):

```

mcpllm-reviewchat:

system: "You are a senior ML engineer reviewing experiment code.

Focus on: correctness of the training loop, proper evaluation protocol,

fair baseline comparison, reproducibility (seeds, determinism),

proper metric computation, and common pitfalls (data leakage,

wrong split, gradient accumulation bugs)."

message: |

## Experiment

{experiment title and hypothesis}

## Code

{generated code}

## Expected Behavior

{setup details from wiki page}

Review for correctness and potential issues.

```

根据 Review LLM 反馈修正代码。

  1. Sanity check(小规模验证):

Phase 2: 部署(Deploy)

Local 模式(`--env local` 或默认)
  1. 检查 GPU:nvidia-smi 确认 GPU 可用、显存足够
  2. 启动:

```bash

screen -dmS exp-{slug} bash -c \

"cd $(pwd) && bash experiments/code/{slug}/run.sh 2>&1 | tee logs/exp-{slug}.log"

```

  1. 更新 wiki/experiments/{slug}.md:
  1. 估算运行时长,写入 frontmatter:

根据 setup.hardware(GPU 型号/数量)、setup.model(参数量)、setup.dataset(规模)合理估算:

| 典型场景 | 估算范围 |

|----------|----------|

| 单 GPU + 小数据集(CIFAR / 小 NLP benchmark) | 0.5 – 3h |

| 单 A100 + 中等数据集(ImageNet / GLUE) | 4 – 12h |

| 多 GPU 或大模型 fine-tuning(≥7B) | 8 – 48h |

```bash

python3 tools/research_wiki.py set-meta \

wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"

python3 tools/research_wiki.py set-meta \

wiki/experiments/{slug}.md estimated_hours {N}

```

  1. 追加日志:

```bash

python3 tools/research_wiki.py log wiki/ \

"exp-run | deployed {slug} | env: local | session: exp-{slug} | eta: {N}h"

```

Remote 模式(`--env remote`)

前提:用户已配置 config/server.yaml。

  1. 确认连通:python3 tools/remote.py status
  1. 查找空闲 GPU:python3 tools/remote.py gpu-status
  1. 同步代码:python3 tools/remote.py sync-code
  2. 安装依赖(首次或 requirements 有变化):python3 tools/remote.py setup-env
  3. 启动远程实验:

```bash

python3 tools/remote.py launch \

--name "exp-{slug}" \

--cmd "bash experiments/code/{slug}/run.sh" \

--gpu {gpu_index}

```

  1. 更新 wiki/experiments/{slug}.md frontmatter —— 以下字段已由 /exp-design 写入完整 CLAUDE.md 模板,都是空值:

```bash

# 顶层 scalar 字段 —— 用 set-meta

python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md status running

python3 tools/research_wiki.py set-meta wiki/experiments/{slug}.md run_log "logs/exp-{slug}.log"

```

嵌套 remote: 块无法通过 set-meta 更新(set-meta 只处理顶层 scalar 字段)。直接用 Edit 工具就地替换这五个空的子字段值。文件里已有的 block 形如:

```yaml

remote:

server: ""

gpu: ""

session: ""

started: ""

completed: ""

```

用 5 次 Edit 调用(每个子字段一次)设置 server、gpu、session、started。completed: "" 留空由 Phase 4 填写。如果发现文件里没有 remote: block,说明 /exp-design 没写完整的 CLAUDE.md 模板;停下来报 bug,不要在这里追加 block(追加会让字段顺序偏离 canonical 模板,破坏后续 edit 的匹配)。

  1. 估算运行时长,写入 frontmatter(同 local 模式估算逻辑):

```bash

python3 tools/research_wiki.py set-meta \

wiki/experiments/{slug}.md started "{YYYY-MM-DDTHH:MM}"

python3 tools/research_wiki.py set-meta \

wiki/experiments/{slug}.md estimated_hours {N}

```

  1. 追加日志:

```bash

python3 tools/research_wiki.py log wiki/ \

"exp-run | deployed {slug} | env: remote | server: {host} | gpu: {gpu} | eta: {N}h"

```

输出 DEPLOY_REPORT 到终端:

# Deploy Report: {experiment title}

### Status: DEPLOYED ✅

- Session: exp-{slug}
- Environment: local | remote ({host} GPU {gpu})
- Log file: logs/exp-{slug}.log
- Code: experiments/code/{slug}/
- Estimated: ~{N}h(预计完成于 {YYYY-MM-DD HH:MM})

### Next Steps

1. Monitor progress: `/exp-status`
2. Check this experiment: `/exp-run {slug} --collect`
3. In /research pipeline: progress saved to wiki/outputs/pipeline-progress.md

### Quick Commands

Local: check if still running

screen -ls | grep exp-{slug}

Local: tail log

tail -f logs/exp-{slug}.log


Collect 模式(`--collect` 或 `--check`,status == running)

Phase 3: 监控/检查运行状态(Monitor)

  1. 读取部署信息:从 wiki/experiments/{slug}.md frontmatter 获取环境(local 或 remote)和 session 名。
  1. 检查进程是否还活着:
  1. 若实验仍在运行(alive == true):

```

Experiment {slug}: RUNNING

Progress: step {N} / epoch {E}

Latest metric: {metric} = {value}

Anomalies: {none | NaN detected | ...}

Estimated remaining: ~{N} hours

Run /exp-status to monitor all running experiments.

```

  1. 若实验已完成(alive == false / session gone):

Phase 4: 收集结果(Collect Results)

  1. 拉取远程结果(仅 remote 模式):

```bash

python3 tools/remote.py pull-results \

--remote-path "results/{slug}/" \

--local-path "./results/{slug}/"

python3 tools/remote.py pull-results \

--remote-path "logs/exp-{slug}.log" \

--local-path "./logs/"

```

  1. 检查结果文件存在:results/{slug}/seed_*.json
  1. 解析结果:
  1. 更新实验页面 wiki/experiments/{slug}.md:
  1. 追加日志:

```bash

python3 tools/research_wiki.py log wiki/ \

"exp-run | completed {slug} | outcome: {outcome} | key: {key_result}"

```

  1. 输出 RUN_REPORT 到终端:

```markdown

# Run Report: {experiment title}

## Outcome: {succeeded / failed / inconclusive}

## Results

| Metric | Baseline | Ours (mean±std) | Δ |

|--------|----------|-----------------|---|

| {metric} | {baseline-value} | {mean}±{std} | +{delta} |

## Key Finding

{key_result}

## Next Steps

```


Full 模式(`--full`,status == planned)

依次执行全部 4 个 Phase(Phase 1 → Phase 2 → Phase 3 → Phase 4),中间不返回。

适用场景:本地 CPU/GPU 几分钟内可完成的快速实验(sanity check、toy dataset 验证等)。

Phase 3 中不需要先检查 "是否还在运行",而是等待 screen session 真正结束后再执行 Phase 4:

# 等待 session 结束(轮询)
while screen -ls | grep -q "exp-{slug}"; do
  sleep 30
done
# session 消失,进入 Phase 4

Constraints

Error Handling

Dependencies

Skills(via Skill tool)

Tools(via Bash)

Configuration

MCP Servers

Claude Code Native

Called by

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.