devito
devito copied to clipboard
Additional checks on ConditionalDimension to prevent OOB errors
There are currently limited checks on the validity of TimeFunction
s that use ConditionalDimension
, which can result in OOB errors when running operators that are often difficult to track for users.
This is a Slack conversation with @FabioLuporini about the issue:
If we want to hint the user about a potential user-level error, we should (could) raise one or more warnings at op.arguments
(op.apply
) time through the _arg_check
method. Example: https://github.com/devitocodes/devito/blob/master/devito/types/dense.py#L1418
At op.arguments
time (which, I remind you, is called via op.apply
), _arg_check
is called for each object in op.parameters
to perform, as the name suggests, error checks. The intervals
data structure, which in essence captures the extent of the iteration spaces, is part of its interface and could be used along with the args
values to detect a potential OOB in the case self.time_dim
is a ConditionalDimension
.
The various _arg_check
s perform a number of checks, and we could enhance them if we think it might be of help here. The only catch here is that I don’t know whether intervals
provides sufficient information.
what I have in mind:
- let
self
be aTimeFunction
over aConditionalDimension
with factorF
- if
intervals[self.time_dim]
returns something likeA = (1, 1)
- and we calculate from
args
that the time iteration extent isX
( ==time_M - time_m + 1
) - and see that
self.shape_allocated[self.time_dim]
isY
- at this point, if
(X + A.right + A.left) / F >= Y
(aka(X + 2) / F >= Y
), then we will have an OOB at runtime (probably needs some mod/max/min to make sure to handle the bounds of the formula correctly), and we should raise a warning or even anInvalidArgument
exception (if we are absolutely certain this is an error)