快速开始清单
按顺序执行这些步骤。不要跳过任何步骤。
- 完整阅读本 SKILL.md
- 获取参考脚本(步骤 0)
- 创建
earth2studio/models/px/<name>.py,带三重继承 - 创建
test/models/px/test_<name>.py,含模拟测试 - 运行:
uv run pytest test/models/px/test_<name>.py -v- [添加]/更新模型额外、安装文档、API文档和变更日志(步骤1-2、9) - 运行:
make format && make lint
⚠️关键: Python命令首先使用
uv run:
- ✅
uv run pytest .../uv run python ...> - ❌pytest .../python ...(缺乏依赖)**卡住或输出错误:**不要反复重试相同修复。遵循自我改进在继续之前修复本技能。
用途
实现连接第三方ML天气模型到Earth2Studio的模型封装。模型做时间积分前向推进——给定初始状态,它们通过逐步跨越时间(如6增量)来预测未来状态。
工作区
| 上下文 | 位置 |
|---|---|
| 港口体育 | 写入/workspace/output/earth2studio/models/px/... |
港口+--copy-repo |
/workspace/repo完整检出 |
| 本地克隆 | 含pyproject.toml的目录 |
** 尺寸读取evals/targets/** —— 曼哈顿评分者参考。
参考文件
在步骤匹配中补充:
| 文件 | 内容 | 加载于 |
|---|---|---|
references/skeleton-template.py |
带 FILL 注释的完整模型重构 | 步骤 3-6 |
references/method-templates.py |
规范方法实现 | 步骤 4-6 |
references/testing-guide.py |
测试重构与mock模式 | 步骤 7 |
references/validation-guide.md |
对比脚本、公关、代码评审 | 步骤 10-11 |
工作流程步骤
###步骤 0 — 获取相关脚本
若提供了$ARGUMENTS,使用它。否则发问:
请提供参考剧情的URL/路径。
###步骤 1 — 分析与提议依赖
分析:包、架构、I/O形状、时间步长、分辨率、检查点。
提议pyproject.toml组(按字母序号,加入all)。 每个模型必须有可选的依赖额外,即使不需要任何包:```toml
model-name = ["package1>=version", "package2"]
或,当不需要额外包时:
model-name = []
**[确认]** 提供依赖并请用户批准。
###步骤 2 — 添加依赖
编辑`pyproject.toml`:按字母顺序添加模型额外,即使为空,并更新`all`聚合。
###步骤3 — 创建模型文件
**文件:**`earth2studio/models/px/<lowercase>.py`
**必需继承(三者皆需):**```python
class ModelName(torch.nn.Module, AutoModelMixin, PrognosticMixin):
只需导入:```python import numpy as np import torch from earth2studio.models.auto import AutoModelMixin, Package from earth2studio.models.batch import batch_coords, batch_func from earth2studio.models.px.base import PrognosticMixin from earth2studio.models.utils import create_coords_from_lat_lon, handshake_dim from earth2studio.lexicon import E2STUDIO_VOCAB from earth2studio.utils import check_optional_dependencies from loguru import logger
**SPDX 头每个( .py 文件顶部必需):**```python
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES.
# SPDX-License-Identifier: Apache-2.0
规范方法顺序:
1.__init__2.input_coords3.output_coords(@batch_coords)
4.load_default_package5.load_model6.to(任选)
7. 介入方法 8.__call__(@batch_func)9._default_generator10.create_iterator
###步骤4 — 实现坐标
input_coords 规则:
-batch:np.empty(0)-time:np.empty(0)(动态)
-lead_time: 开始np.timedelta64(0, "h")-lat:90 到 -90(北到南);这是公开的 Earth2Studio 规定,即使源模型使用相反顺序
-lon:0到360
- 若检查点/模型核心希望南到北纬度,在核心模型前后内部跳跃张量;不要在
input_coords或output_coords中引反转后的纬度 - 将变量映射到
E2STUDIO_VOCAB(在earth2studio/lexicon/base.py中有282条)
输出坐标: 使用handshake_dim/handshake_coords做输入验证,然后递增lead_time。优先共享坐标检查辅助函数,并在模型执行前从output_coords、__call__在迭代器设置中调用它。
###步骤5 — 实现前向传播
__call__: 使用 @batch_func 装饰,形状 (batch, time, Lead_time, var, lat, lon)。
仓库为模型格式 → 调用模型 → 仓库回。
create_iterator: 必须首先重置联邦政府条件(step 0)。
使用front_hook/rear_hook注入扰动。
###步骤6 — 实际模型加载
load_default_package: 锁定 HuggingFace URL:hf://org/repo@commit
load_model: 使用package.resolve()、map_location="cpu"、eval()模式,用@check_optional_dependencies()装饰。
###步骤 7 — 编写测试
文件:test/models/px/test_<name>.py
必要测试:
| 函数 | 用途 |
|---|---|
test_<model>_call |
单次向前向传播(参数化设备/时间) |
test_<model>_iter |
迭代器产生序列 |
test_<model>_exceptions |
悬浮坐标抛错 |
test_<model>_package |
真实权重(@pytest.mark.package) |
创建匹配接口的PhooModelName哑元用于模拟测试。
运行测试:```bash uv run pytest test/models/px/test_.py -m "not package" -v uv run pytest test/models/px/test_.py::test__package --package -v
不要压缩预算测试。若任意随机输入对真实检查点而言在物理上无效,则在立即加载真实权重并运行前向传播的同时,使用稳定的、模型模拟的合成输入。
###步骤8 — 注册模型(若请求)
- 按字母序号添加到`earth2studio/models/px/__init__.py`- 验证 pyproject.toml 中的依赖
###步骤 9 — 文档
- 按字母序号添加到`docs/modules/models_px.rst`这对每个新的模型都是必需的,使 API 文档包含生成的页面。
- 按字母序号添加到`docs/userguide/about/install.md`(字母序表)用于模型额外,即使额外为空。包含模型特定说明,以及`pip install earth2studio[model-name]`与`uv add earth2studio --extra model-name`消耗指令。
- 在`CHANGELOG.md`的`### Added`下更新。每个对新的火花模型都是必需的。
**格式与lint:**```bash
make format && make lint && make license
###步骤10 - 验证(若请求)
遵循references/validation-guide.md。未提交的vanilla、E2S、与配置性检查脚本对比;不要提交生成的作品或图片。对图使用PR安全的占位创建符,方便用户手动上传图片。
[确认] 用户必须在继续前视力检查图。
###步骤11 - PR(若请求)
遵循references/validation-guide.md并用:
-references/pr-body-template.md-references/pr-comment-template.md
创建PR前,验证pyproject.toml有额外模型、allextra 包含它、安装文档同时包含 pip 与 uv 命令、且docs/modules/models_px.rst与CHANGELOG.md已更新。
不要在 PR 文本中包含机器名、绝对路径、设备清单或上传图片链接。改用图占位符。
示例
简单的身份模型```text
User: Create IdentityModel - returns input unchanged, 6h step, 181x360, vars: t2m, u10m, v10m, msl
Agent: [读取 SKILL.md,创建带三重继承的 identity.py, 创建 test_identity.py,运行 pytest,运行 make format && lint]
###外部模型(盘古)```text
User: Add Pangu-Weather wrapper
GitHub: https://github.com/198808xc/Pangu-Weather
Agent: [读取 SKILL.md,获取 inference.py,创建 pangu.py,
创建 test_pangu.py,运行 pytest]
关键模式
###坐标模板```python @property def input_coords(self) -> CoordSystem: return CoordSystem({ "batch": np.empty(0), "time": np.empty(0), "lead_time": np.array([np.timedelta64(0, "h")]), "variable": np.array(["t2m", "u10m", ...]), # 公开 Earth2Studio 约定是北到南纬度。 "lat": np.linspace(90, -90, 181), "lon": np.linspace(0, 359, 360), })
@batch_coords() def output_coords(self, input_coords: CoordSystem) -> CoordSystem: output = input_coords.copy() output["lead_time"] = input_coords["lead_time"] + np.timedelta64(6, "h") return output
### 迭代器模板```python
def create_iterator(self, x, coords):
yield x, coords # 初始条件(step 0)
while True:
x, coords = self.front_hook(x, coords)
x, coords = self(x, coords)
x, coords = self.rear_hook(x, coords)
yield x, coords
故障排查
| 错误 | 解决方案 |
|---|---|
OptionalDependencyFailure |
uv add --optional <group> <pkg> |
| 坐标握手失败 | 检查handshake_dim索引满足维度位置 |
| 迭代器形状错误 | 使用随机输入积累逻辑 |
ModuleNotFoundError: pytest |
使用uv run pytest纽pytest |
提醒
要:
- 所有Python命令的使用
uv run python- 使用loguru.logger, 方案print()- 继承torch.nn.Module + AutoModelMixin + PrognosticMixin- 在create_iterator中先财政政策 - 在
_default_generator中使用front_hook()/rear_hook()- 每个 .py 文件包含 SPDX 头
不要:
- 创建用于复用的通用基础类
- 提交 API 密钥或对比脚本
- 从
evals/targets/读取




