Skip to content

feat: add mixed-resolution embedding index for stretched mesh#229

Merged
jacobbieker merged 1 commit into
openclimatefix:mainfrom
AswaniSahoo:feat/stretched-embedding-index
Jul 5, 2026
Merged

feat: add mixed-resolution embedding index for stretched mesh#229
jacobbieker merged 1 commit into
openclimatefix:mainfrom
AswaniSahoo:feat/stretched-embedding-index

Conversation

@AswaniSahoo

Copy link
Copy Markdown
Contributor

Pull Request

Description

Adds mixed_resolution_embedding_indices, the piece that lets a stretched mesh use a learnable embedding per H3 cell. On a single-resolution mesh the model keeps one embedding table indexed by cell, but a stretched mesh mixes coarse and fine cells, so one table indexed by a single resolution no longer fits.

This maps each mesh cell to a (resolution, row). The row is the cell's position in sorted(uncompact_cells(get_res0_cells(), res)), the same global numbering DynamicGraphBuilder already uses. Because the row depends only on the cell, a location keeps the same row no matter which mesh it lands in, so a moving region reuses the vector it already learned for that spot instead of relearning it after every move.

Pure function, no model or training changes yet. The model wiring that gathers from two per-resolution tables (coarse and fine) using these indices comes in a later PR. This is the third building block for the stretched-grid model, after the mesh builder (#226) and alongside the latent graph (#227) and point assignment (#228).

Related to #3

How Has This Been Tested?

Added tests to tests/test_stretched_mesh.py - plain pytest, runs entirely on h3, no network:

  • one (resolution, row) per cell, resolution matching the cell
  • every row sits inside its own resolution's global table range
  • a row equals the cell's position in the sorted global cell set at its resolution
  • a coarse cell keeps its row when the refined region moves (UK box vs Japan box)
  • a fine cell shared by two different regions keeps the same row in both

Commands:

  • pytest tests/test_stretched_mesh.py -q -> 12 passed
  • ruff check graph_weather/models/layers/stretched_mesh.py tests/test_stretched_mesh.py -> clean

Checklist:

  • My code follows OCF's coding style guidelines
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked my code and corrected any misspellings

@AswaniSahoo

Copy link
Copy Markdown
Contributor Author

@jacobbieker these are the small, independent building blocks for the stretched-grid regional model, The PR that wires all three into RegionalForecaster is next and depends on them. No rush - whenever you get a chance.

@AswaniSahoo

Copy link
Copy Markdown
Contributor Author

@jacobbieker these are the small, independent building blocks for the stretched-grid regional model, all off main: #227 (latent graph over the mixed-res mesh, coarse/fine seam stitched), #228 (assign observation points to the right-size cell), and #229 (mixed-resolution embedding index so a moving region keeps its learned per-cell vectors). Each is pure h3 with its own tests. The PR that wires all three into RegionalForecaster is next and depends on them. No rush - whenever you get a chance.

@jacobbieker

Copy link
Copy Markdown
Collaborator

Looks good, thanks for this! If you can fix the branch conflicts, we can then merge this

@AswaniSahoo
AswaniSahoo force-pushed the feat/stretched-embedding-index branch from 7c86a7f to 9817560 Compare July 5, 2026 19:00
@AswaniSahoo

Copy link
Copy Markdown
Contributor Author

Thanks @jacobbieker 😊 Rebased on main, conflicts resolved. Ready whenever you are.

@jacobbieker
jacobbieker merged commit 6c2eb17 into openclimatefix:main Jul 5, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants