From 02db061378c66bd0adca06279b3d2cf61e9011b6 Mon Sep 17 00:00:00 2001
From: Frederik Hennig <frederik.hennig@fau.de>
Date: Wed, 24 Jul 2024 17:28:58 +0200
Subject: [PATCH] Some minor internal and API fixes

---
 src/pystencils/__init__.py                       |  2 ++
 src/pystencils/alignedarray.py                   |  9 ++++++---
 src/pystencils/boundaries/boundaryhandling.py    |  9 +++------
 .../datahandling/serial_datahandling.py          |  4 ++--
 src/pystencils/display_utils.py                  | 12 +++++++-----
 src/pystencils/runhelper/db.py                   |  2 +-
 src/pystencils/simplificationfactory.py          |  2 +-
 .../sympyextensions/integer_functions.py         | 16 ----------------
 src/pystencils/utils.py                          |  3 +--
 9 files changed, 23 insertions(+), 36 deletions(-)

diff --git a/src/pystencils/__init__.py b/src/pystencils/__init__.py
index f5cb3e10b..5baf97b6b 100644
--- a/src/pystencils/__init__.py
+++ b/src/pystencils/__init__.py
@@ -19,6 +19,7 @@ from .kernel_decorator import kernel, kernel_config
 from .kernelcreation import create_kernel, create_staggered_kernel
 from .backend.kernelfunction import KernelFunction
 from .backend.jit import no_jit
+from .backend.exceptions import KernelConstraintsError
 from .slicing import make_slice
 from .spatial_coordinates import (
     x_,
@@ -54,6 +55,7 @@ __all__ = [
     "create_kernel",
     "create_staggered_kernel",
     "KernelFunction",
+    "KernelConstraintsError",
     "Target",
     "no_jit",
     "show_code",
diff --git a/src/pystencils/alignedarray.py b/src/pystencils/alignedarray.py
index 63bdb3a5f..4e315af78 100644
--- a/src/pystencils/alignedarray.py
+++ b/src/pystencils/alignedarray.py
@@ -1,3 +1,4 @@
+# flake8: noqa
 import numpy as np
 
 
@@ -17,10 +18,12 @@ def aligned_empty(shape, byte_alignment=True, dtype=np.float64, byte_offset=0, o
         align_inner_coordinate: if True, the start of the innermost coordinate lines are aligned as well
     """
     if byte_alignment is True or byte_alignment == 'cacheline':
-        from pystencils.backends.simd_instruction_sets import (get_supported_instruction_sets, get_cacheline_size,
-                                                               get_vector_instruction_set)
+        # from pystencils.backends.simd_instruction_sets import (get_supported_instruction_sets, get_cacheline_size,
+        #                                                        get_vector_instruction_set)
 
-        instruction_sets = get_supported_instruction_sets()
+        # instruction_sets = get_supported_instruction_sets()
+        #   TODO `get_supported_instruction_sets` has to be reimplemented
+        instruction_sets = None
         if instruction_sets is None:
             byte_alignment = 64
         elif byte_alignment == 'cacheline':
diff --git a/src/pystencils/boundaries/boundaryhandling.py b/src/pystencils/boundaries/boundaryhandling.py
index f171d5609..c7657ec51 100644
--- a/src/pystencils/boundaries/boundaryhandling.py
+++ b/src/pystencils/boundaries/boundaryhandling.py
@@ -36,12 +36,9 @@ class FlagInterface:
         >>> dh = create_data_handling((4, 5))
         >>> fi = FlagInterface(dh, 'flag_field', np.uint8)
         >>> assert dh.has_data('flag_field')
-        >>> fi.reserve_next_flag()
-        2
-        >>> fi.reserve_flag(4)
-        4
-        >>> fi.reserve_next_flag()
-        8
+        >>> assert fi.reserve_next_flag() == 2
+        >>> assert fi.reserve_flag(4) == 4
+        >>> assert fi.reserve_next_flag() == 8
     """
 
     def __init__(self, data_handling, flag_field_name, dtype=DEFAULT_FLAG_TYPE):
diff --git a/src/pystencils/datahandling/serial_datahandling.py b/src/pystencils/datahandling/serial_datahandling.py
index 4eb341df5..ba705f4b9 100644
--- a/src/pystencils/datahandling/serial_datahandling.py
+++ b/src/pystencils/datahandling/serial_datahandling.py
@@ -344,11 +344,11 @@ class SerialDataHandling(DataHandling):
         if target == Target.CPU:
             def result_functor():
                 for arr_name, func in zip(names, result):
-                    func(pdfs=self.cpu_arrays[arr_name])
+                    func(self.cpu_arrays[arr_name])
         else:
             def result_functor():
                 for arr_name, func in zip(names, result):
-                    func(pdfs=self.gpu_arrays[arr_name])
+                    func(self.gpu_arrays[arr_name])
 
         return result_functor
 
diff --git a/src/pystencils/display_utils.py b/src/pystencils/display_utils.py
index 301cdef0f..7f110c9c0 100644
--- a/src/pystencils/display_utils.py
+++ b/src/pystencils/display_utils.py
@@ -9,7 +9,6 @@ from .backend.jit import KernelWrapper
 
 def to_dot(expr: sp.Expr, graph_style: Optional[Dict[str, Any]] = None, short=True):
     """Show a sympy or pystencils AST as dot graph"""
-    from pystencils.sympyextensions.astnodes import Node
     try:
         import graphviz
     except ImportError:
@@ -18,12 +17,15 @@ def to_dot(expr: sp.Expr, graph_style: Optional[Dict[str, Any]] = None, short=Tr
 
     graph_style = {} if graph_style is None else graph_style
 
-    if isinstance(expr, Node):
-        from pystencils.backends.dot import print_dot
-        return graphviz.Source(print_dot(expr, short=short, graph_attr=graph_style))
-    else:
+    # if isinstance(expr, Node):
+    #     from pystencils.backends.dot import print_dot
+    #     return graphviz.Source(print_dot(expr, short=short, graph_attr=graph_style))
+    if isinstance(expr, sp.Basic):
         from sympy.printing.dot import dotprint
         return graphviz.Source(dotprint(expr, graph_attr=graph_style))
+    else:
+        #  TODO Implement dot / graphviz exporter for new backend AST
+        raise NotImplementedError("Printing of AST nodes for the new backend is not implemented yet")
 
 
 def highlight_cpp(code: str):
diff --git a/src/pystencils/runhelper/db.py b/src/pystencils/runhelper/db.py
index 466b9dc14..dd413a5e4 100644
--- a/src/pystencils/runhelper/db.py
+++ b/src/pystencils/runhelper/db.py
@@ -8,7 +8,7 @@ import six
 from blitzdb.backends.file.backend import serializer_classes
 from blitzdb.backends.file.utils import JsonEncoder
 
-from pystencils.cpu.cpujit import get_compiler_config
+from pystencils.backend.jit.legacy_cpu import get_compiler_config
 from pystencils import CreateKernelConfig, Target, Field
 
 import json
diff --git a/src/pystencils/simplificationfactory.py b/src/pystencils/simplificationfactory.py
index 869454ecf..68eb22d59 100644
--- a/src/pystencils/simplificationfactory.py
+++ b/src/pystencils/simplificationfactory.py
@@ -1,4 +1,4 @@
-from pystencils.sympyextensions import (
+from pystencils.simp import (
     SimplificationStrategy,
     insert_constants,
     insert_symbol_times_minus_one,
diff --git a/src/pystencils/sympyextensions/integer_functions.py b/src/pystencils/sympyextensions/integer_functions.py
index 3b215266e..eb3bb4ccc 100644
--- a/src/pystencils/sympyextensions/integer_functions.py
+++ b/src/pystencils/sympyextensions/integer_functions.py
@@ -78,10 +78,6 @@ class modulo_floor(sp.Function):
         8
         >>> modulo_floor(12, 4)
         12
-        >>> from pystencils import TypedSymbol
-        >>> a, b = TypedSymbol("a", "int64"), TypedSymbol("b", "int32")
-        >>> modulo_floor(a, b).to_c(str)
-        '(int64_t)((a) / (b)) * (b)'
     """
     nargs = 2
     is_integer = True
@@ -111,10 +107,6 @@ class modulo_ceil(sp.Function):
         12
         >>> modulo_ceil(12, 4)
         12
-        >>> from pystencils import TypedSymbol
-        >>> a, b = TypedSymbol("a", "int64"), TypedSymbol("b", "int32")
-        >>> modulo_ceil(a, b).to_c(str)
-        '((a) % (b) == 0 ? a : ((int64_t)((a) / (b))+1) * (b))'
     """
     nargs = 2
     is_integer = True
@@ -142,10 +134,6 @@ class div_ceil(sp.Function):
         3
         >>> div_ceil(8, 4)
         2
-        >>> from pystencils import TypedSymbol
-        >>> a, b = TypedSymbol("a", "int64"), TypedSymbol("b", "int32")
-        >>> div_ceil(a, b).to_c(str)
-        '( (a) % (b) == 0 ? (int64_t)(a) / (int64_t)(b) : ( (int64_t)(a) / (int64_t)(b) ) +1 )'
     """
     nargs = 2
     is_integer = True
@@ -173,10 +161,6 @@ class div_floor(sp.Function):
         2
         >>> div_floor(8, 4)
         2
-        >>> from pystencils import TypedSymbol
-        >>> a, b = TypedSymbol("a", "int64"), TypedSymbol("b", "int32")
-        >>> div_floor(a, b).to_c(str)
-        '((int64_t)(a) / (int64_t)(b))'
     """
     nargs = 2
     is_integer = True
diff --git a/src/pystencils/utils.py b/src/pystencils/utils.py
index 98331e7e5..de98e4431 100644
--- a/src/pystencils/utils.py
+++ b/src/pystencils/utils.py
@@ -82,8 +82,7 @@ def boolean_array_bounding_box(boolean_array):
 
     >>> a = np.zeros((4, 4), dtype=bool)
     >>> a[1:-1, 1:-1] = True
-    >>> boolean_array_bounding_box(a)
-    [(1, 3), (1, 3)]
+    >>> assert boolean_array_bounding_box(a) == [(1, 3), (1, 3)]
     """
     dim = boolean_array.ndim
     shape = boolean_array.shape
-- 
GitLab