Skip to content

Commit 0a0ec7f

Browse files
authored
refactor[cartesian]: Better error message for out of bound read on stencils (#2567)
- Better error message for out of bound read: refactor [cartesian] ## Description Changed the error message raised when a stencil attempts to read outside of the valid bounds of an array. The new message now provides information about which fields fail, their side, and some tips to guide users resolving the error. Existing test suite covers this change, new tests should not be required to validate this change.
1 parent 47b9582 commit 0a0ec7f

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- Kardos, Péter. ETH Zurich - EXCLAIM
2222
- Kellerhals, Samuel. ETH Zurich - EXCLAIM
2323
- Kotsalos, Christos. ETH Zurich - CSCS
24+
- Kropiewnicki, Charles. SSAI/NASA-GSFC
2425
- Luz, Magdalena. ETH Zurich - EXCLAIM
2526
- Madonna, Alberto. ETH Zurich - CSCS
2627
- Mariotti, Kean. ETH Zurich - CSCS

src/gt4py/cartesian/stencil_object.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,27 @@ def _validate_args( # Function is too complex
376376
raise ValueError(f"Compute domain contains zero sizes '{domain}')")
377377

378378
if not domain <= (
379-
max_domain := self._get_max_domain(
379+
self._get_max_domain(
380380
arg_infos, self.domain_info, self.field_info, origin, squeeze=False
381381
)
382382
):
383-
raise ValueError(
384-
f"Compute domain too large (provided: {domain}, maximum: {max_domain}. Check stencil domain provided or adjust K interval as needed.)"
383+
offending_fields = []
384+
for name, info in self.field_info.items():
385+
field_used_domain = self._get_max_domain(
386+
arg_infos, self.domain_info, {name: info}, origin, squeeze=False
387+
)
388+
if field_used_domain < domain:
389+
offending_fields.append((name, field_used_domain))
390+
391+
error = ValueError(
392+
f"Compute domain too large for stencil {self.options['name']}: \n"
393+
f" Stencil domain is {domain} but field indexation leads to read outside of bounds.\n"
394+
f" Check region/horizontal offsets or interval/vertical offsets, or stencil domain.\n"
395+
f" Offending fields (name, size with offset removed): {offending_fields}"
385396
)
386397

398+
raise error
399+
387400
if domain[2] < self.domain_info.min_sequential_axis_size:
388401
raise ValueError(
389402
f"Compute domain too small. Sequential axis is {domain[2]}, but must be at least {self.domain_info.min_sequential_axis_size}."

0 commit comments

Comments
 (0)