-
Notifications
You must be signed in to change notification settings - Fork 644
Add HealDA dataloader protocols and init recipe #1555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pzharrington
wants to merge
10
commits into
NVIDIA:main
Choose a base branch
from
pzharrington:healda-data
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
720d97e
Add healda protocols and loaders to experimental
pzharrington 7a9aa88
Cleanup and address imports
pzharrington 71eccaf
Update precommit for examples tests
pzharrington 1caa5ef
integrate restartable sampler, other updates, migrate tests
pzharrington 31b7e8c
move imports, cleanup
pzharrington 2165efc
ruff check fix
pzharrington 46db004
skip prefetch on CPU
pzharrington 229abfb
Rename to local_platform
pzharrington c3a2c0c
Revert precommit change
pzharrington 47af3af
greptile feedback
pzharrington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,202 @@ | ||
| # HealDA — AI-based Data Assimilation on the HEALPix Grid | ||
|
|
||
| > **🏗️ This recipe is under active construction. 🏗️** | ||
| > Structure and functionality are subject to changes. | ||
|
|
||
| HealDA is a stateless assimilation model that produces a single | ||
| global weather analysis from conventional and satellite | ||
| observations. It operates on a HEALPix level-6 padded XY grid | ||
| and outputs ERA5-compatible atmospheric variables. | ||
|
|
||
| ## Setup | ||
|
|
||
| Start by installing PhysicsNeMo (if not already installed) with | ||
| the `healda` optional dependency group, along with the packages | ||
| in `requirements.txt`. Then, copy this folder | ||
| (`examples/weather/healda`) to a system with a GPU available. | ||
| Also, prepare a dataset that can serve training data according | ||
| to the protocols outlined in the | ||
| [Generalized Data Loading](#generalized-data-loading) section | ||
| below. | ||
|
|
||
| ## Generalized Data Loading | ||
|
|
||
| The `physicsnemo.experimental.datapipes.healda` package provides | ||
| a composable data loading pipeline with clear extension points. | ||
| The architecture separates components into loaders, transforms, | ||
| datasets, and sampling infrastructure. | ||
|
|
||
| ### Architecture | ||
|
|
||
| ```text | ||
| ObsERA5Dataset(era5_data, obs_loader, transform) | ||
| | Temporal windowing via FrameIndexGenerator | ||
| | __getitems__ -> get() per index -> transform.transform() | ||
| v | ||
| RestartableDistributedSampler (stateful distributed sampling with checkpointing) | ||
| | | ||
| DataLoader (pin_memory, persistent_workers) | ||
| | | ||
| prefetch_map(loader, transform.device_transform) | ||
| | | ||
| Training loop (GPU-ready batch) | ||
| ``` | ||
|
|
||
| ### Key Protocols | ||
|
|
||
| Custom data sources and transforms plug in via these protocols | ||
| (see `physicsnemo.experimental.datapipes.healda.protocols`): | ||
|
|
||
| **`ObsLoader`** — the observation loading interface: | ||
|
|
||
| ```python | ||
| class MyObsLoader: | ||
| async def sel_time(self, times): | ||
| """Return {"obs": [pa.Table, ...]}""" | ||
| ... | ||
| ``` | ||
|
|
||
| **`Transform`** / **`DeviceTransform`** — two-stage batch | ||
| processing: | ||
|
|
||
| ```python | ||
| class MyTransform: | ||
| def transform(self, times, frames): | ||
| """CPU-side: normalize, encode obs, time features.""" | ||
| ... | ||
|
|
||
| def device_transform(self, batch, device): | ||
| """GPU-side: move to device, compute obs features.""" | ||
| ... | ||
| ``` | ||
|
|
||
| ### Provided Implementations | ||
|
|
||
| | Component | Module | Description | | ||
| |---|---|---| | ||
| | `ObsERA5Dataset` | `dataset` | ERA5 state + observations | | ||
| | `UFSUnifiedLoader` | `loaders.ufs_obs` | Parquet obs loader | | ||
| | `ERA5Loader` | `loaders.era5` | Async ERA5 zarr loader | | ||
| | `ERA5ObsTransform` | `transforms.era5_obs` | Two-stage transform | | ||
| | `RestartableDistributedSampler` | `samplers` | Stateful distributed sampler | | ||
| | `prefetch_map` | `prefetch` | CUDA stream prefetching | | ||
|
|
||
| All modules above are under | ||
| `physicsnemo.experimental.datapipes.healda`. | ||
|
|
||
| ### Writing a Custom Observation Loader | ||
|
|
||
| Implement `async def sel_time(times)` returning a dict with | ||
| observation data per timestamp: | ||
|
|
||
| ```python | ||
| class GOESRadianceLoader: | ||
| def __init__(self, data_path, channels): | ||
| self.data_path = data_path | ||
| self.channels = channels | ||
|
|
||
| async def sel_time(self, times): | ||
| tables = [] | ||
| for t in times: | ||
| table = self._load_goes_radiances(t) | ||
| tables.append(table) | ||
| return {"obs": tables} | ||
| ``` | ||
|
|
||
| Then pass it to the dataset: | ||
|
|
||
| ```python | ||
| from physicsnemo.experimental.datapipes.healda import ( | ||
| ObsERA5Dataset, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.transforms.era5_obs import ( | ||
| ERA5ObsTransform, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.configs.variable_configs import ( | ||
| VARIABLE_CONFIGS, | ||
| ) | ||
|
|
||
| dataset = ObsERA5Dataset( | ||
| era5_data=era5_xr["data"], | ||
| obs_loader=GOESRadianceLoader(...), | ||
| transform=ERA5ObsTransform(sensors=["goes"], ...), | ||
| variable_config=VARIABLE_CONFIGS["era5"], | ||
| ) | ||
| ``` | ||
|
|
||
| ### Putting It Together | ||
|
|
||
| A complete training pipeline wires together all the | ||
| components — dataset, sampler, DataLoader, and GPU prefetch: | ||
|
|
||
| ```python | ||
| import torch | ||
| from torch.utils.data import DataLoader | ||
|
|
||
| from physicsnemo.experimental.datapipes.healda import ( | ||
| ObsERA5Dataset, | ||
| RestartableDistributedSampler, | ||
| identity_collate, | ||
| prefetch_map, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.loaders.ufs_obs import ( | ||
| UFSUnifiedLoader, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.transforms.era5_obs import ( | ||
| ERA5ObsTransform, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.configs.variable_configs import ( | ||
| VARIABLE_CONFIGS, | ||
| ) | ||
|
|
||
| sensors = ["atms", "mhs", "conv"] | ||
|
|
||
| # 1. Build loaders | ||
| obs_loader = UFSUnifiedLoader( | ||
| data_path="/path/to/processed_obs", | ||
| sensors=sensors, | ||
| normalization="zscore", | ||
| obs_context_hours=(-21, 3), | ||
| ) | ||
| transform = ERA5ObsTransform( | ||
| variable_config=VARIABLE_CONFIGS["era5"], | ||
| sensors=sensors, | ||
| ) | ||
|
|
||
| # 2. Build dataset | ||
| dataset = ObsERA5Dataset( | ||
| era5_data=era5_xr["data"], | ||
| obs_loader=obs_loader, | ||
| transform=transform, | ||
| variable_config=VARIABLE_CONFIGS["era5"], | ||
| split="train", | ||
| ) | ||
|
|
||
| # 3. Sampler + DataLoader | ||
| sampler = RestartableDistributedSampler( | ||
| dataset, rank=rank, num_replicas=world_size, | ||
| ) | ||
| sampler.set_epoch(0) | ||
| dataloader = DataLoader( | ||
| dataset, | ||
| sampler=sampler, | ||
| batch_size=2, | ||
| num_workers=8, | ||
| collate_fn=identity_collate, | ||
| pin_memory=True, | ||
| persistent_workers=True, | ||
| ) | ||
|
|
||
| # 4. GPU prefetch (hides CPU→GPU transfer behind training) | ||
| device = torch.device("cuda") | ||
| loader = prefetch_map( | ||
| dataloader, | ||
| lambda batch: transform.device_transform(batch, device), | ||
| queue_size=1, | ||
| ) | ||
|
|
||
| # 5. Training loop — batches arrive GPU-ready | ||
| for batch in loader: | ||
| loss = model(batch) | ||
| ... | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # nvidia-physicsnemo[datapipes-extras] | ||
| cftime | ||
| pyarrow | ||
| dotenv | ||
| earth2grid @ git+https://github.com/NVlabs/earth2grid.git@main | ||
| healpy | ||
| matplotlib | ||
| joblib | ||
| icechunk | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| """HealDA data loading pipeline. | ||
|
|
||
| Provides the complete data pipeline for HealDA training: observation loading, | ||
| ERA5 state loading, two-stage transforms (CPU + GPU), distributed sampling, | ||
| and background CUDA prefetching. | ||
|
|
||
| Key entry points: | ||
|
|
||
| - :class:`ObsERA5Dataset` — map-style dataset combining ERA5 state + observations | ||
| - :class:`UFSUnifiedLoader` — parquet-based observation loader | ||
| - :class:`ERA5ObsTransform` — two-stage transform with Triton feature kernels | ||
| - :func:`prefetch_map` — background CUDA stream prefetching | ||
| - :class:`RestartableDistributedSampler` — stateful distributed sampler with checkpoint support | ||
|
|
||
| Protocols for custom loaders/transforms: | ||
|
|
||
| - :class:`ObsLoader` — async observation loading interface | ||
| - :class:`Transform` — CPU-side batch transform | ||
| - :class:`DeviceTransform` — GPU-side batch transform | ||
| """ | ||
|
|
||
| from physicsnemo.experimental.datapipes.healda.dataset import ( | ||
| ObsERA5Dataset, | ||
| identity_collate, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.prefetch import prefetch_map | ||
| from physicsnemo.experimental.datapipes.healda.protocols import ( | ||
| DeviceTransform, | ||
| ObsLoader, | ||
| Transform, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.samplers import ( | ||
| RestartableDistributedSampler, | ||
| ) | ||
| from physicsnemo.experimental.datapipes.healda.types import ( | ||
| Batch, | ||
| BatchInfo, | ||
| TimeUnit, | ||
| UnifiedObservation, | ||
| VariableConfig, | ||
| empty_batch, | ||
| split_by_sensor, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| # Dataset | ||
| "ObsERA5Dataset", | ||
| # Protocols | ||
| "ObsLoader", | ||
| "Transform", | ||
| "DeviceTransform", | ||
| # Types | ||
| "UnifiedObservation", | ||
| "Batch", | ||
| "BatchInfo", | ||
| "VariableConfig", | ||
| "TimeUnit", | ||
| "empty_batch", | ||
| "split_by_sensor", | ||
| # Infrastructure | ||
| "prefetch_map", | ||
| "RestartableDistributedSampler", | ||
| "identity_collate", | ||
| ] |
15 changes: 15 additions & 0 deletions
15
physicsnemo/experimental/datapipes/healda/configs/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2023 - 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| # SPDX-FileCopyrightText: All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.