devito
devito copied to clipboard
Check legality of symbolic derivatives
For example, if we do:
u.biharmonic(1/m)
and m
was not initialized with "sufficient" space order, then OOB accesses will be generated, and segfaults will happen
how to fix: make sure in the DSL layer we always check that we're not applying differential operators to arguments that would result in illegal code
@FabioLuporini, as far as I understood the problem, we could just check deriv_order
and space_order
in evaluate
of Derivative
. The only thing I'm still figuring out is when spacer_order
or deriv_order
is tuple. I'm not sure if this solution has the depth proposed by your hint. Let me know. By the way you mean DSE layer, right?
We could check it in evaluate
or __new__
of Derivative
:
@property
def evaluate(self):
# Evaluate finite-difference.
# Note: evaluate and _eval_fd splitted for potential future different
# types of discretizations.
do = self.deriv_order
if isinstance(do,int): do = (do,)
for i, d in enumerate(self.dims):
expr_order = self.expr.time_order if d.is_Time else self.expr.space_order
if do[i] > expr_order:
raise ValueError("Expression order must be equal or greater than "
"Derivative order")
return self._eval_fd(self.expr)
Here is the MFE I'm testing. If any of the functions have space or time order lower than derivative, the patch will get it.
from devito import (Grid, TimeFunction, Eq, Operator)
grid = Grid(tuple([11]*2))
u = TimeFunction(name="u", grid=grid, space_order=2, time_order=2)
m = TimeFunction(name="m", grid=grid, space_order=1, time_order=1)
# op = Operator(Eq(u.forward,u.biharmonic(1/m)))
# op = Operator(Eq(u.forward,(u * m).dx2))
op = Operator(Eq(u.forward,(u * m).dt2))
op.apply(time=0)