Skip to content

Validate Flat dimensions in interpolate!#5474

Open
ewquon wants to merge 1 commit intomainfrom
eq/validate-flat-interpolation
Open

Validate Flat dimensions in interpolate!#5474
ewquon wants to merge 1 commit intomainfrom
eq/validate-flat-interpolation

Conversation

@ewquon
Copy link
Copy Markdown
Collaborator

@ewquon ewquon commented Apr 3, 2026

Summary

  • Adds validation in interpolate! for cross-dimensionality interpolation (e.g., 3D field to a column field)
  • When the destination grid has Flat dimensions without stored coordinates and the source grid has size > 1 in those dimensions, throws a clear ArgumentError instead of a cryptic BoundsError
  • The fix is to specify the coordinate on the Flat dimension of the destination grid, e.g., RectilinearGrid(size=Nz, x=0.5, y=0.5, z=(0, 1), topology=(Flat, Flat, Bounded))

Closes #5473

Test plan

  • Verified interpolate! from 3D to column grid with specified x, y coordinates produces correct results
  • Verified interpolate! without coordinates throws ArgumentError with helpful message
  • Verified 3D-to-3D interpolation (no Flat dims) is unaffected — validation is skipped entirely

🤖 Generated with Claude Code

When interpolating from a higher-dimensional field to a field on a grid
with Flat dimensions, the destination grid must have a stored coordinate
for each Flat dimension where the source grid has size > 1. Without this,
flatten_node strips the missing coordinates and FractionalIndices receives
a tuple of the wrong size, causing a BoundsError.

This adds an early validation check in interpolate! that produces a clear
error message instead.

Closes #5473

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread src/Fields/interpolate.jl
Comment on lines +368 to +373
if topology(to_grid, d) === Flat && isnothing(to_coords[d]) && size(from_grid, d) > 1
throw(ArgumentError(
"Cannot interpolate! to a field on a grid that is Flat in $name " *
"without a specified $name coordinate, because the source grid " *
"has size $(size(from_grid, d)) > 1 in that dimension. " *
"Specify $name on the destination grid."))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be caught with dispatch rather than if?

Also I don't think we should support interpolation to Flat dimensions from grids that have size==1, even though mathematically this is possible. Basically I think that interpolation of any kind to a Flat dimension should be disallowed, ie we only support Flat to Flat.

Copy link
Copy Markdown
Member

@glwagner glwagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest tightening the error so that interpolation to Flat dimensions only works if the source grid dimension is also Flat. This should result in a simpler error condition.

I am also wondering if dispatch would work (but it might be too complex, so the if is better).

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 3, 2026

Codecov Report

❌ Patch coverage is 14.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.74%. Comparing base (446b88e) to head (179c470).
⚠️ Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/Fields/interpolate.jl 14.28% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5474      +/-   ##
==========================================
- Coverage   73.76%   73.74%   -0.03%     
==========================================
  Files         402      402              
  Lines       22880    22887       +7     
==========================================
  Hits        16878    16878              
- Misses       6002     6009       +7     
Flag Coverage Δ
buildkite 68.91% <14.28%> (-0.03%) ⬇️
julia 68.91% <14.28%> (-0.03%) ⬇️
reactant_1 6.45% <0.00%> (-0.01%) ⬇️
reactant_2 11.23% <0.00%> (-0.01%) ⬇️
reactant_3 9.56% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/Fields/interpolate.jl
Comment on lines +364 to +366
to_coords = (ξnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ),
ηnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ),
rnode(1, 1, 1, to_grid, ℓ, ℓ, ℓ))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is most likely not GPU-safe

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.

Interpolating to a field with data at 2+ Nothing location dims fails

3 participants