Skip to content

dsl: Misc fixes for subgrids - #3127

Open
EdCaunt wants to merge 1 commit into
mainfrom
fixup-subgrid
Open

EdCaunt wants to merge 1 commit into
mainfrom
fixup-subgrid

Conversation

@EdCaunt

@EdCaunt EdCaunt commented Nov 30, 2026

Copy link
Copy Markdown
Contributor
  1. High-order SubGrid stencils (basic.py): so>=4 derivatives failed to compile or build. indexify now rescales the root spacing, so xs + 4*h_x becomes xs + 2. This also covers Functions on a SubDomain of a SubGrid.
  2. CIRE on SubGrids (aliases.py): temporaries along a SubGrid Dimension were indexed by the parent Dimension. A new _relaxed helper keeps them on the SubGrid Dimension. The assert is narrowed rather than removed, so other non-linear Dimensions (e.g. modulo ones) still trip it.
  3. Sparse operations on SubGrids (interpolators.py): interpolation gave wrong values and injection didn't compile. They now use the SubGrid's own Dimensions. Linear, sinc and precomputed now match a plain Grid exactly, including on SubDomains.
  4. Ranks owning no SubGrid points (distributed.py): these crashed or hung on the first halo exchange. SubGridDistributor.neighborhood now skips empty ranks.
  5. Factor too large (grid.py): a factor that leaves a single point along an axis now raises a clear ValueError.

@EdCaunt
EdCaunt requested a review from mloubout November 30, 2026 11:20
@codecov

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 23.97260% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.26%. Comparing base (e9591ce) to head (b4903f9).

Files with missing lines Patch % Lines
tests/test_subsampling.py 16.03% 89 Missing ⚠️
devito/mpi/distributed.py 11.11% 16 Missing ⚠️
devito/passes/clusters/aliases.py 70.00% 2 Missing and 1 partial ⚠️
devito/types/grid.py 0.00% 2 Missing ⚠️
devito/operations/interpolators.py 66.66% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (e9591ce) and HEAD (b4903f9). Click for more details.

HEAD has 11 uploads less than BASE
Flag BASE (e9591ce) HEAD (b4903f9)
18 10
pytest-gpu-gcc- 6 4
pytest-gpu-icx- 3 2
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3127       +/-   ##
===========================================
- Coverage   83.40%   52.26%   -31.14%     
===========================================
  Files         260      260               
  Lines       59671    59809      +138     
  Branches     5036     5054       +18     
===========================================
- Hits        49769    31262    -18507     
- Misses       9022    27498    +18476     
- Partials      880     1049      +169     
Flag Coverage Δ
pytest-gpu-aomp-amdgpuX 68.23% <45.00%> (-0.02%) ⬇️
pytest-gpu-gcc- 42.54% <22.60%> (-36.34%) ⬇️
pytest-gpu-icx- 42.41% <22.60%> (-36.41%) ⬇️
pytest-gpu-nvc-nvidiaX 69.06% <45.00%> (?)

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

☔ View full report in Codecov by Harness.
📢 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.

@mloubout mloubout added the API api (symbolics, types, ...) label Nov 30, 2026

@mloubout mloubout left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry quite a few comments. What made those pop up?

Comment thread devito/mpi/distributed.py
@property
def neighborhood(self):
"""
As in `Distributor.neighborhood`, but skipping the MPI ranks owning no

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a very weird corner case. I don't see how practical usage of SubGrid would end up in such a setup. I understand what it does but i think this is overkill and such odd case should just error as this is not what the api is intended for.

Comment thread devito/types/grid.py
if f < 1:
raise ValueError(f"Subsampling factor must be >= 1, got `{f}`")

for d, n, f in zip(parent.dimensions, parent.shape, factors, strict=True):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This prevents using dummy tiny grids to build an operator, those shape checks should only be done at arg processing

Comment thread tests/test_subsampling.py
v = Function(name='v', grid=target, space_order=4)
u.data[:] = np.sin(np.arange(u.data.size).reshape(u.shape)/7.)

if interpolation == 'precomputed':

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

there is utilities in test_interpolation for that.


assert not d.is_NonlinearDerived
# Only a subsampled Dimension may be iterated over, e.g. a SubGrid's
assert not d.is_NonlinearDerived or d.is_Conditional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iterated subdimension needs is_Strided

d = interval.dim
while d.is_Derived and not d.is_Conditional:
d = d.parent
if d.is_Conditional:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Likely need to check Strided as well

Comment thread devito/types/basic.py
mappers = []
for d in self.dimensions:
mapper = {d.spacing: 1, -d.spacing: -1}
# A subsampled Dimension's spacing is a multiple of its root's, e.g.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it touching d.root it's not the dimension that indexes self?

Comment thread devito/types/basic.py
for d in self.dimensions:
mapper = {d.spacing: 1, -d.spacing: -1}
# A subsampled Dimension's spacing is a multiple of its root's, e.g.
# `2*h_x`, so rescale the root's instead to also map `4*h_x` to `2`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is it checking root here. self.dimension are the ones indxing self and are the Subdim.

Comment thread tests/test_subsampling.py
((33, 33), (2, 3), ('advanced', {'blockrelax': True})),
((17, 17, 17), (2, 2, 4), 'advanced'),
])
def test_high_order_derivatives(self, so, shape, factor, opt):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems to mix different things. The cire part should be tested as a standalone in the test_dse with the other cire test and checks the Array itself.

else:
pd = d.parent
writeto.append(interval.relaxed)
writeto.append(_relaxed(interval))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure i understand why this is needed. The subsampling pass already does that.

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

API api (symbolics, types, ...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants