earth2studio-create-diagnostic
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseQuick Start Checklist
快速开始检查清单
Do these steps in order. Do not skip ahead. Before editing, read this
SKILL.md and load the relevant reference files for the model type. After
implementation, run the focused pytest command before saying tests pass. If
tests cannot run, report the exact command and failure instead of claiming
success.
- Read this SKILL.md completely first
- Get the reference script, repo, paper, or model documentation (Step 0)
- Classify the diagnostic as simple, AutoModel, or generative (Step 1)
- Propose dependency extras before editing dependency files (Step 1)
- Create with diagnostic-only APIs
earth2studio/models/dx/<name>.py - Create with mock tests
test/models/dx/test_<name>.py - Run:
uv run pytest test/models/dx/test_<name>.py -m "not package" -v - Add/update model extra, install docs, API docs, and changelog when required
- Run:
make format && make lint && make license
Critical command rule: always use for Python commands:
uv run- Use and
uv run pytest ...uv run python ... - Do not use bare or
pytestin repo workflowspython
If the generated model is wrong, do not keep retrying the same fix. Follow
Self-Improvement, patch this skill or its references, then
continue with the corrected workflow.
请按顺序执行以下步骤,不要跳过。编辑前,请阅读本SKILL.md并加载对应模型类型的相关参考文件。实现完成后,先运行指定的pytest命令,再确认测试是否通过。如果测试无法运行,请报告确切的命令和失败信息,不要声称成功。
- 先完整阅读本SKILL.md
- 获取参考脚本、代码库、论文或模型文档(步骤0)
- 将诊断分类为简单型、AutoModel型或生成型(步骤1)
- 在编辑依赖文件前,提出依赖扩展建议(步骤1)
- 创建文件,仅包含诊断相关API
earth2studio/models/dx/<name>.py - 创建文件,编写模拟测试
test/models/dx/test_<name>.py - 运行命令:
uv run pytest test/models/dx/test_<name>.py -m "not package" -v - 必要时添加/更新模型扩展、安装文档、API文档和变更日志
- 运行命令:
make format && make lint && make license
关键命令规则:所有Python命令都必须使用:
uv run- 使用和
uv run pytest ...uv run python ... - 在代码库工作流中不要使用裸或
pytest命令python
如果生成的模型存在错误,不要重复尝试相同的修复方法。请遵循自我改进部分的指引,修补本技能或其参考文件,然后使用修正后的工作流继续。
Purpose
目的
Implement a diagnostic model wrapper connecting third-party or derived ML
transforms to Earth2Studio. Diagnostic models transform data at a single time
point: input fields in, output fields out, no forecast integration.
实现诊断模型包装器,将第三方或派生的ML转换与Earth2Studio连接。诊断模型在单个时间点转换数据:输入字段进入,输出字段输出,不涉及预测集成。
Prerequisites
前置条件
- Earth2Studio installed via with dev dependencies (
uv)uv sync --all-extras - Python 3.10+ environment
- Reference inference script, repo, paper, or model documentation
- Checkpoint source and license information for packaged models
- 通过安装带有开发依赖的Earth2Studio(
uv)uv sync --all-extras - Python 3.10+环境
- 参考推理脚本、代码库、论文或模型文档
- 打包模型的检查点来源和许可证信息
Limitations
限制
- Handles single-step transformations only
- Does not support time-stepping forecast models; use
earth2studio-create-prognostic - Real package tests can require network access to NGC, HuggingFace, S3, or other registries
- Generative validation can require GPU and fixed seeds for meaningful comparison
- 仅处理单步转换
- 不支持时间步长预测模型;请使用
earth2studio-create-prognostic - 实际包测试可能需要访问NGC、HuggingFace、S3或其他注册表的网络权限
- 生成式验证可能需要GPU和固定随机种子以进行有意义的比较
Diagnostic Model Types
诊断模型类型
| Type | Inheritance | Dependency extra | Example |
|---|---|---|---|
| Simple derived diagnostic | | Usually none | |
| Packaged AutoModel diagnostic | | Required, even if empty | |
| Generative diagnostic | | Required, even if empty | |
| 类型 | 继承关系 | 依赖扩展 | 示例 |
|---|---|---|---|
| 简单派生诊断 | 仅 | 通常无 | |
| 打包的AutoModel诊断 | | 必填,即使为空 | |
| 生成式诊断 | | 必填,即使为空 | |
Workspace
工作区
| Context | Location |
|---|---|
| Harbor eval | Write to |
Harbor + | Full checkout at |
| Local clone | Directory with |
Never read ; those files are grader references only.
evals/targets/| 上下文 | 位置 |
|---|---|
| Harbor评估 | 写入至 |
Harbor + | 完整检出至 |
| 本地克隆 | 包含 |
请勿读取;这些文件仅为 grader 参考文件。
evals/targets/Reference Files
参考文件
Load these files on demand during the matching workflow:
| File | Content | Load at |
|---|---|---|
| Full diagnostic skeletons for simple, AutoModel, and generative wrappers | Steps 3-6 |
| Focused coordinate, loading, forward, and device method snippets | Steps 4-6 |
| Mock, package, exception, sample, and seed test patterns | Step 7 |
| Reference comparison, plots, PR hygiene, and review follow-up | Steps 10-11 |
| PR body template | Step 11 |
| Validation comment template | Step 11 |
在匹配的工作流中按需加载以下文件:
| 文件 | 内容 | 加载时机 |
|---|---|---|
| 简单型、AutoModel型和生成型包装器的完整诊断骨架 | 步骤3-6 |
| 聚焦坐标、加载、前向传播和设备方法的代码片段 | 步骤4-6 |
| 模拟测试、包测试、异常测试、样本测试和种子测试模式 | 步骤7 |
| 参考对比、绘图、PR规范和评审跟进 | 步骤10-11 |
| PR正文模板 | 步骤11 |
| 验证评论模板 | 步骤11 |
Instructions
操作步骤
Step 0 - Get Reference Material
步骤0 - 获取参考资料
If provides a URL or local path, use it. Otherwise ask:
$ARGUMENTSPlease provide a reference inference script, repository, paper, or model documentation.
Capture the reference model's input variables, output variables, tensor shapes,
normalization, grid, checkpoint source, dependency requirements, and license.
如果提供了URL或本地路径,请使用该路径。否则请询问:
$ARGUMENTS请提供参考推理脚本、代码库、论文或模型文档。
记录参考模型的输入变量、输出变量、张量形状、归一化方式、网格、检查点来源、依赖要求和许可证信息。
Step 1 - Analyze Type and Propose Dependencies
步骤1 - 分析类型并提出依赖建议
Classify the requested diagnostic before editing files:
| If the model... | Then use... |
|---|---|
| Computes a derived quantity with no checkpoint | Simple diagnostic |
Loads weights from | AutoModel diagnostic |
| Produces multiple samples, diffusion outputs, VAE samples, or stochastic super-resolution | Generative diagnostic |
Dependency policy:
- Simple derived diagnostics usually do not need a extra.
pyproject.toml - AutoModel and generative diagnostics must have a named optional dependency extra, even if the list is empty.
- Add the extra alphabetically under and include it in the
[project.optional-dependencies]aggregate.all - Use the model-extra name in and
OptionalDependencyFailure("model-extra").@check_optional_dependencies()
Present the proposed dependency extra and ask the user to approve before editing
:
pyproject.tomltoml
model-name = ["package1>=version", "package2"]在编辑文件前,对请求的诊断进行分类:
| 如果模型... | 则使用... |
|---|---|
| 计算派生量且无检查点 | 简单诊断 |
从 | AutoModel诊断 |
| 生成多个样本、扩散输出、VAE样本或随机超分辨率结果 | 生成式诊断 |
依赖策略:
- 简单派生诊断通常不需要在中添加扩展。
pyproject.toml - AutoModel和生成式诊断必须有一个命名的可选依赖扩展,即使列表为空。
- 在下按字母顺序添加扩展,并将其包含在
[project.optional-dependencies]聚合中。all - 在和
OptionalDependencyFailure("model-extra")中使用模型扩展名称。@check_optional_dependencies()
在编辑前,先提出拟议的依赖扩展并请求用户批准:
pyproject.tomltoml
model-name = ["package1>=version", "package2"]or, when the packaged diagnostic needs no extra runtime packages:
或者,当打包诊断不需要额外的运行时包时:
model-name = []
undefinedmodel-name = []
undefinedStep 2 - Add Dependencies
步骤2 - 添加依赖
After approval, edit :
pyproject.toml- Add the extra alphabetically.
- Update the aggregate.
all - Prefer minimum supported versions from the reference package documentation.
- Do not add broad unpinned Git dependencies unless the reference model requires them and the user approves.
获得批准后,编辑:
pyproject.toml- 按字母顺序添加扩展。
- 更新聚合。
all - 优先使用参考包文档中支持的最低版本。
- 除非参考模型要求且用户批准,否则不要添加宽泛的未固定Git依赖。
Step 3 - Create Model File
步骤3 - 创建模型文件
File:
earth2studio/models/dx/<lowercase>.pyUse the repo-standard SPDX/license header shown in existing model files.
Simple diagnostic imports commonly include:
python
from collections import OrderedDict
import numpy as np
import torch
from earth2studio.models.batch import batch_coords, batch_func
from earth2studio.utils import handshake_coords, handshake_dim
from earth2studio.utils.type import CoordSystemPackaged and generative diagnostics commonly also include:
python
from earth2studio.models.auto import AutoModelMixin, Package
from earth2studio.models.dx.base import DiagnosticModel
from earth2studio.utils.imports import OptionalDependencyFailure, check_optional_dependencies
from loguru import loggerCanonical method order:
__init__input_coords- decorated with
output_coords@batch_coords() - if useful
__str__ - for AutoModel/generative diagnostics
load_default_package - for AutoModel/generative diagnostics
load_model - only when non-PyTorch state must move devices
to - Private/support methods
- decorated with
__call__and@torch.inference_mode()@batch_func()
Avoid shared base classes or broad abstractions unless the wrapper naturally has
multiple closely related variants where a small base class reduces duplication.
文件路径:
earth2studio/models/dx/<lowercase>.py使用现有模型文件中所示的代码库标准SPDX/许可证头部。
简单诊断常用导入:
python
from collections import OrderedDict
import numpy as np
import torch
from earth2studio.models.batch import batch_coords, batch_func
from earth2studio.utils import handshake_coords, handshake_dim
from earth2studio.utils.type import CoordSystem打包诊断和生成式诊断通常还需导入:
python
from earth2studio.models.auto import AutoModelMixin, Package
from earth2studio.models.dx.base import DiagnosticModel
from earth2studio.utils.imports import OptionalDependencyFailure, check_optional_dependencies
from loguru import logger标准方法顺序:
__init__input_coords- 带有装饰器的
@batch_coords()output_coords - 有用的(可选)
__str__ - AutoModel/生成式诊断的
load_default_package - AutoModel/生成式诊断的
load_model - 仅当非PyTorch状态需要移动设备时使用
to - 私有/支持方法
- 带有和
@torch.inference_mode()装饰器的@batch_func()__call__
除非包装器自然存在多个密切相关的变体,且小型基类可以减少重复代码,否则避免使用共享基类或宽泛的抽象。
Step 4 - Implement Coordinates
步骤4 - 实现坐标
Diagnostic input coordinates usually use this public Earth2Studio order:
- :
batchand first in thenp.empty(0)OrderedDict - : input variable names using Earth2Studio vocabulary names
variable - : public latitude convention north-to-south, usually
latto90-90 - : public longitude convention
lonto0, endpoint normally false360
No diagnostic wrapper should expose . If a diagnostic needs validity
time metadata, document it as per-sample metadata in ; do not make
it a tensor dimension unless an existing dx pattern requires it.
lead_timecoords["time"]output_coordshandshake_dimhandshake_coordssamplebatch诊断输入坐标通常使用以下Earth2Studio公共顺序:
- :
batch,且在np.empty(0)中排第一OrderedDict - :使用Earth2Studio词汇命名的输入变量名
variable - :公共纬度约定(北到南),通常为
lat到90-90 - :公共经度约定
lon到0,通常不包含端点360
任何诊断包装器都不应暴露。如果诊断需要有效时间元数据,请将其记录为中的每样本元数据;除非现有dx模式要求,否则不要将其作为张量维度。
lead_timecoords["time"]output_coordshandshake_dimhandshake_coordsbatchsampleStep 5 - Implement Forward Pass
步骤5 - 实现前向传播
Use a single-step ; never create an iterator. Validate coordinates
before model execution, then return .
__call__(output_tensor, output_coords)python
@torch.inference_mode()
@batch_func()
def __call__(self, x: torch.Tensor, coords: CoordSystem) -> tuple[torch.Tensor, CoordSystem]:
output_coords = self.output_coords(coords)
x = (x - self.center) / self.scale
out = self.core_model(x)
return out, output_coordsFor generative diagnostics, loop over the batch dimension and generate
per input item. Use explicit seeds for reproducibility when
the reference implementation supports seeded sampling.
number_of_samples使用单步;切勿创建迭代器。在模型执行前验证坐标,然后返回。
__call__(output_tensor, output_coords)python
@torch.inference_mode()
@batch_func()
def __call__(self, x: torch.Tensor, coords: CoordSystem) -> tuple[torch.Tensor, CoordSystem]:
output_coords = self.output_coords(coords)
x = (x - self.center) / self.scale
out = self.core_model(x)
return out, output_coords对于生成式诊断,遍历batch维度,为每个输入项生成个样本。当参考实现支持种子采样时,使用显式种子以确保可复现性。
number_of_samplesStep 6 - Implement Model Loading
步骤6 - 实现模型加载
For packaged diagnostics:
- should lock HuggingFace URLs to a commit (
load_default_package) or NGC/S3 versions to an immutable release.hf://org/repo@commit - should call
load_model, load checkpoints on CPU first, set modules topackage.resolve(...), and disable gradients where appropriate.eval() - Use only when loading a pickled full PyTorch object is required.
weights_only=False - Decorate optional model classes and with
load_model.@check_optional_dependencies() - Use for useful loading messages; do not use
loguru.loggerinsideprint().earth2studio/
对于打包诊断:
- 应将HuggingFace URL锁定到特定提交(
load_default_package),或将NGC/S3版本锁定到不可变的发布版本。hf://org/repo@commit - 应调用
load_model,先在CPU上加载检查点,将模块设置为package.resolve(...)模式,并在适当的地方禁用梯度。eval() - 仅当需要加载完整的PyTorch pickle对象时,才使用。
weights_only=False - 对可选模型类和使用
load_model装饰器。@check_optional_dependencies() - 使用输出有用的加载信息;在
loguru.logger内部不要使用earth2studio/。print()
Step 7 - Write Tests
步骤7 - 编写测试
File:
test/models/dx/test_<name>.pyRequired tests:
| Function | Purpose |
|---|---|
| Forward pass with mock or simple model |
| Invalid coordinate order, values, or variables raise errors |
| Real weights with |
Generative diagnostics also require sample-count and deterministic-seed tests.
Use . Create a dummy that matches
the real core model's interface and produces deterministic output.
references/testing-guide.pyPhoo<ModelName>Run focused tests:
bash
uv run pytest test/models/dx/test_<name>.py -m "not package" -v
uv run pytest test/models/dx/test_<name>.py::test_<model>_package --package -vDo not omit package tests for packaged models. If arbitrary random inputs are not
physically valid for the real checkpoint, build a stable model-appropriate input
while still loading real weights and running a forward pass.
文件路径:
test/models/dx/test_<name>.py必填测试:
| 函数 | 目的 |
|---|---|
| 使用模拟或简单模型进行前向传播测试 |
| 验证无效坐标顺序、值或变量会引发错误 |
| 针对AutoModel/生成式诊断的真实权重测试(带有 |
生成式诊断还需要样本数量和确定性种子测试。使用。创建一个虚拟类,匹配真实核心模型的接口并生成确定性输出。
references/testing-guide.pyPhoo<ModelName>运行指定测试:
bash
uv run pytest test/models/dx/test_<name>.py -m "not package" -v
uv run pytest test/models/dx/test_<name>.py::test_<model>_package --package -v不要省略打包模型的包测试。如果任意随机输入对真实检查点无效,请构建一个稳定的、适合模型的输入,同时仍加载真实权重并运行前向传播。
Step 8 - Register Model
步骤8 - 注册模型
For public models, update alphabetically.
Skip registration only when the user explicitly wants an internal or experimental
file that should not be exported.
earth2studio/models/dx/__init__.py对于公开模型,按字母顺序更新。仅当用户明确希望创建不应导出的内部或实验性文件时,才跳过注册。
earth2studio/models/dx/__init__.pyStep 9 - Documentation
步骤9 - 文档
For public models:
- Add to alphabetically so API docs include the generated page.
docs/modules/models_dx.rst - Add to if a model extra exists. Include model notes plus both
docs/userguide/about/install.mdandpip install earth2studio[model-name]instructions.uv add earth2studio --extra model-name - Update under
CHANGELOG.md.### Added
Format and lint:
bash
make format && make lint && make license对于公开模型:
- 按字母顺序添加到,使API文档包含生成的页面。
docs/modules/models_dx.rst - 如果存在模型扩展,请添加到。包含模型说明以及
docs/userguide/about/install.md和pip install earth2studio[model-name]两种安装指令。uv add earth2studio --extra model-name - 在的
CHANGELOG.md部分更新内容。### Added
格式化和检查:
bash
make format && make lint && make licenseStep 10 - Validation (if requested)
步骤10 - 验证(如果需要)
Follow . Create uncommitted vanilla,
Earth2Studio, comparison, and sanity-check scripts. Do not commit generated
outputs, checkpoints, images, or local validation scripts.
references/validation-guide.mdFor generative diagnostics, fix seeds and compare matching samples or report
statistical/tolerance-based agreement when exact equality is impossible.
Ask the user to visually inspect plots before proceeding.
遵循。创建未提交的原生脚本、Earth2Studio脚本、对比脚本和 sanity-check 脚本。不要提交生成的输出、检查点、图像或本地验证脚本。
references/validation-guide.md对于生成式诊断,固定种子并对比匹配样本;当无法实现完全相等时,报告基于统计或容差的一致性。请用户在继续前目视检查绘图。
Step 11 - PR (if requested)
步骤11 - 创建PR(如果需要)
Follow and use:
references/validation-guide.mdreferences/pr-body-template.mdreferences/pr-comment-template.md
Before creating the PR, verify dependency extras, , install docs, API docs,
changelog, tests, and validation artifacts are consistent. Do not include machine
names, hostnames, absolute paths, cache paths, device inventory, or uploaded image
links in PR text. Use plot placeholders for manual image upload.
all遵循并使用:
references/validation-guide.mdreferences/pr-body-template.mdreferences/pr-comment-template.md
创建PR前,验证依赖扩展、聚合、安装文档、API文档、变更日志、测试和验证工件是否一致。PR文本中不要包含机器名称、主机名、绝对路径、缓存路径、设备清单或上传的图像链接。使用绘图占位符以便手动上传图像。
allExamples
示例
Simple Diagnostic
简单诊断
text
User: Create a diagnostic that computes wind speed from u10m and v10m.
Agent: Reads SKILL.md, classifies as simple, creates windspeed.py with only
torch.nn.Module, writes call and exception tests, runs focused pytest.text
用户:创建一个从u10m和v10m计算风速的诊断模型。
Agent:阅读SKILL.md,将其分类为简单型,创建windspeed.py文件(仅继承torch.nn.Module),编写调用和异常测试,运行指定的pytest命令。AutoModel Diagnostic
AutoModel诊断
text
User: Add a precipitation estimator from this reference script.
Agent: Reads SKILL.md and references, proposes dependency extra, creates a
torch.nn.Module + AutoModelMixin wrapper, writes mock/package tests,
updates docs/changelog/dependencies, and runs validation commands.text
用户:根据此参考脚本添加一个降水估算器。
Agent:阅读SKILL.md和参考文件,提出依赖扩展建议,创建继承torch.nn.Module + AutoModelMixin的包装器,编写模拟/包测试,更新文档/变更日志/依赖,运行验证命令。Generative Diagnostic
生成式诊断
text
User: Wrap this diffusion super-resolution model.
Agent: Classifies as generative, adds sample output coordinates, supports seed
handling, writes sample and deterministic-seed tests, and prepares seeded
validation comparisons.text
用户:包装此扩散超分辨率模型。
Agent:将其分类为生成型,添加样本输出坐标,支持种子处理,编写样本和确定性种子测试,准备种子化的验证对比。Troubleshooting
故障排除
| Error | Solution |
|---|---|
| Install with |
| Coordinate handshake fails | Check |
| Wrong output shape | Verify |
| Use |
| Package test fails on random input | Use a stable physically plausible input while still loading real weights |
| 错误 | 解决方案 |
|---|---|
| 使用 |
| 坐标握手失败 | 检查 |
| 输出形状错误 | 验证 |
| 使用 |
| 包测试在随机输入上失败 | 使用稳定的、符合物理规律的输入,同时仍加载真实权重 |
Reminders
注意事项
Do:
- Use and
uv run pythonfor all Python commands.uv run pytest - Use on
@batch_coords().output_coords - Use and
@torch.inference_mode()on@batch_func().__call__ - Keep as the first coordinate with
batchinnp.empty(0).input_coords - Validate coordinates with and
handshake_dim().handshake_coords() - Add in generative
sample.output_coords - Include the repo-standard SPDX/license header in every Python file.
- Use , never
loguru.logger, insideprint().earth2studio/
Do not:
- Inherit from .
PrognosticMixin - Include coordinates.
lead_time - Create .
create_iterator - Create general base classes for a single wrapper without a clear multi-variant need.
- Commit API keys, credentials, validation scripts, plots, or generated outputs.
- Read from .
evals/targets/
请遵循:
- 所有Python命令使用和
uv run python。uv run pytest - 在上使用
output_coords装饰器。@batch_coords() - 在上使用
__call__和@torch.inference_mode()装饰器。@batch_func() - 在中保持
input_coords为第一个坐标,值为batch。np.empty(0) - 使用和
handshake_dim()验证坐标。handshake_coords() - 在生成式中添加
output_coords维度。sample - 在每个Python文件中包含代码库标准的SPDX/许可证头部。
- 在内部使用
earth2studio/,切勿使用loguru.logger。print()
请勿:
- 继承自。
PrognosticMixin - 包含坐标。
lead_time - 创建。
create_iterator - 为单个包装器创建通用基类,除非明确存在多变体需求。
- 提交API密钥、凭证、验证脚本、绘图或生成的输出。
- 读取目录下的文件。
evals/targets/
Self-Improvement
自我改进
If this skill produces incorrect outputs, update it before continuing:
- Identify the issue in the generated code or workflow.
- Edit or the relevant file in
SKILL.mdto fix the guidance.references/ - Run focused validation for the changed skill files.
- Commit the skill fix separately when working in a branch that expects commits.
- Continue the model implementation with the corrected workflow.
如果本技能生成的输出不正确,请先更新技能再继续:
- 识别生成代码或工作流中的问题。
- 编辑或
SKILL.md中的相关文件以修正指引。references/ - 对修改后的技能文件运行指定的验证。
- 在需要提交的分支中,单独提交技能修复。
- 使用修正后的工作流继续模型实现。