Skip to content

Check legality of symbolic derivatives #1578

Description

@FabioLuporini

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

Activity

  1. changed the title [-]Check legaly of symbolic derivatives[/-] [+]Check legality of symbolic derivatives[/+] on Feb 18, 2021
  2. self-assigned this
    on Feb 18, 2021
  3. Leitevmd commented on Feb 19, 2021

    @Leitevmd
    Contributor

    @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?

  4. Leitevmd commented on Feb 19, 2021

    @Leitevmd
    Contributor

    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)
  5. added a commit that references this issue on Feb 24, 2021
  6. added a commit that references this issue on Mar 22, 2021
  7. FabioLuporini commented on Jul 29, 2025

    @FabioLuporini
    ContributorAuthor

    this was fixed several months by this commit: cf85b06

    hence, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions