From 6208a699c01301dc621f9607c1cacbd136538851 Mon Sep 17 00:00:00 2001 From: ZoeLeibowitz Date: Wed, 4 Sep 2024 22:54:35 +0100 Subject: [PATCH] misc: Clean up --- devito/ir/iet/nodes.py | 2 ++ devito/petsc/iet/routines.py | 13 ++++++++----- devito/petsc/types/array.py | 3 +-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/devito/ir/iet/nodes.py b/devito/ir/iet/nodes.py index 0d4f215a9d..cda23d4fbd 100644 --- a/devito/ir/iet/nodes.py +++ b/devito/ir/iet/nodes.py @@ -1,6 +1,7 @@ """The Iteration/Expression Tree (IET) hierarchy.""" import abc +import ctypes import inspect from functools import cached_property from collections import OrderedDict, namedtuple @@ -1059,6 +1060,7 @@ def functions(self): def expr_symbols(self): ret = [] if self.pointer.is_Object: + assert issubclass(self.pointer._C_ctype, ctypes._Pointer) ret.extend([self.pointer._C_symbol, self.pointee._C_symbol]) elif self.pointer.is_PointerArray or self.pointer.is_TempFunction: ret.extend([self.pointer.indexed, self.pointee.indexed]) diff --git a/devito/petsc/iet/routines.py b/devito/petsc/iet/routines.py index 84c2d71112..eaa1f12fc1 100644 --- a/devito/petsc/iet/routines.py +++ b/devito/petsc/iet/routines.py @@ -138,11 +138,13 @@ def create_matvec_body(self, injectsolve, body, solver_objs, objs): dmda, solver_objs['Y_local'], 'INSERT_VALUES', solver_objs['Y_global'] ]) - # NOTE: Question: I have placed a chunk of the calls in the `stacks` argument - # of the `CallableBody` to ensure that these calls precede the `cast` statements. - # The 'casts' depend on the calls, so this order is necessary. By doing this, - # I avoid having to manually construct the 'casts' and can allow Devito to handle - # their construction. Are there any potential issues with this approach? + # TODO: Some of the calls are placed in the `stacks` argument of the + # `CallableBody` to ensure that they precede the `cast` statements. The + # 'casts' depend on the calls, so this order is necessary. By doing this, + # you avoid having to manually construct the `casts` and can allow + # Devito to handle their construction. This is a temporary solution and + # should be revisited + body = [body, vec_restore_array_y, vec_restore_array_x, @@ -402,6 +404,7 @@ def runsolve(self, solver_objs, objs, rhs_callback, injectsolve): def build_petsc_struct(iet, name, liveness): # Place all context data required by the shell routines into a struct + # TODO: Clean this search up basics = FindSymbols('basics').visit(iet) avoid0 = [i for i in FindSymbols('indexedbases').visit(iet) if isinstance(i.function, PETScArray)] diff --git a/devito/petsc/types/array.py b/devito/petsc/types/array.py index 0e71ca2e06..a150ea3247 100644 --- a/devito/petsc/types/array.py +++ b/devito/petsc/types/array.py @@ -16,8 +16,7 @@ class PETScArray(ArrayBasic, Differentiable): """ PETScArrays are generated by the compiler only and represent - a customised variant of ArrayBasic. They are designed to - avoid generating a cast in the low-level code. + a customised variant of ArrayBasic. Differentiable enables compatability with standard Function objects, allowing for the use of the `subs` method. TODO: Potentially re-evaluate and separate into PETScFunction(Differentiable)