Skip to content

Fix per-grid forcing and boundary normalization - #917

Open
kalashmishra21 wants to merge 3 commits into
mllam:mainfrom
kalashmishra21:fix/916-per-grid-normalization
Open

kalashmishra21 wants to merge 3 commits into
mllam:mainfrom
kalashmishra21:fix/916-per-grid-normalization

Conversation

@kalashmishra21

@kalashmishra21 kalashmishra21 commented Nov 30, 2026 •

Copy link
Copy Markdown

Describe your changes

Normalize forcing and boundary statistics in grid then feature order, and repeat statistics along the feature axis. This fixes incorrect broadcasting when a datastore supplies separate statistics for each grid point.

Add regression coverage for both statistics dimension orders, both forcing sources, and different window sizes.

Issue Link

Closes #916

Type of change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📖 Documentation (Addition or improvements to documentation)

Checklist before requesting a review

  • My branch is up-to-date with the target branch - if not update your fork with the changes from the target branch (use pull with --rebase option if possible).
  • I have performed a self-review of my code
  • For any new/modified functions/classes I have added docstrings that clearly describe its purpose, expected inputs and returned values
  • I have placed in-line comments to clarify the intent of any hard-to-understand passages of my code
  • I have updated the README to cover introduced code changes
  • If this PR changes contributor workflow, I've updated CONTRIBUTING.md / AGENTS.md
  • I have added tests that prove my fix is effective or that my feature works
  • I have given the PR a name that clearly describes the change, written in imperative form
  • I have requested a reviewer and an assignee (assignee is responsible for merging). This applies only if you have write access to the repo, otherwise feel free to tag a maintainer to add a reviewer and assignee.

Checklist for reviewers

  • the code is readable
  • the code is well tested
  • the code is documented (including return types and parameters)
  • the code is easy to maintain

Author checklist after completed review

  • I have added a line to the CHANGELOG describing this change, in a section reflecting type of change (add section where missing)

Checklist for assignee

  • PR is up to date with the base branch
  • the tests pass
  • (if the PR is not just maintenance/bugfix) the PR is assigned to the next milestone. If it is not, propose it for a future milestone.
  • author has added an entry to the changelog (and designated the change as added, changed, fixed or maintenance)
  • Once the PR is ready to be merged, squash commits and merge the PR.

kalashmishra21 and others added 2 commits November 30, 2026 12:20
Co-authored-by: OpenAI Codex <noreply@openai.com>
Co-authored-by: OpenAI Codex <noreply@openai.com>
@kalashmishra21
kalashmishra21 marked this pull request as ready for review November 30, 2026 12:22
@nikhil3495

Copy link
Copy Markdown
Contributor

Nice catch, @kalashmishra21, and the test matrix is thorough. I copied the new test onto main: the 8 per-grid cases fail there and the 8 per-feature controls pass, and everything passes on this branch. The transpose plus repeat_interleave(dim=-1) leaves 1-D per-feature stats unchanged, so existing behaviour is untouched.

One sibling worth flagging: state stats go through the same hook but don't get the transpose. With per-grid state stats in (state_feature, grid_index) order, on_after_batch_transfer (base.py:406) still raises the same kind of RuntimeError on this branch, while (grid_index, state_feature) order works. Adding the same transpose to da_state_stats around base.py:219 would make the hook consistent. Full per-grid state support probably goes further though, since StepPredictor indexes state_mean[feature_idx] for clamping (step_predictors/base.py:245), so a follow-up issue might fit better than growing this PR.

@kalashmishra21

Copy link
Copy Markdown
Author

@nikhil3495 Thanks for reviewing and testing the fix! Good point about the state statistics. i agree that it would be better to handle per-grid state normalization in a separate issue, especially since it may also affect clamping. I'll look into that separately.

@kalashmishra21

Copy link
Copy Markdown
Author

Hi @Sir-Sloth-The-Lazy , when you get a chance, could you have a look at this PR for review ?
Thanks!

This branch has not been deployed

No deployments
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.

Per-grid forcing and boundary statistics break batch normalization

3 participants