跳到正文
cccskills
免费在 GitHub 公开中文介绍

notebook-for-experiment

创建可复现的性能实验 Jupyter 笔记本,记录实验条件、测量、分析和图表,并保存提交版本、运行命令与代码差异,方便他人在不同机器上重跑。

原文查看原文说明

Create reproducible Jupyter notebooks for performance experiments.

JetBrains/intellij-community星标 20,684(GitHub 20,684 + cccskills 0)
集成工具Docker

实测评分 未实测

查看安装方法

适用场景

  • 记录可重复的性能实验
  • 比较不同配置的测量结果
  • 更新分析单元格并重新运行

中文介绍

功能

此技能用于创建或更新性能实验的 Jupyter 笔记本,将实验步骤、测量数据读取、统计分析、表格和图表整理在一起。笔记本会记录测量所用的提交版本、完整运行命令以及所需代码改动,便于其他工程师在不同机器上重新运行实验。随附的 nb.py 工具可处理笔记本单元格、执行内容并导出 HTML;每次运行所需的依赖由 uv 管理。

适用场景

如果要把性能结果与实验条件和分析方法一起分享,而不是只留在临时日志或个人笔记中,可以使用此技能。它也适合比较不同配置的测量值,或保存实验代码改动。如果实验存在随机性或依赖环境的因素,应在开始前确认其稳定性。

使用示例

  • “请把这个测试的性能测量整理成包含复现步骤和图表的笔记本。”
  • “请更新此笔记本中的分析单元格并重新运行输出。”

注意事项

需要安装 uv,并且必须通过 uv run 调用 nb.py。在 IntelliJ 单体仓库中,也可以使用指南所述的固定版本包装器。要复现实验结果,需记录稳定分支上的提交版本、运行命令和代码差异。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
B部分不足包含执行笔记本和应用补丁,但运行前检查说明有限。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足需要 `uv`,并说明 IntelliJ 单体仓库的包装器。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月28日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(4)

  • SKILL.md17.3 KB
  • reference/log-files.md2.8 KB
  • reference/machine-info.md2.5 KB
  • scripts/nb.py18.6 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

<!-- Generated by community/.ai/render-guides.mjs; edit community/.agents/skills/notebook-for-experiment/SKILL.md -->

Notebook for experiment

Tooling

Installing uv

uv is the recommended tool for running notebooks — it requires no global Jupyter installation, pins exact dependency versions per invocation, and keeps each invocation's environment isolated. There are no conflicts with system Python or existing virtualenvs.

Install on macOS / Linux:

curl -LsSf https://astral.sh/uv/install.sh | sh

Install on Windows (PowerShell):

powershell -c "irm https://astral.sh/uv/install.ps1 | iex"

Inside the IntelliJ monorepo, use the pinned wrapper instead of a system uv. It downloads and caches the right version automatically:

# Full monorepo layout (project root contains community/):
./community/tools/uv.cmd run ...

# Community-only checkout (project root IS community/):
./tools/uv.cmd run ...

Notebook helper tool

${CLAUDE_SKILL_DIR}/scripts/nb.py is a small CLI that covers the most common notebook operations without requiring a running Jupyter server:

# List all cells (index, type, first line)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py list-cells notebook.ipynb

# Print source of cell N (0-based)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py get-cell notebook.ipynb 3

# Replace cell N with content from stdin (use a file path instead of '-' to read from a file)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py set-cell notebook.ipynb 3 -

# Insert a new cell at position N (shifts later cells down); reads from stdin or a file
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py insert-cell notebook.ipynb 6 markdown < description.md
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py insert-cell notebook.ipynb 11 code snippet.py

# Delete cell N
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py delete-cell notebook.ipynb 5

# Collapse all code cells except the config cell (cell 1) so the notebook
# opens with only the editable config visible; use expand-cells to reverse
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py collapse-cells notebook.ipynb
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py expand-cells notebook.ipynb

# Keep a non-standard cell visible by tagging it nb:visible, or with --keep:
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py collapse-cells notebook.ipynb --keep 1 4

# Apply the patch(es) embedded in the last cell to a git repo
# --repo is required when the notebook and repo are on different paths
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py apply-patch notebook.ipynb --repo /path/to/repo

# Apply the patch(es) embedded in a specific cell
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py apply-patch notebook.ipynb 12 --repo /path/to/repo

# Bake the current git diff back into the diff fence of the last cell
# (the inverse of apply-patch — use after iterating on the patch)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py update-patch notebook.ipynb --repo /path/to/repo
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py update-patch notebook.ipynb --repo /path/to/repo --staged

# Execute all cells in place (overwrites outputs)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py execute notebook.ipynb

# Export to HTML (writes alongside the notebook; use -o for a custom directory).
# Cells collapsed via collapse-cells have their source omitted in the HTML output.
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py export-html notebook.ipynb
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py export-html notebook.ipynb -o out/

# Start JupyterLab for interactive editing (opens in browser)
uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py serve notebook.ipynb

Always invoke nb.py via uv run — this ensures a compatible Python is used. nb.py carries inline dependency metadata (PEP 723), so uv installs the required packages (nbconvert, jupyter-client, ipykernel, numpy, pandas, matplotlib, plotly) automatically for commands that need them.

If system uv is not available, use the pinned monorepo wrapper instead:

# Full monorepo layout:
./community/tools/uv.cmd run ${CLAUDE_SKILL_DIR}/scripts/nb.py list-cells notebook.ipynb

# Community-only checkout:
./tools/uv.cmd run ${CLAUDE_SKILL_DIR}/scripts/nb.py list-cells notebook.ipynb

Passing complex arguments on Windows

PowerShell and cmd.exe handle escaping poorly for arguments containing backslashes, spaces, or special characters (e.g. JVM options with UNC paths). Store the value in an environment variable first to sidestep the problem.

Bash:

export WSL_PROJECT='\\wsl.localhost\Ubuntu-24.04\home\yourname\idea'
./tests.cmd --jvm-option "-Dijent.wsl.project.root=$WSL_PROJECT"

PowerShell:

$env:WSL_PROJECT = '\\wsl.localhost\Ubuntu-24.04\home\yourname\idea'
./tests.cmd --jvm-option "-Dijent.wsl.project.root=$env:WSL_PROJECT"

The same technique applies for any argument that would be hard to inline-escape: paths, output directories, or flags that differ per engineer. The Kotlin side can read the value via System.getProperty("...") or System.getenv("...").

Cell visibility

By convention, notebooks should open with all boilerplate code collapsed so the reader only sees the config cell they need to edit. Use collapse-cells after finishing the notebook structure:

uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py collapse-cells notebook.ipynb

This hides all code cells except cell 1 (the standard config cell). To mark a different cell as permanently visible, add the tag nb:visible to its metadata:

# In a one-off update script:
nb["cells"][4]["metadata"].setdefault("tags", []).append("nb:visible")

When any code cell carries nb:visible, the tag takes precedence over --keep.

After collapsing, open the notebook in the browser to verify the layout before committing:

uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py serve notebook.ipynb

Standard cell layout

#TypePurpose
0markdownTitle; what is measured; exact shell command(s) to collect data
1codeConfig — only user-editable variables (e.g. repo_root = Path(r'...'))
2codeMachine info (host, OS, CPU, RAM)
3codeImports + data loading
4..NcodeAnalysis — parse, stats, plots, tables
lastmarkdownFull patch(es) needed to reproduce the data, as fenced diff blocks

Reproducibility

Every notebook must be self-contained enough for a different engineer on a different machine to re-run it and get the same results.

Required elements:

  • Pinned commit: state the exact git hash under which results were collected (in the title cell or a comment in the config cell). The commit must belong to a stable branch — origin/master or a release branch (three-digit major version and maybe a minor version after a dot, e.g. origin/261, origin/261.12345). Feature branches are deleted after merging, so a hash reachable only from a feature branch becomes inaccessible to anyone trying to reproduce the results.
  • Full patch in last cell: embed the exact diff as a fenced block. Bash / macOS / Linux:
    git diff $(git merge-base <stable branch> <hash>) <hash>
    
    PowerShell:
    git diff (git merge-base <stable branch> <hash>) <hash>
    
    If an instrumentation patch was applied separately (not merged), include it too.
  • Exact run command: the title cell must contain the complete command including module and test class FQN.

Test stability

Before writing the notebook, verify the test workload is deterministic and noise-free. Ask the user if uncertain. Red flags:

RiskMitigation
Index caches reused across runspreserveSystemDir = false (IDE Starter default)
Pre-built / shared indexes downloaded.setSharedIndexesDownload(false)
Background telemetry uploads.disableReportingStatisticsToProduction(), .disableFusSendingOnIdeClose()
Test runs on wrong filesystemVerify the actual runtime path (e.g. WSL or Docker path vs Windows host path). For WSL/Docker tests, check that resolvedProjectHome points inside the target environment. A common pitfall: hook APIs that return a new context but the caller discards the return value, silently keeping the old path.
Non-deterministic algorithmsVerify fixed seeds, disabled sampling, etc.
Competing background processesIdentify and disable anything that shares the measured resource.

If a test result depends on any random or session-specific factor, ask the user before proceeding.

Test design

The fewer steps a user needs to collect data, the better. The ideal: apply one patch, run one command, open the notebook.

Aim for a single test invocation. Put all measurements in one test class. If measurements share setup (e.g. opening and indexing a project), run them in sequence inside one test method, or as @Order-annotated methods that always run together as a group.

Use a single patch. Combine instrumentation and test changes into one diff. Two patches double the preparation steps for anyone trying to reproduce the results.

Anti-pattern: a notebook that requires running an indexing test and a rename test as separate invocations (different --module flags, different log files to locate) forces a two-step recipe. Merge the measurements into one test class so a single command generates all data.

Verify that the experiment code compiles before embedding the patch in the notebook. Run ./tests.cmd --module <module> --test <FQN> — Bazel compilation runs as part of the test launch even if the test fails at runtime. Fix any compilation errors before the diff goes into the patch cell.

Machine info cell

See reference/machine-info.md for a stdlib-only implementation that works on Windows, macOS, and Linux.

Finding log files

See reference/log-files.md for patterns covering IDE Starter tests and regular (non-Starter) tests.

Availability guards

Some notebooks measure multiple configurations, and a user may have run only one of them. In those cases the data-loading cell should set a boolean flag and every subsequent analysis cell that depends on that data should check it before running. This lets execute (or "Run All") complete without errors even when only partial data exists.

For two variants the pattern is straightforward:

# In the data-loading cell — set flags for each optional configuration:
try:
    async_log = find_log('my-test-async')
    _async_sizes = parse_sizes(async_log)
except FileNotFoundError as e:
    print(f'Skipping async mode: {e}')
    _async_sizes = []

_async_ok = bool(_async_sizes)

# In each analysis cell that uses async data:
if not _async_ok:
    print('No async data — run the async variant of the test first.')
else:
    # ... analysis code ...

For three or more variants, keep the loading block uniform and collect results into a dict so analysis cells stay readable regardless of how many variants exist:

# In the data-loading cell:
_VARIANTS = ['baseline', 'nagle', 'nodelay']
_data: dict[str, list] = {}

for _variant in _VARIANTS:
    try:
        _log = find_log(f'my-test-{_variant}')
        _data[_variant] = parse_sizes(_log)
        print(f'{_variant}: {len(_data[_variant])} samples')
    except FileNotFoundError as e:
        print(f'Skipping {_variant}: {e}')
        _data[_variant] = []

# In each analysis cell — iterate only over variants that have data:
_available = {k: v for k, v in _data.items() if v}
if not _available:
    print('No data available — run at least one test variant first.')
else:
    for variant, sizes in _available.items():
        # ... per-variant analysis ...
        pass

This scales to any number of variants without duplicating the guard logic.

Never raise or sys.exit() inside an analysis cell — that aborts the entire notebook execution. The find_log function is intentionally different: it raises because it guards a hard prerequisite (the test must have run), while availability guards handle optional configurations.

Updating an existing notebook

To change cell content without running a full Jupyter server:

  1. For a single cell — use nb.py set-cell with - to read from stdin:

    Bash (macOS / Linux / Git Bash):

    uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py set-cell notebook.ipynb 3 - <<'EOF'
    import pandas as pd
    df = pd.read_csv(log_path)
    EOF
    

    PowerShell:

    @"
    import pandas as pd
    df = pd.read_csv(log_path)
    "@ | uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py set-cell notebook.ipynb 3 -
    

    Passing a file path instead of - is also supported when the content is already on disk.

    set-cell preserves the existing cell type — replacing a markdown cell with a .md file leaves it as markdown; replacing a code cell leaves it as code. Outputs are cleared only for code cells (stale outputs from old code would be misleading).

  2. For multi-cell edits — write a temporary Python script that manipulates the JSON directly, run it, then delete the script:

    import json, pathlib
    
    nb_path = pathlib.Path('notebook.ipynb')
    nb = json.loads(nb_path.read_text(encoding='utf-8'))
    
    def set_src(cells, n, text):
        lines = text.splitlines(keepends=True)
        if lines and lines[-1].endswith('\n'):
            lines[-1] = lines[-1][:-1]
        cells[n]['source'] = lines
    
    set_src(nb['cells'], 1, 'repo_root = ...\n')
    set_src(nb['cells'], 3, 'import ...\n')
    
    nb_path.write_text(json.dumps(nb, indent=1, ensure_ascii=False) + '\n', encoding='utf-8')
    
  3. After modifying experiment source files (Kotlin, Java, Rust, etc.) that are part of the patch — run update-patch to bake the updated diff back into the last cell:

    uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py update-patch notebook.ipynb \
        --repo /path/to/repo
    # or, if you have staged the changes instead:
    uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py update-patch notebook.ipynb \
        --repo /path/to/repo --staged
    

    Do this after every iteration on the experiment code so the patch cell always reflects exactly what was applied when the data was collected. Forgetting this step is a common source of stale patches in committed notebooks.

  4. Re-execute to refresh all outputs:

    uv run ${CLAUDE_SKILL_DIR}/scripts/nb.py execute notebook.ipynb
    

The notebook file itself is the artifact to commit; keep any update scripts temporary.

Cell content guidelines

Static text: use Markdown, not print()

A code cell that only calls print("...") or print("""...""") with literal strings should be a Markdown cell instead. Markdown cells render with proper headings, bold, tables, and links; print() output is plain monospace with no formatting.

Do — markdown cell:

## Key finding

The root cause is …

Don't — code cell:

print("""Key finding\n\nThe root cause is …""")

Only use print() for values computed at runtime (log paths, parsed numbers, verdicts that depend on data).

Measurements: add visual plots

Every cell that produces a table of measured values should also (or instead) produce a matplotlib figure. Prefer:

  • Bar charts for comparing values across configurations or time points.
  • Histograms for distributions (e.g. batch-size counts).
  • Pie / stacked-bar charts for proportions (e.g. special-channel vs gRPC bytes).

Use plt.show() so outputs are embedded in the notebook. When data for a configuration is unavailable (guarded by an _ok flag), skip its bars rather than crashing.

Tabular data: use pandas, not manual formatting

When an analysis cell produces a table — comparison results, per-variant stats, ranked lists — use a pandas DataFrame instead of building ASCII tables with print() and string formatting. Jupyter renders DataFrames as HTML automatically; the output is sortable, readable, and copy-paste friendly.

Do — DataFrame output:

import pandas as pd

rows = [
    {"variant": "baseline", "p50_ms": 120, "p99_ms": 340},
    {"variant": "nagle",    "p50_ms": 118, "p99_ms": 310},
    {"variant": "nodelay",  "p50_ms":  95, "p99_ms": 270},
]
df = pd.DataFrame(rows)
display(df)

Don't — manual ASCII table:

print(f"{'variant':<10} {'p50_ms':>8} {'p99_ms':>8}")
for r in rows:
    print(f"{r['variant']:<10} {r['p50_ms']:>8} {r['p99_ms']:>8}")

Use pandas for the full data lifecycle inside notebook cells:

  • Loading: pd.read_csv(log_path) or construct from parsed dicts/lists.
  • Transforming: df.groupby(...).agg(...), df.assign(delta=df.after - df.before).
  • Displaying: display(df) (HTML table) or display(df.describe()) for quick stats.
  • Feeding plots: df.plot.bar(x="variant", y=["p50_ms", "p99_ms"]) integrates directly with matplotlib.

Declare pandas in the imports cell (cell 3) so it is available to all subsequent analysis cells.

Anti-patterns

  • Hardcoded absolute log paths — breaks on every other machine.
  • No commit hash or patch — results cannot be reproduced.
  • Tests that reuse index caches or download shared indexes — results vary between runs.
  • Tests that run on the wrong filesystem silently (WSL/Docker path bugs) — data measures the wrong thing.
  • raise / sys.exit() on missing data — breaks "run all cells".
  • Measuring a workload with an unverified random or session-specific factor without asking the user.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

actions

免费有简介

实现或修改 IntelliJ `AnAction`,并在 `plugin.xml` 中注册。将显示名称和说明写入消息资源文件,按需设置图标,并通过事件协程作用域启动挂起任务,避免同步处理阻塞 IDE。

  • 为 IDE 菜单添加操作
  • 修改操作注册或图标
  • 整理操作名称和说明
JetBrains/intellij-community2.1万2026年10月29日 更新

bazel-test-migration

免费有简介

将 IntelliJ JPS 测试模块迁移到 Bazel,并排查仅在 Bazel 中出现的失败。根据症状检查依赖、插件、测试数据和 runfiles,重新生成并验证目标。

  • 将 JPS 测试模块迁移到 Bazel
  • 排查仅在 Bazel 中失败的测试
  • 检查测试依赖和数据配置
JetBrains/intellij-community2.1万2026年10月29日 更新

code-style

免费有简介

按 IntelliJ 项目规范编写或审查 Kotlin 和 Java 代码,涵盖语言选择、格式、密封类型、线程注解及控制流异常处理。

  • 按 IntelliJ 规范编写 Kotlin
  • 审查 Java 代码
  • 检查异常处理和密封类型分支
JetBrains/intellij-community2.1万2026年10月29日 更新

commits

免费有简介

本指南帮助您按 IntelliJ 项目规则拆分更改并撰写提交信息:有工单时使用编号和变更说明,无工单时使用标签与子系统名,并在需要时说明原因和决定。

  • 按项目格式编写带工单号的提交信息
  • 整理测试或文档提交并选择合适标签
  • 按规则修改已有提交信息
JetBrains/intellij-community2.1万2026年10月29日 更新

使用多个 Python 类型检查器比较代码片段或文件的类型推断和报错判断,并汇总各工具的结论、耗时与诊断信息,可保存为 Markdown 报告。

  • 比较不同检查器的类型推断
  • 确认代码是否会被判为类型错误
  • 查看多个工具的诊断差异
JetBrains/intellij-community2.1万2026年10月29日 更新

整理 Compose Desktop 界面中的状态和副作用,让可组合函数负责绘制,由展示器或协调器处理应用决策。了解状态归属、Effect、可复用组件接口、延迟列表键、动画和性能,适用于单项界面修改。

  • 分离界面绘制与展示器决策
  • 整理界面状态的归属
  • 检查 Effect 键和协程用法
JetBrains/intellij-community2.1万2026年10月29日 更新

查看 JetBrains 的全部技能

报告此技能的问题