Skip to content

compiler: Map implicit ConditionalDimensions onto SubDomain dimensions - #3118

Open
sankalpsthakur wants to merge 1 commit into
devitocodes:mainfrom
sankalpsthakur:fix/2803-implicit-cdim-subdomain
Open

sankalpsthakur wants to merge 1 commit into
devitocodes:mainfrom
sankalpsthakur:fix/2803-implicit-cdim-subdomain

Conversation

@sankalpsthakur

Copy link
Copy Markdown

Summary

Fixes #2803.

An Eq with subdomain= and an implicit ConditionalDimension whose parent and/or condition are defined on the Grid dimensions crashed at Operator build:

devito/ir/support/space.py:586: ValueError: tuple.index(x): x not in tuple

Root cause

_make_dimension_map (devito/ir/equations/algorithms.py) maps the Grid dimensions onto the SubDomain's SubDimensions ({x: ix, y: iy}) and already rebuilds ConditionalDimensions found in Function.dimensions (the SubGrid case). It did not handle the ConditionalDimensions in expr.implicit_dims, so the implicit dimension kept parent=y and a condition on u(x, y) while all accesses were lowered onto ix/iy. For the issue's reproducer on the base commit, the Cluster reaching guard() (devito/ir/clusters/algorithms.py) has Eq(u[ix + 1, iy + 1], 7) with IterationSpace [ix, y, iy]. guard() places the condition Gt(u(x, y), 0) by calling c.ispace.index() on each Dimension of the condition, and x is not in that space, which raises the ValueError.

Fix

After the existing SubGrid handling, each implicit ConditionalDimension whose parent is a mapped Grid dimension, or whose condition references one, is rebuilt with its parent and condition mapped through the SubDomain's dimension_map. uxreplace then substitutes it in the Eq's implicit_dims, as it already does for other mapped dimensions. A getattr guard is used because plain relationals have no implicit_dims.

Tests

  • Added TestSubDomain_w_condition::test_condition_w_subdomain_v3 in tests/test_subdomains.py: a 6x6 grid, ci = ConditionalDimension(parent=y, condition=Gt(u, 0)), Eq(u, 7, implicit_dims=ci, subdomain=grid.interior). It checks the data against numpy (interior cells with u > 0 set to 7, boundary untouched) and the loop structure.
  • On the base commit the new test fails with ValueError: tuple.index(x): x not in tuple; with the change it passes.
  • Locally (macOS, Python 3.14.7, DEVITO_ARCH=clang DEVITO_LANGUAGE=C, no MPI): pytest -m "not parallel" tests/test_subdomains.py tests/test_dimension.py tests/test_ir.py tests/test_symbolics.py tests/test_buffering.py tests/test_operator.py gives 1073 passed, 2 xfailed, 1 failed. The failure is test_dimension.py::TestConditionalDimension::test_blocking_w_guard, which also fails when run on the base commit, with the same compile error (fatal error: 'omp.h' file not found) from Apple clang.
  • ruff check is clean on the changed files. flake8 --max-line-length 90 with the ignore list from [tool.flake8] in pyproject.toml passed explicitly via --extend-ignore is also clean; without that list flake8 reports pre-existing E275 warnings in tests/test_subdomains.py that are not on lines this change touches.

AI/LLM disclosure

AI coding tools were used to help draft or modify code and this PR description. I reviewed the complete change, understand the reasoning, and ran the reported local tests before submitting.

An implicit ConditionalDimension defined over the Grid Dimensions (parent
and/or condition) was left untouched by _make_dimension_map when the Eq
carried a subdomain, while every access was lowered onto the SubDomain's
SubDimensions. The resulting IterationSpace was [ix, y, iy], and guard() crashed
looking up x in it with "ValueError: tuple.index(x): x not in tuple".

Rebuild such ConditionalDimensions with their parent and condition mapped
through the SubDomain's dimension_map, mirroring what is already done for
subsampled Functions.

Fixes devitocodes#2803

Signed-off-by: Sankalp Thakur <sankalphimself@gmail.com>

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.

ConditionalDimension + implicit_dims fails when combined with SubDomain

1 participant