devito icon indicating copy to clipboard operation
devito copied to clipboard

Additional checks on ConditionalDimension to prevent OOB errors

Open ccuetom opened this issue 1 year ago • 0 comments

There are currently limited checks on the validity of TimeFunctions 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 a TimeFunction over a ConditionalDimension with factor F
  • if intervals[self.time_dim] returns something like A = (1, 1)
  • and we calculate from args that the time iteration extent is X ( == time_M - time_m + 1)
  • and see that self.shape_allocated[self.time_dim] is Y
  • 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 an InvalidArgument exception (if we are absolutely certain this is an error)

ccuetom avatar Jun 26 '23 10:06 ccuetom