Earth2studio Create Prognostic

作者 nvidiacf5224d14250Apache-2.03.5K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Create Earth2Studio prognostic (time-stepping forecast) model wrappers. Do NOT use for diagnostic models, data sources, or installation.

AI 產生的概覽

建立 Earth2Studio 預報模型封裝,將第三方機器學習天氣模型接入該框架。

功能
引導代理實作預報(時間步進)模型封裝,包括座標定義、前向傳遞、模型載入與迭代器建立。它也會產生以模擬為基礎的測試、相依性附加群組、文件項目與變更記錄更新,並可選擇提供驗證指令碼與 PR 範本。此技能附帶參考範本與可執行指令碼,用於建立骨架與測試。
適用情境
在需要依據參考推論指令碼或程式碼倉庫,為 Earth2Studio 新增預報天氣模型封裝時使用。它不適用於診斷模型、資料來源或安裝工作。
執行需求
需要具備 Earth2Studio、PyTorch、NumPy、loguru 與 pytest 的 Python 環境,並透過 uv 執行。需要存取 Earth2Studio 程式碼倉庫簽出,且套件測試需要連線至 Hugging Face 模型權重的網路存取。此技能附帶可執行指令碼與參考範本。

Quick Start Checklist

Do these steps IN ORDER. Do not skip any step.

  • Read this SKILL.md completely first
  • Get reference script (Step 0)
  • Create earth2studio/models/px/<name>.py with triple inheritance
  • Create test/models/px/test_<name>.py with mock tests
  • Run: uv run pytest test/models/px/test_<name>.py -v
  • Add/update model extra, install docs, API docs, and changelog (Steps 1-2, 9)
  • Run: make format && make lint

⚠️ CRITICAL: Always use uv run for Python commands:

  • ✅ uv run pytest ... / uv run python ...
  • ❌ pytest ... / python ... (missing dependencies)

Stuck or wrong output: Do not keep retrying the same fix. Follow Self-Improvement to patch this skill before continuing.

Purpose

Implement a prognostic model wrapper connecting third-party ML weather models to Earth2Studio. Prognostic models time-integrate forward—given initial state, they predict future states by stepping through time (e.g., 6-hour increments).

Workspace

ContextLocation
Harbor evalWrite to /workspace/output/earth2studio/models/px/...
Harbor + --copy-repoFull checkout at /workspace/repo
Local cloneDirectory with pyproject.toml

Never read evals/targets/ — grader references only.

Reference Files

Load on demand during the matching step:

FileContentLoad at
references/skeleton-template.pyFull model skeleton with FILL commentsSteps 3–6
references/method-templates.pyCanonical method implementationsSteps 4–6
references/testing-guide.pyTest skeleton and mock patternsStep 7
references/validation-guide.mdComparison scripts, PR, code reviewSteps 10–11

Workflow Steps

Step 0 — Get Reference Script

If $ARGUMENTS provided, use it. Otherwise ask:

Please provide a reference inference script URL/path.

Step 1 — Analyze & Propose Dependencies

Analyze: packages, architecture, I/O shapes, time step, resolution, checkpoint.

Propose pyproject.toml group (alphabetical, add to all). Every prognostic model must have an optional dependency extra, even when no packages are required:

toml
model-name = ["package1>=version", "package2"]# or, when no additional packages are required:model-name = []

[CONFIRM] Present dependencies and ask user to approve.

Step 2 — Add Dependencies

Edit pyproject.toml: add the model extra alphabetically, even if it is empty, and update the all aggregate.

Step 3 — Create Model File

File: earth2studio/models/px/<lowercase>.py

Required inheritance (all three):

python
class ModelName(torch.nn.Module, AutoModelMixin, PrognosticMixin):

Required imports:

python
import numpy as npimport torchfrom earth2studio.models.auto import AutoModelMixin, Packagefrom earth2studio.models.batch import batch_coords, batch_funcfrom earth2studio.models.px.base import PrognosticMixinfrom earth2studio.models.utils import create_coords_from_lat_lon, handshake_dimfrom earth2studio.lexicon import E2STUDIO_VOCABfrom earth2studio.utils import check_optional_dependenciesfrom loguru import logger

SPDX header (required at top of every .py file):

python
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES.# SPDX-License-Identifier: Apache-2.0

Canonical method order:

  1. __init__ 2. input_coords 3. output_coords (@batch_coords)
  2. load_default_package 5. load_model 6. to (optional)
  3. Private methods 8. __call__ (@batch_func) 9. _default_generator
  4. create_iterator

Step 4 — Implement Coordinates

input_coords rules:

  • batch: np.empty(0)
  • time: np.empty(0) (dynamic)
  • lead_time: starts at np.timedelta64(0, "h")
  • lat: 90 to -90 (north to south); this is the public Earth2Studio convention even if the source model uses the opposite order
  • lon: 0 to 360
  • If a checkpoint/model core expects south-to-north latitude, flip tensors internally before/after the core model; do not expose flipped latitude in input_coords or output_coords
  • Map variables to E2STUDIO_VOCAB (282 entries in earth2studio/lexicon/base.py)

output_coords: Use handshake_dim/handshake_coords for input validation, then increment lead_time. Prefer a shared coordinate-check helper and call it from output_coords, __call__, and iterator setup before model execution.

Step 5 — Implement Forward Pass

__call__: @batch_func decorated, shape (batch, time, lead_time, var, lat, lon). Reshape to model format → call model → reshape back.

create_iterator: MUST yield initial condition first (step 0). Use front_hook/rear_hook for perturbation injection.

Step 6 — Implement Model Loading

load_default_package: Lock HuggingFace URLs: hf://org/repo@commit

load_model: Use package.resolve(), map_location="cpu", eval() mode, decorate with @check_optional_dependencies().

Step 7 — Write Tests

File: test/models/px/test_<name>.py

Required tests:

FunctionPurpose
test_<model>_callSingle forward pass (parametrize device/time)
test_<model>_iterIterator produces sequence
test_<model>_exceptionsInvalid coords raise errors
test_<model>_packageReal weights (@pytest.mark.package)

Create PhooModelName dummy matching interface for mock tests.

Run tests:

bash
uv run pytest test/models/px/test_<name>.py -m "not package" -vuv run pytest test/models/px/test_<name>.py::test_<model>_package --package -v

Do not omit the package test. If arbitrary random inputs are not physically valid for the real checkpoint, use a stable model-appropriate synthetic input while still loading real weights and running a forward pass.

Step 8 — Register Model (if requested)

  • Add to earth2studio/models/px/__init__.py (alphabetical)
  • Verify deps in pyproject.toml

Step 9 — Documentation

  • Add to docs/modules/models_px.rst (alphabetical). This is required for every new prognostic model so the API docs include the generated page.
  • Add to docs/userguide/about/install.md (alphabetical tab) for the model extra, even when the extra is empty. Include model-specific notes plus both pip install earth2studio[model-name] and uv add earth2studio --extra model-name instructions.
  • Update CHANGELOG.md under ### Added. This is required for every new prognostic model.

Format and lint:

bash
make format && make lint && make license

Step 10 - Validation (if requested)

Follow references/validation-guide.md. Create uncommitted vanilla, E2S, comparison, and sanity-check scripts; do not commit generated outputs or images. Use PR-safe placeholders for plots so the user can upload images manually.

[CONFIRM] User must visually inspect plots before proceeding.

Step 11 - PR (if requested)

Follow references/validation-guide.md and use:

  • references/pr-body-template.md
  • references/pr-comment-template.md

Before creating the PR, verify pyproject.toml has the model extra, the all extra includes it, install docs include both pip and uv commands, and docs/modules/models_px.rst plus CHANGELOG.md are updated.

Do not include machine names, absolute paths, device inventory, or uploaded image links in PR text. Use plot placeholders instead.


Examples

Simple Identity Model

text
User: Create IdentityModel - returns input unchanged, 6h step, 181x360, vars: t2m, u10m, v10m, msl
Agent: [reads SKILL.md, creates identity.py with triple inheritance,        creates test_identity.py, runs pytest, runs make format && lint]

External Model (Pangu)

text
User: Add Pangu-Weather wrapper      GitHub: https://github.com/198808xc/Pangu-Weather
Agent: [reads SKILL.md, fetches inference.py, creates pangu.py,        creates test_pangu.py, runs pytest]

Key Patterns

Coordinate Template

python
@propertydef 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", ...]),        # Public Earth2Studio convention is north-to-south latitude.        "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

Iterator Template

python
def create_iterator(self, x, coords):    yield x, coords  # Initial condition (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

Troubleshooting

ErrorSolution
OptionalDependencyFailureuv add --optional <group> <pkg>
Coordinate handshake failsCheck handshake_dim indices match dim position
Iterator wrong shapesDebug reshape logic with random input
ModuleNotFoundError: pytestUse uv run pytest not pytest

Reminders

DO:

  • Use uv run python for ALL Python commands
  • Use loguru.logger, never print()
  • Inherit torch.nn.Module + AutoModelMixin + PrognosticMixin
  • Yield initial condition first in create_iterator
  • Use front_hook()/rear_hook() in _default_generator
  • Include SPDX header in every .py file

DON'T:

  • Create general base classes for reuse
  • Commit API keys or comparison scripts
  • Read from evals/targets/

來源與署名

來源:nvidia/skills位於skills/earth2studio-create-prognostic提交cf5224d

授權條款: Apache-2.0

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架