From c8a7c75aa1470fc48cd032583efa8cf3235dcec1 Mon Sep 17 00:00:00 2001 From: Frederik Hennig <frederik.hennig@fau.de> Date: Tue, 23 Jul 2024 13:53:10 +0200 Subject: [PATCH] migrate test suite --- .../test_base_pointer_specification.py | 0 tests/{ => _old}/test_config.py | 0 tests/{ => _old}/test_create_kernel_config.py | 0 tests/{ => _old}/test_global_definitions.py | 0 tests/{ => _old}/test_jacobi_cbackend.py | 0 tests/{ => _old}/test_json_backend.py | 0 tests/{ => _old}/test_json_serializer.py | 0 .../test_move_constant_before_loop.py | 0 tests/{ => _old}/test_printing.py | 0 tests/{ => _old}/test_source_code_comment.py | 0 tests/{ => _old}/test_transformations.py | 0 tests/{ => _old}/test_type_interference.py | 0 tests/{ => _old}/test_types.py | 0 tests/{ => _todo}/test_conditional_vec.py | 0 tests/{ => _todo}/test_dot_printer.ipynb | 0 tests/{ => _todo}/test_dot_printer.py | 0 tests/{ => _todo}/test_fvm.py | 4 +- tests/{ => _todo}/test_indexed_kernels.py | 33 ----- tests/{ => _todo}/test_loop_cutting.py | 0 tests/{ => _todo}/test_modulo.py | 0 tests/{ => _todo}/test_random.py | 0 tests/{ => _todo}/test_vectorization.py | 0 .../test_vectorization_specific.py | 0 .../test_phasefield_dentritic_3D.ipynb | 0 tests/{ => fd}/test_derivative.py | 0 tests/{ => fd}/test_fd_derivation.ipynb | 0 .../test_fd_derivation_via_rotation.ipynb | 0 tests/{ => fd}/test_fd_derivative.py | 0 tests/{ => fd}/test_finite_differences.py | 0 tests/{symbolics => frontend}/test_Min_Max.py | 0 tests/{symbolics => frontend}/test_abs.py | 0 .../test_address_of.py | 0 .../test_assignment_collection.py | 44 +++++-- .../test_assignments.py} | 22 ++++ tests/{ => frontend}/test_bit_masks.py | 2 + .../test_conditional_field_access.py | 0 .../{ => frontend}/test_fast_approximation.py | 2 + tests/{ => frontend}/test_field.py | 2 +- .../{ => frontend}/test_field_access_poly.py | 0 .../{ => frontend}/test_field_equality.ipynb | 0 .../test_floor_ceil_int_optimization.py | 0 ...st_match_subs_for_assignment_collection.py | 0 tests/{ => frontend}/test_pickle_support.py | 0 .../test_simplification_strategy.py | 5 +- tests/{ => frontend}/test_simplifications.py | 47 ++++---- tests/{ => frontend}/test_stencils.py | 0 .../test_subexpression_insertion.py | 0 tests/{ => frontend}/test_sympyextensions.py | 0 .../test_typed_sympy.py | 0 tests/{ => frontend}/test_utils.py | 0 tests/{ => kernelcreation}/test_blocking.py | 4 + .../test_blocking_staggered.py | 2 + tests/{ => kernelcreation}/test_buffer.py | 3 +- tests/{ => kernelcreation}/test_buffer_gpu.py | 44 +++---- .../kernelcreation/test_domain_kernels.py | 0 .../test_functions.py | 45 ++++++- .../{nbackend => }/kernelcreation/test_gpu.py | 5 +- .../test_half_precision.py | 0 .../kernelcreation/test_index_kernels.py | 0 tests/kernelcreation/test_kernel_decorator.py | 32 +++++ tests/{ => kernelcreation}/test_logarithm.py | 2 +- .../test_size_and_layout_checks.py | 7 ++ .../test_sliced_iteration.py | 3 + .../test_staggered_kernel.py | 4 + tests/kernelcreation/test_struct_types.py | 49 ++++++++ tests/{ => kernelcreation}/test_sum_prod.py | 6 +- tests/{ => runtime}/test_aligned_array.py | 3 + tests/{ => runtime}/test_boundary.py | 0 .../test_boundary_indexlist_creation.py | 0 .../test_cpu_jit.py} | 17 ++- .../test_data/datahandling_load_test.npz | Bin .../datahandling_parallel_load_test/dst.dat | Bin .../datahandling_parallel_load_test/src.dat | Bin .../datahandling_parallel_save_test/dst.dat | Bin .../datahandling_parallel_save_test/src.dat | Bin .../test_data/datahandling_save_test.npz | Bin 0 -> 428 bytes tests/{ => runtime}/test_data/lenna.png | Bin .../test_data/test_vessel2d_mask.png | Bin tests/{ => runtime}/test_datahandling.py | 2 + .../test_datahandling_parallel.py | 2 +- .../test_jupyter_extensions.ipynb | 0 tests/{ => runtime}/test_parameterstudy.py | 7 ++ tests/{ => runtime}/test_plot.py | 0 tests/{ => runtime}/test_sharedmethodcache.py | 0 tests/{ => runtime}/test_slicing.py | 0 .../test_small_block_benchmark.ipynb | 0 tests/{ => runtime}/test_stencil_plot.ipynb | 0 tests/{ => runtime}/test_timeloop.py | 0 ...t_assignment_collection_dict_conversion.py | 32 ----- tests/test_assignment_from_stencil.py | 22 ---- tests/test_data/datahandling_save_test.npz | Bin 410 -> 0 bytes tests/test_math_functions.py | 113 ------------------ tests/test_quicktests.py | 5 +- tests/test_struct_types.py | 44 ------- tests/{nbackend => }/types/__init__.py | 0 tests/{nbackend => }/types/test_types.py | 0 96 files changed, 289 insertions(+), 325 deletions(-) rename tests/{ => _old}/test_base_pointer_specification.py (100%) rename tests/{ => _old}/test_config.py (100%) rename tests/{ => _old}/test_create_kernel_config.py (100%) rename tests/{ => _old}/test_global_definitions.py (100%) rename tests/{ => _old}/test_jacobi_cbackend.py (100%) rename tests/{ => _old}/test_json_backend.py (100%) rename tests/{ => _old}/test_json_serializer.py (100%) rename tests/{ => _old}/test_move_constant_before_loop.py (100%) rename tests/{ => _old}/test_printing.py (100%) rename tests/{ => _old}/test_source_code_comment.py (100%) rename tests/{ => _old}/test_transformations.py (100%) rename tests/{ => _old}/test_type_interference.py (100%) rename tests/{ => _old}/test_types.py (100%) rename tests/{ => _todo}/test_conditional_vec.py (100%) rename tests/{ => _todo}/test_dot_printer.ipynb (100%) rename tests/{ => _todo}/test_dot_printer.py (100%) rename tests/{ => _todo}/test_fvm.py (99%) rename tests/{ => _todo}/test_indexed_kernels.py (63%) rename tests/{ => _todo}/test_loop_cutting.py (100%) rename tests/{ => _todo}/test_modulo.py (100%) rename tests/{ => _todo}/test_random.py (100%) rename tests/{ => _todo}/test_vectorization.py (100%) rename tests/{ => _todo}/test_vectorization_specific.py (100%) rename tests/{ => apps}/test_phasefield_dentritic_3D.ipynb (100%) rename tests/{ => fd}/test_derivative.py (100%) rename tests/{ => fd}/test_fd_derivation.ipynb (100%) rename tests/{ => fd}/test_fd_derivation_via_rotation.ipynb (100%) rename tests/{ => fd}/test_fd_derivative.py (100%) rename tests/{ => fd}/test_finite_differences.py (100%) rename tests/{symbolics => frontend}/test_Min_Max.py (100%) rename tests/{symbolics => frontend}/test_abs.py (100%) rename tests/{symbolics => frontend}/test_address_of.py (100%) rename tests/{ => frontend}/test_assignment_collection.py (82%) rename tests/{test_augmented_assignment.py => frontend/test_assignments.py} (60%) rename tests/{ => frontend}/test_bit_masks.py (94%) rename tests/{symbolics => frontend}/test_conditional_field_access.py (100%) rename tests/{ => frontend}/test_fast_approximation.py (91%) rename tests/{ => frontend}/test_field.py (99%) rename tests/{ => frontend}/test_field_access_poly.py (100%) rename tests/{ => frontend}/test_field_equality.ipynb (100%) rename tests/{ => frontend}/test_floor_ceil_int_optimization.py (100%) rename tests/{ => frontend}/test_match_subs_for_assignment_collection.py (100%) rename tests/{ => frontend}/test_pickle_support.py (100%) rename tests/{ => frontend}/test_simplification_strategy.py (96%) rename tests/{ => frontend}/test_simplifications.py (82%) rename tests/{ => frontend}/test_stencils.py (100%) rename tests/{ => frontend}/test_subexpression_insertion.py (100%) rename tests/{ => frontend}/test_sympyextensions.py (100%) rename tests/{symbolics => frontend}/test_typed_sympy.py (100%) rename tests/{ => frontend}/test_utils.py (100%) rename tests/{ => kernelcreation}/test_blocking.py (92%) rename tests/{ => kernelcreation}/test_blocking_staggered.py (89%) rename tests/{ => kernelcreation}/test_buffer.py (99%) rename tests/{ => kernelcreation}/test_buffer_gpu.py (91%) rename tests/{nbackend => }/kernelcreation/test_domain_kernels.py (100%) rename tests/{nbackend => kernelcreation}/test_functions.py (67%) rename tests/{nbackend => }/kernelcreation/test_gpu.py (98%) rename tests/{ => kernelcreation}/test_half_precision.py (100%) rename tests/{nbackend => }/kernelcreation/test_index_kernels.py (100%) create mode 100644 tests/kernelcreation/test_kernel_decorator.py rename tests/{ => kernelcreation}/test_logarithm.py (89%) rename tests/{ => kernelcreation}/test_size_and_layout_checks.py (94%) rename tests/{ => kernelcreation}/test_sliced_iteration.py (97%) rename tests/{ => kernelcreation}/test_staggered_kernel.py (93%) create mode 100644 tests/kernelcreation/test_struct_types.py rename tests/{ => kernelcreation}/test_sum_prod.py (92%) rename tests/{ => runtime}/test_aligned_array.py (97%) rename tests/{ => runtime}/test_boundary.py (100%) rename tests/{ => runtime}/test_boundary_indexlist_creation.py (100%) rename tests/{test_dtype_check.py => runtime/test_cpu_jit.py} (53%) rename tests/{ => runtime}/test_data/datahandling_load_test.npz (100%) rename tests/{ => runtime}/test_data/datahandling_parallel_load_test/dst.dat (100%) rename tests/{ => runtime}/test_data/datahandling_parallel_load_test/src.dat (100%) rename tests/{ => runtime}/test_data/datahandling_parallel_save_test/dst.dat (100%) rename tests/{ => runtime}/test_data/datahandling_parallel_save_test/src.dat (100%) create mode 100644 tests/runtime/test_data/datahandling_save_test.npz rename tests/{ => runtime}/test_data/lenna.png (100%) rename tests/{ => runtime}/test_data/test_vessel2d_mask.png (100%) rename tests/{ => runtime}/test_datahandling.py (99%) rename tests/{ => runtime}/test_datahandling_parallel.py (99%) rename tests/{ => runtime}/test_jupyter_extensions.ipynb (100%) rename tests/{ => runtime}/test_parameterstudy.py (95%) rename tests/{ => runtime}/test_plot.py (100%) rename tests/{ => runtime}/test_sharedmethodcache.py (100%) rename tests/{ => runtime}/test_slicing.py (100%) rename tests/{ => runtime}/test_small_block_benchmark.ipynb (100%) rename tests/{ => runtime}/test_stencil_plot.ipynb (100%) rename tests/{ => runtime}/test_timeloop.py (100%) delete mode 100644 tests/test_assignment_collection_dict_conversion.py delete mode 100644 tests/test_assignment_from_stencil.py delete mode 100644 tests/test_data/datahandling_save_test.npz delete mode 100644 tests/test_math_functions.py delete mode 100644 tests/test_struct_types.py rename tests/{nbackend => }/types/__init__.py (100%) rename tests/{nbackend => }/types/test_types.py (100%) diff --git a/tests/test_base_pointer_specification.py b/tests/_old/test_base_pointer_specification.py similarity index 100% rename from tests/test_base_pointer_specification.py rename to tests/_old/test_base_pointer_specification.py diff --git a/tests/test_config.py b/tests/_old/test_config.py similarity index 100% rename from tests/test_config.py rename to tests/_old/test_config.py diff --git a/tests/test_create_kernel_config.py b/tests/_old/test_create_kernel_config.py similarity index 100% rename from tests/test_create_kernel_config.py rename to tests/_old/test_create_kernel_config.py diff --git a/tests/test_global_definitions.py b/tests/_old/test_global_definitions.py similarity index 100% rename from tests/test_global_definitions.py rename to tests/_old/test_global_definitions.py diff --git a/tests/test_jacobi_cbackend.py b/tests/_old/test_jacobi_cbackend.py similarity index 100% rename from tests/test_jacobi_cbackend.py rename to tests/_old/test_jacobi_cbackend.py diff --git a/tests/test_json_backend.py b/tests/_old/test_json_backend.py similarity index 100% rename from tests/test_json_backend.py rename to tests/_old/test_json_backend.py diff --git a/tests/test_json_serializer.py b/tests/_old/test_json_serializer.py similarity index 100% rename from tests/test_json_serializer.py rename to tests/_old/test_json_serializer.py diff --git a/tests/test_move_constant_before_loop.py b/tests/_old/test_move_constant_before_loop.py similarity index 100% rename from tests/test_move_constant_before_loop.py rename to tests/_old/test_move_constant_before_loop.py diff --git a/tests/test_printing.py b/tests/_old/test_printing.py similarity index 100% rename from tests/test_printing.py rename to tests/_old/test_printing.py diff --git a/tests/test_source_code_comment.py b/tests/_old/test_source_code_comment.py similarity index 100% rename from tests/test_source_code_comment.py rename to tests/_old/test_source_code_comment.py diff --git a/tests/test_transformations.py b/tests/_old/test_transformations.py similarity index 100% rename from tests/test_transformations.py rename to tests/_old/test_transformations.py diff --git a/tests/test_type_interference.py b/tests/_old/test_type_interference.py similarity index 100% rename from tests/test_type_interference.py rename to tests/_old/test_type_interference.py diff --git a/tests/test_types.py b/tests/_old/test_types.py similarity index 100% rename from tests/test_types.py rename to tests/_old/test_types.py diff --git a/tests/test_conditional_vec.py b/tests/_todo/test_conditional_vec.py similarity index 100% rename from tests/test_conditional_vec.py rename to tests/_todo/test_conditional_vec.py diff --git a/tests/test_dot_printer.ipynb b/tests/_todo/test_dot_printer.ipynb similarity index 100% rename from tests/test_dot_printer.ipynb rename to tests/_todo/test_dot_printer.ipynb diff --git a/tests/test_dot_printer.py b/tests/_todo/test_dot_printer.py similarity index 100% rename from tests/test_dot_printer.py rename to tests/_todo/test_dot_printer.py diff --git a/tests/test_fvm.py b/tests/_todo/test_fvm.py similarity index 99% rename from tests/test_fvm.py rename to tests/_todo/test_fvm.py index 0b103e525..78c767b58 100644 --- a/tests/test_fvm.py +++ b/tests/_todo/test_fvm.py @@ -4,8 +4,8 @@ import numpy as np import pytest from itertools import product from pystencils.rng import random_symbol -from pystencils.sympyextensions.astnodes import SympyAssignment -from pystencils.node_collection import NodeCollection +# from pystencils.sympyextensions.astnodes import SympyAssignment +# from pystencils.node_collection import NodeCollection def advection_diffusion(dim: int): diff --git a/tests/test_indexed_kernels.py b/tests/_todo/test_indexed_kernels.py similarity index 63% rename from tests/test_indexed_kernels.py rename to tests/_todo/test_indexed_kernels.py index 2c0738dcf..bfaa1c080 100644 --- a/tests/test_indexed_kernels.py +++ b/tests/_todo/test_indexed_kernels.py @@ -8,39 +8,6 @@ from pystencils.transformations import filtered_tree_iteration from pystencils.typing import BasicType, FieldPointerSymbol, PointerType, TypedSymbol -@pytest.mark.parametrize('target', [ps.Target.CPU, ps.Target.GPU]) -def test_indexed_kernel(target): - if target == Target.GPU: - pytest.importorskip("cupy") - import cupy as cp - - arr = np.zeros((3, 4)) - dtype = np.dtype([('x', int), ('y', int), ('value', arr.dtype)]) - index_arr = np.zeros((3,), dtype=dtype) - index_arr[0] = (0, 2, 3.0) - index_arr[1] = (1, 3, 42.0) - index_arr[2] = (2, 1, 5.0) - - indexed_field = Field.create_from_numpy_array('index', index_arr) - normal_field = Field.create_from_numpy_array('f', arr) - update_rule = Assignment(normal_field[0, 0], indexed_field('value')) - - config = CreateKernelConfig(target=target, index_fields=[indexed_field]) - ast = create_kernel([update_rule], config=config) - kernel = ast.compile() - - if target == Target.CPU: - kernel(f=arr, index=index_arr) - else: - gpu_arr = cp.asarray(arr) - gpu_index_arr = cp.ndarray(index_arr.shape, dtype=index_arr.dtype) - gpu_index_arr.set(index_arr) - kernel(f=gpu_arr, index=gpu_index_arr) - arr = gpu_arr.get() - for i in range(index_arr.shape[0]): - np.testing.assert_allclose(arr[index_arr[i]['x'], index_arr[i]['y']], index_arr[i]['value'], atol=1e-13) - - @pytest.mark.parametrize('index_size', ("fixed", "variable")) @pytest.mark.parametrize('array_size', ("3D", "2D", "10, 12", "13, 17, 19")) @pytest.mark.parametrize('target', (ps.Target.CPU, ps.Target.GPU)) diff --git a/tests/test_loop_cutting.py b/tests/_todo/test_loop_cutting.py similarity index 100% rename from tests/test_loop_cutting.py rename to tests/_todo/test_loop_cutting.py diff --git a/tests/test_modulo.py b/tests/_todo/test_modulo.py similarity index 100% rename from tests/test_modulo.py rename to tests/_todo/test_modulo.py diff --git a/tests/test_random.py b/tests/_todo/test_random.py similarity index 100% rename from tests/test_random.py rename to tests/_todo/test_random.py diff --git a/tests/test_vectorization.py b/tests/_todo/test_vectorization.py similarity index 100% rename from tests/test_vectorization.py rename to tests/_todo/test_vectorization.py diff --git a/tests/test_vectorization_specific.py b/tests/_todo/test_vectorization_specific.py similarity index 100% rename from tests/test_vectorization_specific.py rename to tests/_todo/test_vectorization_specific.py diff --git a/tests/test_phasefield_dentritic_3D.ipynb b/tests/apps/test_phasefield_dentritic_3D.ipynb similarity index 100% rename from tests/test_phasefield_dentritic_3D.ipynb rename to tests/apps/test_phasefield_dentritic_3D.ipynb diff --git a/tests/test_derivative.py b/tests/fd/test_derivative.py similarity index 100% rename from tests/test_derivative.py rename to tests/fd/test_derivative.py diff --git a/tests/test_fd_derivation.ipynb b/tests/fd/test_fd_derivation.ipynb similarity index 100% rename from tests/test_fd_derivation.ipynb rename to tests/fd/test_fd_derivation.ipynb diff --git a/tests/test_fd_derivation_via_rotation.ipynb b/tests/fd/test_fd_derivation_via_rotation.ipynb similarity index 100% rename from tests/test_fd_derivation_via_rotation.ipynb rename to tests/fd/test_fd_derivation_via_rotation.ipynb diff --git a/tests/test_fd_derivative.py b/tests/fd/test_fd_derivative.py similarity index 100% rename from tests/test_fd_derivative.py rename to tests/fd/test_fd_derivative.py diff --git a/tests/test_finite_differences.py b/tests/fd/test_finite_differences.py similarity index 100% rename from tests/test_finite_differences.py rename to tests/fd/test_finite_differences.py diff --git a/tests/symbolics/test_Min_Max.py b/tests/frontend/test_Min_Max.py similarity index 100% rename from tests/symbolics/test_Min_Max.py rename to tests/frontend/test_Min_Max.py diff --git a/tests/symbolics/test_abs.py b/tests/frontend/test_abs.py similarity index 100% rename from tests/symbolics/test_abs.py rename to tests/frontend/test_abs.py diff --git a/tests/symbolics/test_address_of.py b/tests/frontend/test_address_of.py similarity index 100% rename from tests/symbolics/test_address_of.py rename to tests/frontend/test_address_of.py diff --git a/tests/test_assignment_collection.py b/tests/frontend/test_assignment_collection.py similarity index 82% rename from tests/test_assignment_collection.py rename to tests/frontend/test_assignment_collection.py index 797465eca..c1319acf3 100644 --- a/tests/test_assignment_collection.py +++ b/tests/frontend/test_assignment_collection.py @@ -3,8 +3,7 @@ import sympy as sp import pystencils as ps from pystencils import Assignment, AssignmentCollection -from pystencils.sympyextensions.astnodes import Conditional -from pystencils.sympyextensions import SymbolGen +from pystencils.simp.assignment_collection import SymbolGen a, b, c = sp.symbols("a b c") x, y, z, t = sp.symbols("x y z t") @@ -35,12 +34,12 @@ def test_assignment_collection(): assert '<table' in ac_inserted._repr_html_() -def test_free_and_defined_symbols(): - ac = AssignmentCollection([Assignment(z, x + y), Conditional(t > 0, Assignment(a, b+1), Assignment(a, b+2))], - [], subexpression_symbol_generator=symbol_gen) +# def test_free_and_defined_symbols(): +# ac = AssignmentCollection([Assignment(z, x + y), Conditional(t > 0, Assignment(a, b+1), Assignment(a, b+2))], +# [], subexpression_symbol_generator=symbol_gen) - print(ac) - print(ac.__repr__) +# print(ac) +# print(ac.__repr__) def test_vector_assignments(): @@ -186,3 +185,34 @@ def test_new_merged(): assert ps.Assignment(f[0, 0](0), 20) in merged_ac.main_assignments assert ps.Assignment(d[0, 0](0), 10) in merged_ac.main_assignments + + +def test_assignment_collection_dict_conversion(): + x, y = ps.fields('x,y: [2D]') + + collection_normal = ps.AssignmentCollection( + [ps.Assignment(x.center(), y[1, 0] + y[0, 0])], + [] + ) + collection_dict = ps.AssignmentCollection( + {x.center(): y[1, 0] + y[0, 0]}, + {} + ) + assert str(collection_normal) == str(collection_dict) + assert collection_dict.main_assignments_dict == {x.center(): y[1, 0] + y[0, 0]} + assert collection_dict.subexpressions_dict == {} + + collection_normal = ps.AssignmentCollection( + [ps.Assignment(y[1, 0], x.center()), + ps.Assignment(y[0, 0], x.center())], + [] + ) + collection_dict = ps.AssignmentCollection( + {y[1, 0]: x.center(), + y[0, 0]: x.center()}, + {} + ) + assert str(collection_normal) == str(collection_dict) + assert collection_dict.main_assignments_dict == {y[1, 0]: x.center(), + y[0, 0]: x.center()} + assert collection_dict.subexpressions_dict == {} diff --git a/tests/test_augmented_assignment.py b/tests/frontend/test_assignments.py similarity index 60% rename from tests/test_augmented_assignment.py rename to tests/frontend/test_assignments.py index 43fa7e8e1..4377386a1 100644 --- a/tests/test_augmented_assignment.py +++ b/tests/frontend/test_assignments.py @@ -1,5 +1,27 @@ +import numpy as np import pytest + import pystencils as ps +from pystencils.assignment import assignment_from_stencil + + +def test_assignment_from_stencil(): + + stencil = [ + [0, 0, 4, 1, 0, 0, 0], + [0, 0, 0, 2, 0, 0, 0], + [0, 0, 0, 3, 0, 0, 0] + ] + + x, y = ps.fields('x, y: [2D]') + + assignment = assignment_from_stencil(stencil, x, y) + assert isinstance(assignment, ps.Assignment) + assert assignment.rhs == x[0, 1] + 4 * x[-1, 1] + 2 * x[0, 0] + 3 * x[0, -1] + + assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) + assert isinstance(assignment, ps.Assignment) + @pytest.mark.parametrize('target', [ps.Target.CPU, ps.Target.GPU]) diff --git a/tests/test_bit_masks.py b/tests/frontend/test_bit_masks.py similarity index 94% rename from tests/test_bit_masks.py rename to tests/frontend/test_bit_masks.py index 3844a7a9f..6c8d6e85e 100644 --- a/tests/test_bit_masks.py +++ b/tests/frontend/test_bit_masks.py @@ -7,7 +7,9 @@ from pystencils.sympyextensions.bit_masks import flag_cond @pytest.mark.parametrize('mask_type', [np.uint8, np.uint16, np.uint32, np.uint64]) +@pytest.mark.xfail(reason="Bit masks not yet supported by the new backend") def test_flag_condition(mask_type): + f_arr = np.zeros((2, 2, 2), dtype=np.float64) mask_arr = np.zeros((2, 2), dtype=mask_type) diff --git a/tests/symbolics/test_conditional_field_access.py b/tests/frontend/test_conditional_field_access.py similarity index 100% rename from tests/symbolics/test_conditional_field_access.py rename to tests/frontend/test_conditional_field_access.py diff --git a/tests/test_fast_approximation.py b/tests/frontend/test_fast_approximation.py similarity index 91% rename from tests/test_fast_approximation.py rename to tests/frontend/test_fast_approximation.py index 375bcabac..4238d93f9 100644 --- a/tests/test_fast_approximation.py +++ b/tests/frontend/test_fast_approximation.py @@ -6,6 +6,7 @@ from pystencils.sympyextensions.fast_approximation import ( fast_division, fast_inv_sqrt, fast_sqrt, insert_fast_divisions, insert_fast_sqrts) +@pytest.mark.xfail(reason="Fast approximations are not implemented yet") def test_fast_sqrt(): pytest.importorskip('cupy') f, g = ps.fields("f, g: double[2D]") @@ -29,6 +30,7 @@ def test_fast_sqrt(): assert '__frsqrt_rn' in code_str +@pytest.mark.xfail(reason="Fast approximations are not implemented yet") def test_fast_divisions(): pytest.importorskip('cupy') f, g = ps.fields("f, g: double[2D]") diff --git a/tests/test_field.py b/tests/frontend/test_field.py similarity index 99% rename from tests/test_field.py rename to tests/frontend/test_field.py index 3e2c86060..6cd1c223d 100644 --- a/tests/test_field.py +++ b/tests/frontend/test_field.py @@ -57,7 +57,7 @@ def test_field_basic(): def test_error_handling(): - struct_dtype = np.dtype([('a', np.int32), ('b', np.float64), ('c', np.uint32)]) + struct_dtype = np.dtype([('a', np.int32), ('b', np.float64), ('c', np.uint32)], align=True) Field.create_generic('f', spatial_dimensions=2, index_dimensions=0, dtype=struct_dtype) with pytest.raises(ValueError) as e: Field.create_generic('f', spatial_dimensions=2, index_dimensions=1, dtype=struct_dtype) diff --git a/tests/test_field_access_poly.py b/tests/frontend/test_field_access_poly.py similarity index 100% rename from tests/test_field_access_poly.py rename to tests/frontend/test_field_access_poly.py diff --git a/tests/test_field_equality.ipynb b/tests/frontend/test_field_equality.ipynb similarity index 100% rename from tests/test_field_equality.ipynb rename to tests/frontend/test_field_equality.ipynb diff --git a/tests/test_floor_ceil_int_optimization.py b/tests/frontend/test_floor_ceil_int_optimization.py similarity index 100% rename from tests/test_floor_ceil_int_optimization.py rename to tests/frontend/test_floor_ceil_int_optimization.py diff --git a/tests/test_match_subs_for_assignment_collection.py b/tests/frontend/test_match_subs_for_assignment_collection.py similarity index 100% rename from tests/test_match_subs_for_assignment_collection.py rename to tests/frontend/test_match_subs_for_assignment_collection.py diff --git a/tests/test_pickle_support.py b/tests/frontend/test_pickle_support.py similarity index 100% rename from tests/test_pickle_support.py rename to tests/frontend/test_pickle_support.py diff --git a/tests/test_simplification_strategy.py b/tests/frontend/test_simplification_strategy.py similarity index 96% rename from tests/test_simplification_strategy.py rename to tests/frontend/test_simplification_strategy.py index b23fcd1c7..8edfa40f2 100644 --- a/tests/test_simplification_strategy.py +++ b/tests/frontend/test_simplification_strategy.py @@ -1,8 +1,9 @@ import sympy as sp +import pytest import pystencils as ps from pystencils import Assignment, AssignmentCollection -from pystencils.sympyextensions import ( +from pystencils.simp import ( SimplificationStrategy, apply_on_all_subexpressions, subexpression_substitution_in_existing_subexpressions) @@ -47,6 +48,8 @@ def test_simplification_strategy(): def test_split_inner_loop(): + pytest.skip("Loop splitting not implemented yet") + dst = ps.fields('dst(8): double[2D]') s = sp.symbols('s_:8') x = sp.symbols('x') diff --git a/tests/test_simplifications.py b/tests/frontend/test_simplifications.py similarity index 82% rename from tests/test_simplifications.py rename to tests/frontend/test_simplifications.py index 9c7c1edc4..5e1bcb8ed 100644 --- a/tests/test_simplifications.py +++ b/tests/frontend/test_simplifications.py @@ -6,7 +6,7 @@ import sympy as sp import pystencils as ps from pystencils import Assignment, AssignmentCollection, fields -from pystencils.sympyextensions.simplifications import ( +from pystencils.simp import ( subexpression_substitution_in_main_assignments, add_subexpressions_for_divisions, add_subexpressions_for_sums, @@ -150,34 +150,35 @@ def test_add_subexpressions_for_field_reads(): assert ac3.subexpressions[0].lhs.dtype == create_type("float32") -@pytest.mark.parametrize('target', (ps.Target.CPU, ps.Target.GPU)) -@pytest.mark.parametrize('dtype', ('float32', 'float64')) -@pytest.mark.skipif((vs.major, vs.minor, vs.micro) == (3, 8, 2), reason="does not work on python 3.8.2 for some reason") -def test_sympy_optimizations(target, dtype): - if target == ps.Target.GPU: - pytest.importorskip("cupy") - src, dst = ps.fields(f'src, dst: {dtype}[2d]') +# TODO: What does this test mean to accomplish? +# @pytest.mark.parametrize('target', (ps.Target.CPU, ps.Target.GPU)) +# @pytest.mark.parametrize('dtype', ('float32', 'float64')) +# @pytest.mark.skipif((vs.major, vs.minor, vs.micro) == (3, 8, 2), reason="does not work on python 3.8.2 for some reason") +# def test_sympy_optimizations(target, dtype): +# if target == ps.Target.GPU: +# pytest.importorskip("cupy") +# src, dst = ps.fields(f'src, dst: {dtype}[2d]') - assignments = ps.AssignmentCollection({ - src[0, 0]: 1.0 * (sp.exp(dst[0, 0]) - 1) - }) +# assignments = ps.AssignmentCollection({ +# src[0, 0]: 1.0 * (sp.exp(dst[0, 0]) - 1) +# }) - config = pystencils.config.CreateKernelConfig(target=target, default_dtype=dtype) - ast = ps.create_kernel(assignments, config=config) +# config = pystencils.config.CreateKernelConfig(target=target, default_dtype=dtype) +# ast = ps.create_kernel(assignments, config=config) - ps.show_code(ast) +# ps.show_code(ast) - code = ps.get_code_str(ast) - if dtype == 'float32': - assert 'expf(' in code - elif dtype == 'float64': - assert 'exp(' in code +# code = ps.get_code_str(ast) +# if dtype == 'float32': +# assert 'expf(' in code +# elif dtype == 'float64': +# assert 'exp(' in code @pytest.mark.parametrize('target', (ps.Target.CPU, ps.Target.GPU)) -@pytest.mark.parametrize('simplification', (True, False)) @pytest.mark.skipif((vs.major, vs.minor, vs.micro) == (3, 8, 2), reason="does not work on python 3.8.2 for some reason") -def test_evaluate_constant_terms(target, simplification): +@pytest.mark.xfail(reason="The new backend does not (yet) evaluate transcendental functions") +def test_evaluate_constant_terms(target): if target == ps.Target.GPU: pytest.importorskip("cupy") src, dst = ps.fields('src, dst: float32[2d]') @@ -187,7 +188,7 @@ def test_evaluate_constant_terms(target, simplification): src[0, 0]: -sp.cos(1) + dst[0, 0] }) - config = pystencils.config.CreateKernelConfig(target=target, default_assignment_simplifications=simplification) + config = pystencils.config.CreateKernelConfig(target=target) ast = ps.create_kernel(assignments, config=config) code = ps.get_code_str(ast) - assert 'cos(' not in code + assert 'cos(' not in code and 'cosf(' not in code diff --git a/tests/test_stencils.py b/tests/frontend/test_stencils.py similarity index 100% rename from tests/test_stencils.py rename to tests/frontend/test_stencils.py diff --git a/tests/test_subexpression_insertion.py b/tests/frontend/test_subexpression_insertion.py similarity index 100% rename from tests/test_subexpression_insertion.py rename to tests/frontend/test_subexpression_insertion.py diff --git a/tests/test_sympyextensions.py b/tests/frontend/test_sympyextensions.py similarity index 100% rename from tests/test_sympyextensions.py rename to tests/frontend/test_sympyextensions.py diff --git a/tests/symbolics/test_typed_sympy.py b/tests/frontend/test_typed_sympy.py similarity index 100% rename from tests/symbolics/test_typed_sympy.py rename to tests/frontend/test_typed_sympy.py diff --git a/tests/test_utils.py b/tests/frontend/test_utils.py similarity index 100% rename from tests/test_utils.py rename to tests/frontend/test_utils.py diff --git a/tests/test_blocking.py b/tests/kernelcreation/test_blocking.py similarity index 92% rename from tests/test_blocking.py rename to tests/kernelcreation/test_blocking.py index 5ab66cd4e..577b6f1a6 100644 --- a/tests/test_blocking.py +++ b/tests/kernelcreation/test_blocking.py @@ -1,5 +1,6 @@ import numpy as np import sympy as sp +import pytest import pystencils as ps @@ -39,6 +40,7 @@ def check_equivalence(assignments, src_arr): np.testing.assert_almost_equal(ref_arr, dst3_arr) +@pytest.mark.xfail(reason="CPU blocking is not yet implemented in the new backend") def test_jacobi3d_var_size(): src, dst = ps.fields("src, dst: double[3D]", layout='c') @@ -55,6 +57,7 @@ def test_jacobi3d_var_size(): check_equivalence(jacobi(dst, src), arr) +@pytest.mark.xfail(reason="CPU blocking is not yet implemented in the new backend") def test_jacobi3d_fixed_size(): print("Fixed Size: Large non divisible sizes") arr = np.empty([10, 10, 9]) @@ -72,6 +75,7 @@ def test_jacobi3d_fixed_size(): check_equivalence(jacobi(dst, src), arr) +@pytest.mark.xfail(reason="CPU blocking is not yet implemented in the new backend") def test_jacobi3d_fixed_field_size(): src, dst = ps.fields("src, dst: double[3, 5, 6]", layout='c') diff --git a/tests/test_blocking_staggered.py b/tests/kernelcreation/test_blocking_staggered.py similarity index 89% rename from tests/test_blocking_staggered.py rename to tests/kernelcreation/test_blocking_staggered.py index 722c2a358..184df753c 100644 --- a/tests/test_blocking_staggered.py +++ b/tests/kernelcreation/test_blocking_staggered.py @@ -1,8 +1,10 @@ import numpy as np +import pytest import pystencils as ps +@pytest.mark.xfail(reason="Blocking and staggered accesses are not yet implemented in the new backend") def test_blocking_staggered(): f = ps.fields("f: double[3D]") stag = ps.fields("stag(3): double[3D]", field_type=ps.FieldType.STAGGERED) diff --git a/tests/test_buffer.py b/tests/kernelcreation/test_buffer.py similarity index 99% rename from tests/test_buffer.py rename to tests/kernelcreation/test_buffer.py index 0620e0540..36306534f 100644 --- a/tests/test_buffer.py +++ b/tests/kernelcreation/test_buffer.py @@ -193,6 +193,7 @@ def test_field_layouts(): unpack_kernel = unpack_code.compile() unpack_kernel(buffer=bufferArr, dst_field=dst_arr) + def test_iteration_slices(): num_cell_values = 19 dt = np.uint64 @@ -244,5 +245,3 @@ def test_iteration_slices(): np.testing.assert_equal(dst_arr[pack_slice], src_arr[pack_slice]) np.testing.assert_equal(dst_arr[(slice(1, None, 2),) * (dim - 1) + (0,)], 0) np.testing.assert_equal(dst_arr[(slice(None, None, 1),) * (dim - 1) + (slice(1, None),)], 0) - -# test_all_cell_values() \ No newline at end of file diff --git a/tests/test_buffer_gpu.py b/tests/kernelcreation/test_buffer_gpu.py similarity index 91% rename from tests/test_buffer_gpu.py rename to tests/kernelcreation/test_buffer_gpu.py index 63017332e..873cc1213 100644 --- a/tests/test_buffer_gpu.py +++ b/tests/kernelcreation/test_buffer_gpu.py @@ -57,18 +57,16 @@ def test_full_scalar_field(): field_type=FieldType.BUFFER, dtype=src_arr.dtype) pack_eqs = [Assignment(buffer.center(), src_field.center())] - pack_types = {'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=pack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) pack_ast = create_kernel(pack_eqs, config=config) pack_kernel = pack_ast.compile() pack_kernel(buffer=gpu_buffer_arr, src_field=gpu_src_arr) unpack_eqs = [Assignment(dst_field.center(), buffer.center())] - unpack_types = {'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=unpack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) unpack_ast = create_kernel(unpack_eqs, config=config) unpack_kernel = unpack_ast.compile() @@ -95,9 +93,8 @@ def test_field_slice(): field_type=FieldType.BUFFER, dtype=src_arr.dtype) pack_eqs = [Assignment(buffer.center(), src_field.center())] - pack_types = {'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=pack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) pack_ast = create_kernel(pack_eqs, config=config) pack_kernel = pack_ast.compile() @@ -105,9 +102,8 @@ def test_field_slice(): # Unpack into ghost layer of dst_field in N direction unpack_eqs = [Assignment(dst_field.center(), buffer.center())] - unpack_types = {'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=unpack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) unpack_ast = create_kernel(unpack_eqs, config=config) unpack_kernel = unpack_ast.compile() @@ -125,7 +121,7 @@ def test_all_cell_values(): for (src_arr, gpu_src_arr, gpu_dst_arr, gpu_buffer_arr) in fields: src_field = Field.create_from_numpy_array("src_field", gpu_src_arr, index_dimensions=1) dst_field = Field.create_from_numpy_array("dst_field", gpu_src_arr, index_dimensions=1) - buffer = Field.create_generic("buffer", spatial_dimensions=1, index_dimensions=1, + buffer = Field.create_generic("buffer", spatial_dimensions=1, index_shape=(num_cell_values,), field_type=FieldType.BUFFER, dtype=gpu_src_arr.dtype) pack_eqs = [] @@ -135,9 +131,7 @@ def test_all_cell_values(): eq = Assignment(buffer(idx), src_field(idx)) pack_eqs.append(eq) - pack_types = {'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=pack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) pack_code = create_kernel(pack_eqs, config=config) pack_kernel = pack_code.compile() @@ -149,9 +143,7 @@ def test_all_cell_values(): eq = Assignment(dst_field(idx), buffer(idx)) unpack_eqs.append(eq) - unpack_types = {'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=unpack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) unpack_ast = create_kernel(unpack_eqs, config=config) unpack_kernel = unpack_ast.compile() unpack_kernel(buffer=gpu_buffer_arr, dst_field=gpu_dst_arr) @@ -170,7 +162,7 @@ def test_subset_cell_values(): for (src_arr, gpu_src_arr, gpu_dst_arr, gpu_buffer_arr) in fields: src_field = Field.create_from_numpy_array("src_field", gpu_src_arr, index_dimensions=1) dst_field = Field.create_from_numpy_array("dst_field", gpu_src_arr, index_dimensions=1) - buffer = Field.create_generic("buffer", spatial_dimensions=1, index_dimensions=1, + buffer = Field.create_generic("buffer", spatial_dimensions=1, index_shape=(len(cell_indices),), field_type=FieldType.BUFFER, dtype=gpu_src_arr.dtype) pack_eqs = [] @@ -181,7 +173,7 @@ def test_subset_cell_values(): pack_eqs.append(eq) pack_types = {'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=pack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) pack_ast = create_kernel(pack_eqs, config=config) pack_kernel = pack_ast.compile() pack_kernel(buffer=gpu_buffer_arr, src_field=gpu_src_arr) @@ -193,7 +185,7 @@ def test_subset_cell_values(): unpack_eqs.append(eq) unpack_types = {'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=unpack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) unpack_ast = create_kernel(unpack_eqs, config=config) unpack_kernel = unpack_ast.compile() @@ -212,7 +204,7 @@ def test_field_layouts(): for (src_arr, gpu_src_arr, gpu_dst_arr, gpu_buffer_arr) in fields: src_field = Field.create_from_numpy_array("src_field", gpu_src_arr, index_dimensions=1) dst_field = Field.create_from_numpy_array("dst_field", gpu_src_arr, index_dimensions=1) - buffer = Field.create_generic("buffer", spatial_dimensions=1, index_dimensions=1, + buffer = Field.create_generic("buffer", spatial_dimensions=1, index_shape=(num_cell_values,), field_type=FieldType.BUFFER, dtype=src_arr.dtype) pack_eqs = [] @@ -223,7 +215,7 @@ def test_field_layouts(): pack_eqs.append(eq) pack_types = {'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=pack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) pack_ast = create_kernel(pack_eqs, config=config) pack_kernel = pack_ast.compile() @@ -236,13 +228,14 @@ def test_field_layouts(): unpack_eqs.append(eq) unpack_types = {'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype} - config = CreateKernelConfig(target=pystencils.Target.GPU, data_type=unpack_types) + config = CreateKernelConfig(target=pystencils.Target.GPU) unpack_ast = create_kernel(unpack_eqs, config=config) unpack_kernel = unpack_ast.compile() unpack_kernel(buffer=gpu_buffer_arr, dst_field=gpu_dst_arr) +@pytest.mark.xfail(reason="flag_cond is not available yet") def test_buffer_indexing(): src_field, dst_field = fields(f'pdfs_src(19), pdfs_dst(19) :double[3D]') mask_field = fields(f'mask : uint32 [3D]') @@ -256,7 +249,7 @@ def test_buffer_indexing(): up = Assignment(buffer(0), flag_cond(1, mask_field.center, src_field[0, 1, 0](1))) iteration_slice = tuple(slice(None, None, 2) for _ in range(3)) config = CreateKernelConfig(target=Target.GPU) - config = replace(config, iteration_slice=iteration_slice, ghost_layers=0) + config = replace(config, iteration_slice=iteration_slice) ast = create_kernel(up, config=config) parameters = ast.get_parameters() @@ -277,13 +270,16 @@ def test_buffer_indexing(): @pytest.mark.parametrize('gpu_indexing', ("block", "line")) def test_iteration_slices(gpu_indexing): + if gpu_indexing == "line": + pytest.xfail("Line indexing not available yet") + num_cell_values = 19 dt = np.uint64 fields = _generate_fields(dt=dt, stencil_directions=num_cell_values) for (src_arr, gpu_src_arr, gpu_dst_arr, gpu_buffer_arr) in fields: src_field = Field.create_from_numpy_array("src_field", gpu_src_arr, index_dimensions=1) dst_field = Field.create_from_numpy_array("dst_field", gpu_src_arr, index_dimensions=1) - buffer = Field.create_generic("buffer", spatial_dimensions=1, index_dimensions=1, + buffer = Field.create_generic("buffer", spatial_dimensions=1, index_shape=(num_cell_values,), field_type=FieldType.BUFFER, dtype=src_arr.dtype) pack_eqs = [] @@ -304,7 +300,6 @@ def test_iteration_slices(gpu_indexing): gpu_dst_arr.fill(0) config = CreateKernelConfig(target=Target.GPU, iteration_slice=pack_slice, - data_type={'src_field': gpu_src_arr.dtype, 'buffer': gpu_buffer_arr.dtype}, gpu_indexing=gpu_indexing) pack_code = create_kernel(pack_eqs, config=config) @@ -318,7 +313,6 @@ def test_iteration_slices(gpu_indexing): unpack_eqs.append(eq) config = CreateKernelConfig(target=Target.GPU, iteration_slice=pack_slice, - data_type={'dst_field': gpu_dst_arr.dtype, 'buffer': gpu_buffer_arr.dtype}, gpu_indexing=gpu_indexing) unpack_code = create_kernel(unpack_eqs, config=config) diff --git a/tests/nbackend/kernelcreation/test_domain_kernels.py b/tests/kernelcreation/test_domain_kernels.py similarity index 100% rename from tests/nbackend/kernelcreation/test_domain_kernels.py rename to tests/kernelcreation/test_domain_kernels.py diff --git a/tests/nbackend/test_functions.py b/tests/kernelcreation/test_functions.py similarity index 67% rename from tests/nbackend/test_functions.py rename to tests/kernelcreation/test_functions.py index 325e59340..4094556a0 100644 --- a/tests/nbackend/test_functions.py +++ b/tests/kernelcreation/test_functions.py @@ -2,7 +2,10 @@ import sympy as sp import numpy as np import pytest -from pystencils import create_kernel, CreateKernelConfig, Target, Assignment, Field +from pystencils import fields, create_kernel, CreateKernelConfig, Target, Assignment, Field +from pystencils.backend.ast import dfs_preorder +from pystencils.backend.ast.expressions import PsCall + def unary_function(name, xp): @@ -120,3 +123,43 @@ def test_binary_functions(target, function_name, dtype): kfunc(inp=inp, inp2=inp2, outp=outp) xp.testing.assert_allclose(outp, reference, rtol=resolution) + + +@pytest.mark.parametrize('a', [sp.Symbol('a'), fields('a: float64[2d]').center]) +def test_avoid_pow(a): + x = fields('x: float64[2d]') + + up = Assignment(x.center_vector[0], 2 * a ** 2 / 3) + func = create_kernel(up) + + powers = list(dfs_preorder(func.body, lambda n: isinstance(n, PsCall) and "pow" in n.function.name)) + assert not powers + + +@pytest.mark.xfail(reason="fast_div not available yet") +def test_avoid_pow_fast_div(): + x = fields('x: float64[2d]') + a = fields('a: float64[2d]').center + + up = Assignment(x.center_vector[0], fast_division(1, (a**2))) + func = create_kernel(up, config=CreateKernelConfig(target=Target.GPU)) + + powers = list(dfs_preorder(func.body, lambda n: isinstance(n, PsCall) and "pow" in n.function.name)) + assert not powers + + +def test_avoid_pow_move_constants(): + # At the end of the kernel creation the function move_constants_before_loop will be called + # This function additionally contains substitutions for symbols with the same value + # Thus it simplifies the equations again + x = fields('x: float64[2d]') + a, b, c = sp.symbols("a, b, c") + + up = [Assignment(a, 0.0), + Assignment(b, 0.0), + Assignment(c, 0.0), + Assignment(x.center_vector[0], a**2/18 - a*b/6 - a/18 + b**2/18 + b/18 - c**2/36)] + func = create_kernel(up) + + powers = list(dfs_preorder(func.body, lambda n: isinstance(n, PsCall) and "pow" in n.function.name)) + assert not powers diff --git a/tests/nbackend/kernelcreation/test_gpu.py b/tests/kernelcreation/test_gpu.py similarity index 98% rename from tests/nbackend/kernelcreation/test_gpu.py rename to tests/kernelcreation/test_gpu.py index 10d222474..57de84b7a 100644 --- a/tests/nbackend/kernelcreation/test_gpu.py +++ b/tests/kernelcreation/test_gpu.py @@ -1,7 +1,6 @@ import pytest import numpy as np -import cupy as cp import sympy as sp from scipy.ndimage import convolve @@ -11,8 +10,8 @@ from pystencils.simp import sympy_cse_on_assignment_list from pystencils.slicing import add_ghost_layers, make_slice, remove_ghost_layers, normalize_slice try: - import cupy - device_numbers = range(cupy.cuda.runtime.getDeviceCount()) + import cupy as cp + device_numbers = range(cp.cuda.runtime.getDeviceCount()) except ImportError: device_numbers = [] diff --git a/tests/test_half_precision.py b/tests/kernelcreation/test_half_precision.py similarity index 100% rename from tests/test_half_precision.py rename to tests/kernelcreation/test_half_precision.py diff --git a/tests/nbackend/kernelcreation/test_index_kernels.py b/tests/kernelcreation/test_index_kernels.py similarity index 100% rename from tests/nbackend/kernelcreation/test_index_kernels.py rename to tests/kernelcreation/test_index_kernels.py diff --git a/tests/kernelcreation/test_kernel_decorator.py b/tests/kernelcreation/test_kernel_decorator.py new file mode 100644 index 000000000..648f14180 --- /dev/null +++ b/tests/kernelcreation/test_kernel_decorator.py @@ -0,0 +1,32 @@ +import numpy as np +import sympy as sp +import pystencils as ps + + +def test_kernel_decorator_config(): + config = ps.CreateKernelConfig() + a, b, c = ps.fields(a=np.ones(100), b=np.ones(100), c=np.ones(100)) + + @ps.kernel_config(config) + def test(): + a[0] @= b[0] + c[0] + + ps.create_kernel(**test) + + +def test_kernel_decorator2(): + h = sp.symbols("h") + dtype = "float64" + + src, dst = ps.fields(f"src, src_tmp: {dtype}[3D]") + + @ps.kernel + def kernel_func(): + dst[0, 0, 0] @= (src[1, 0, 0] + src[-1, 0, 0] + + src[0, 1, 0] + src[0, -1, 0] + + src[0, 0, 1] + src[0, 0, -1]) / (6 * h ** 2) + + # assignments = ps.assignment_from_stencil(stencil, src, dst, normalization_factor=2) + ast = ps.create_kernel(kernel_func) + + _ = ps.get_code_str(ast) diff --git a/tests/test_logarithm.py b/tests/kernelcreation/test_logarithm.py similarity index 89% rename from tests/test_logarithm.py rename to tests/kernelcreation/test_logarithm.py index 85d7814a3..8490cda2f 100644 --- a/tests/test_logarithm.py +++ b/tests/kernelcreation/test_logarithm.py @@ -12,7 +12,7 @@ def test_log(dtype): assignments = ps.AssignmentCollection({x.center(): sp.log(a)}) - ast = ps.create_kernel(assignments) + ast = ps.create_kernel(assignments, default_dtype=dtype) code = ps.get_code_str(ast) kernel = ast.compile() diff --git a/tests/test_size_and_layout_checks.py b/tests/kernelcreation/test_size_and_layout_checks.py similarity index 94% rename from tests/test_size_and_layout_checks.py rename to tests/kernelcreation/test_size_and_layout_checks.py index 0b653444e..05f8ca513 100644 --- a/tests/test_size_and_layout_checks.py +++ b/tests/kernelcreation/test_size_and_layout_checks.py @@ -8,8 +8,10 @@ from pystencils import Assignment, Field, create_kernel, fields from pystencils.backend.exceptions import KernelConstraintsError +@pytest.mark.xfail(reason="Size checks not yet reimplemented in CPU JIT") def test_size_check(): """Kernel with two fixed-sized fields creating with same size but calling with wrong size""" + src = np.zeros((20, 21, 9)) dst = np.zeros_like(src) @@ -24,6 +26,8 @@ def test_size_check(): src = np.zeros(new_shape) dst = np.zeros(new_shape) + assert False # TODO: The function call below is not valid and will likely segfault + with pytest.raises(ValueError) as e: func(src=src, dst=dst) assert 'Wrong shape' in str(e.value) @@ -59,6 +63,7 @@ def test_fixed_and_variable_field_check(): assert 'Cannot mix fixed- and variable-shape fields' in str(e.value) +@pytest.mark.xfail(reason="Shape checks not yet reimplemented in CPU JIT") def test_two_variable_shaped_fields(): src = np.zeros((20, 21, 9)) dst = np.zeros((22, 21, 9)) @@ -71,6 +76,8 @@ def test_two_variable_shaped_fields(): ast = create_kernel([update_rule]) func = ast.compile() + assert False # TODO: The function call below is not valid + with pytest.raises(TypeError) as e: func(src=src, dst=dst) assert 'must have same' in str(e.value) diff --git a/tests/test_sliced_iteration.py b/tests/kernelcreation/test_sliced_iteration.py similarity index 97% rename from tests/test_sliced_iteration.py rename to tests/kernelcreation/test_sliced_iteration.py index 5eff0a89d..8238a97da 100644 --- a/tests/test_sliced_iteration.py +++ b/tests/kernelcreation/test_sliced_iteration.py @@ -27,3 +27,6 @@ def test_sliced_iteration(): expected_result = np.zeros(size) expected_result[1:x_end_value, 1] = 1 np.testing.assert_almost_equal(expected_result, dst_arr) + + +test_sliced_iteration() diff --git a/tests/test_staggered_kernel.py b/tests/kernelcreation/test_staggered_kernel.py similarity index 93% rename from tests/test_staggered_kernel.py rename to tests/kernelcreation/test_staggered_kernel.py index db72a4ad8..9bc9e71af 100644 --- a/tests/test_staggered_kernel.py +++ b/tests/kernelcreation/test_staggered_kernel.py @@ -10,6 +10,7 @@ from pystencils.enums import Target class TestStaggeredDiffusion: def _run(self, num_neighbors, target=ps.Target.CPU, openmp=False): + pytest.xfail("Staggered kernels not available yet") L = (40, 40) D = 0.066 dt = 1 @@ -76,6 +77,7 @@ class TestStaggeredDiffusion: self._run(4, openmp=True) +@pytest.mark.xfail(reason="Staggered kernels not available yet") def test_staggered_subexpressions(): dh = ps.create_data_handling((10, 10), periodicity=True, default_target=Target.CPU) j = dh.add_array('j', values_per_cell=2, field_type=ps.FieldType.STAGGERED) @@ -85,6 +87,7 @@ def test_staggered_subexpressions(): ps.create_staggered_kernel(assignments, target=dh.default_target).compile() +@pytest.mark.xfail(reason="Staggered kernels not available yet") def test_staggered_loop_cutting(): pytest.importorskip('islpy') dh = ps.create_data_handling((4, 4), periodicity=True, default_target=Target.CPU) @@ -94,6 +97,7 @@ def test_staggered_loop_cutting(): assert not ast.atoms(ps.astnodes.Conditional) +@pytest.mark.xfail(reason="Staggered kernels not available yet") def test_staggered_vector(): dim = 2 v = x_staggered_vector(dim) diff --git a/tests/kernelcreation/test_struct_types.py b/tests/kernelcreation/test_struct_types.py new file mode 100644 index 000000000..de50527a7 --- /dev/null +++ b/tests/kernelcreation/test_struct_types.py @@ -0,0 +1,49 @@ +import numpy as np +import pytest + +from pystencils import Assignment, Field, create_kernel + + +@pytest.mark.parametrize("order", ['c', 'f']) +@pytest.mark.parametrize("align", [True, False]) +def test_fixed_sized_field(order, align): + if not align: + pytest.xfail("Non-Aligned structs not supported") + dt = np.dtype([('e1', np.float32), ('e2', np.double), ('e3', np.double)], align=align) + arr = np.zeros((3, 2), dtype=dt, order=order) + + f = Field.create_from_numpy_array("f", arr) + d = Field.create_from_numpy_array("d", arr) + update_rules = [Assignment(d[0, 0]['e2'], f[0, 0]['e3'])] + result = arr.copy(order=order) + assert result.strides == arr.strides + arr['e2'] = 0 + arr['e3'] = np.random.rand(3, 2) + + kernel = create_kernel(update_rules).compile() + kernel(f=arr, d=result) + np.testing.assert_almost_equal(result['e2'], arr['e3']) + np.testing.assert_equal(arr['e2'], np.zeros((3, 2))) + + +@pytest.mark.parametrize("order", ['c', 'f']) +@pytest.mark.parametrize("align", [True, False]) +def test_variable_sized_field(order, align): + if not align: + pytest.xfail("Non-Aligned structs not supported") + dt = np.dtype([('e1', np.float32), ('e2', np.double), ('e3', np.double)], align=align) + + f = Field.create_generic("f", 2, dt, layout=order) + d = Field.create_generic("d", 2, dt, layout=order) + update_rules = [Assignment(d[0, 0]['e2'], f[0, 0]['e3'])] + + arr = np.zeros((3, 2), dtype=dt, order=order) + result = arr.copy(order=order) + + arr['e2'] = 0 + arr['e3'] = np.random.rand(3, 2) + + kernel = create_kernel(update_rules).compile() + kernel(f=arr, d=result) + np.testing.assert_almost_equal(result['e2'], arr['e3']) + np.testing.assert_equal(arr['e2'], np.zeros((3, 2))) diff --git a/tests/test_sum_prod.py b/tests/kernelcreation/test_sum_prod.py similarity index 92% rename from tests/test_sum_prod.py rename to tests/kernelcreation/test_sum_prod.py index af19d5c02..9cd638c00 100644 --- a/tests/test_sum_prod.py +++ b/tests/kernelcreation/test_sum_prod.py @@ -15,12 +15,12 @@ import sympy as sp import sympy.abc import pystencils as ps -from pystencils.typing import create_type +from pystencils import create_type @pytest.mark.parametrize('dtype', ["float64", "float32"]) +@pytest.mark.xfail(reason="Sum and product reductions are not available yet") def test_sum(dtype): - sum = sp.Sum(sp.abc.k, (sp.abc.k, 1, 100)) expanded_sum = sum.doit() @@ -46,8 +46,8 @@ def test_sum(dtype): @pytest.mark.parametrize('dtype', ["int32", "int64", "float64", "float32"]) +@pytest.mark.xfail(reason="Sum and product reductions are not available yet") def test_product(dtype): - k = ps.TypedSymbol('k', create_type(dtype)) sum = sympy.Product(k, (k, 1, 10)) diff --git a/tests/test_aligned_array.py b/tests/runtime/test_aligned_array.py similarity index 97% rename from tests/test_aligned_array.py rename to tests/runtime/test_aligned_array.py index 33f435a48..64888f029 100644 --- a/tests/test_aligned_array.py +++ b/tests/runtime/test_aligned_array.py @@ -46,6 +46,9 @@ def test_3d_arrays(order, alignment, shape): @pytest.mark.parametrize("parallel", [False, True]) def test_data_handling(parallel): + if parallel: + pytest.importorskip("waLBerla") + for tries in range(16): # try a few times, since we might get lucky and get randomly a correct alignment dh = create_data_handling((6, 7), default_ghost_layers=1, parallel=parallel) dh.add_array('test', alignment=8 * 4, values_per_cell=1) diff --git a/tests/test_boundary.py b/tests/runtime/test_boundary.py similarity index 100% rename from tests/test_boundary.py rename to tests/runtime/test_boundary.py diff --git a/tests/test_boundary_indexlist_creation.py b/tests/runtime/test_boundary_indexlist_creation.py similarity index 100% rename from tests/test_boundary_indexlist_creation.py rename to tests/runtime/test_boundary_indexlist_creation.py diff --git a/tests/test_dtype_check.py b/tests/runtime/test_cpu_jit.py similarity index 53% rename from tests/test_dtype_check.py rename to tests/runtime/test_cpu_jit.py index 4e69b5e60..063533703 100644 --- a/tests/test_dtype_check.py +++ b/tests/runtime/test_cpu_jit.py @@ -1,21 +1,20 @@ import numpy as np import pytest -import pystencils -from pystencils.sympyextensions.astnodes import assignment_from_stencil +import pystencils as ps def test_dtype_check_wrong_type(): array = np.ones((10, 20)).astype(np.float32) output = np.zeros_like(array) - x, y = pystencils.fields('x,y: [2D]') + x, y = ps.fields('x,y: [2D]') stencil = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] - assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) - kernel = pystencils.create_kernel([assignment]).compile() + assignment = ps.assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) + kernel = ps.create_kernel([assignment]).compile() - with pytest.raises(ValueError) as e: + with pytest.raises(TypeError) as e: kernel(x=array, y=output) assert 'Wrong data type' in str(e.value) @@ -23,11 +22,11 @@ def test_dtype_check_wrong_type(): def test_dtype_check_correct_type(): array = np.ones((10, 20)).astype(np.float64) output = np.zeros_like(array) - x, y = pystencils.fields('x,y: [2D]') + x, y = ps.fields('x,y: [2D]') stencil = [[1, 1, 1], [1, 1, 1], [1, 1, 1]] - assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) - kernel = pystencils.create_kernel([assignment]).compile() + assignment = ps.assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) + kernel = ps.create_kernel([assignment]).compile() kernel(x=array, y=output) assert np.allclose(output[1:-1, 1:-1], np.ones_like(output[1:-1, 1:-1])) diff --git a/tests/test_data/datahandling_load_test.npz b/tests/runtime/test_data/datahandling_load_test.npz similarity index 100% rename from tests/test_data/datahandling_load_test.npz rename to tests/runtime/test_data/datahandling_load_test.npz diff --git a/tests/test_data/datahandling_parallel_load_test/dst.dat b/tests/runtime/test_data/datahandling_parallel_load_test/dst.dat similarity index 100% rename from tests/test_data/datahandling_parallel_load_test/dst.dat rename to tests/runtime/test_data/datahandling_parallel_load_test/dst.dat diff --git a/tests/test_data/datahandling_parallel_load_test/src.dat b/tests/runtime/test_data/datahandling_parallel_load_test/src.dat similarity index 100% rename from tests/test_data/datahandling_parallel_load_test/src.dat rename to tests/runtime/test_data/datahandling_parallel_load_test/src.dat diff --git a/tests/test_data/datahandling_parallel_save_test/dst.dat b/tests/runtime/test_data/datahandling_parallel_save_test/dst.dat similarity index 100% rename from tests/test_data/datahandling_parallel_save_test/dst.dat rename to tests/runtime/test_data/datahandling_parallel_save_test/dst.dat diff --git a/tests/test_data/datahandling_parallel_save_test/src.dat b/tests/runtime/test_data/datahandling_parallel_save_test/src.dat similarity index 100% rename from tests/test_data/datahandling_parallel_save_test/src.dat rename to tests/runtime/test_data/datahandling_parallel_save_test/src.dat diff --git a/tests/runtime/test_data/datahandling_save_test.npz b/tests/runtime/test_data/datahandling_save_test.npz new file mode 100644 index 0000000000000000000000000000000000000000..22202358a4fa1d1cea4db89c0889f5bca636598b GIT binary patch literal 428 zcmWIWW@Zs#U|`^2U|>*W=q~1yie+G6U|?lnU}q3vC@xCY%PXj4WDo!gfn>na3=9mj z--y4G7C3n#;8?)gd6S~%#4O2Mx*%_I+QM~<7tEU$9}+ZWhWPyWDU-N__%*eBuLcI_ zpYzc12;ClZ!Qf(`!NtH0SFQxE2vra+Fl;!;{yVVBM8@s%!3?{E1;us@4ESA@Qd}}X yu3}^oVa63&pumCP21XDK4Z8quVl_=;U|@iHEx?<V4P*ur0~13Q0|SE&*hBzalx#cz literal 0 HcmV?d00001 diff --git a/tests/test_data/lenna.png b/tests/runtime/test_data/lenna.png similarity index 100% rename from tests/test_data/lenna.png rename to tests/runtime/test_data/lenna.png diff --git a/tests/test_data/test_vessel2d_mask.png b/tests/runtime/test_data/test_vessel2d_mask.png similarity index 100% rename from tests/test_data/test_vessel2d_mask.png rename to tests/runtime/test_data/test_vessel2d_mask.png diff --git a/tests/test_datahandling.py b/tests/runtime/test_datahandling.py similarity index 99% rename from tests/test_datahandling.py rename to tests/runtime/test_datahandling.py index 15e9cd74b..90c21db18 100644 --- a/tests/test_datahandling.py +++ b/tests/runtime/test_datahandling.py @@ -409,3 +409,5 @@ def test_array_handler(device_number): assert gpu_array2.base is not None assert gpu_array2.strides == cpu_array2.strides + +test_access_and_gather() diff --git a/tests/test_datahandling_parallel.py b/tests/runtime/test_datahandling_parallel.py similarity index 99% rename from tests/test_datahandling_parallel.py rename to tests/runtime/test_datahandling_parallel.py index f572cf326..57a4d36aa 100644 --- a/tests/test_datahandling_parallel.py +++ b/tests/runtime/test_datahandling_parallel.py @@ -11,7 +11,7 @@ from pystencils.slicing import slice_from_direction from pystencils.datahandling.parallel_datahandling import ParallelDataHandling from pystencils.datahandling import create_data_handling -from tests.test_datahandling import ( +from test_datahandling import ( access_and_gather, kernel_execution_jacobi, reduction, synchronization, vtk_output) SCRIPT_FOLDER = Path(__file__).parent.absolute() diff --git a/tests/test_jupyter_extensions.ipynb b/tests/runtime/test_jupyter_extensions.ipynb similarity index 100% rename from tests/test_jupyter_extensions.ipynb rename to tests/runtime/test_jupyter_extensions.ipynb diff --git a/tests/test_parameterstudy.py b/tests/runtime/test_parameterstudy.py similarity index 95% rename from tests/test_parameterstudy.py rename to tests/runtime/test_parameterstudy.py index be5058d6c..255d55ffc 100644 --- a/tests/test_parameterstudy.py +++ b/tests/runtime/test_parameterstudy.py @@ -1,3 +1,10 @@ +import pytest + +try: + import blitzdb +except ImportError: + pytest.skip("BlitzDB not available", allow_module_level=True) + import io import json from http.server import BaseHTTPRequestHandler, HTTPServer diff --git a/tests/test_plot.py b/tests/runtime/test_plot.py similarity index 100% rename from tests/test_plot.py rename to tests/runtime/test_plot.py diff --git a/tests/test_sharedmethodcache.py b/tests/runtime/test_sharedmethodcache.py similarity index 100% rename from tests/test_sharedmethodcache.py rename to tests/runtime/test_sharedmethodcache.py diff --git a/tests/test_slicing.py b/tests/runtime/test_slicing.py similarity index 100% rename from tests/test_slicing.py rename to tests/runtime/test_slicing.py diff --git a/tests/test_small_block_benchmark.ipynb b/tests/runtime/test_small_block_benchmark.ipynb similarity index 100% rename from tests/test_small_block_benchmark.ipynb rename to tests/runtime/test_small_block_benchmark.ipynb diff --git a/tests/test_stencil_plot.ipynb b/tests/runtime/test_stencil_plot.ipynb similarity index 100% rename from tests/test_stencil_plot.ipynb rename to tests/runtime/test_stencil_plot.ipynb diff --git a/tests/test_timeloop.py b/tests/runtime/test_timeloop.py similarity index 100% rename from tests/test_timeloop.py rename to tests/runtime/test_timeloop.py diff --git a/tests/test_assignment_collection_dict_conversion.py b/tests/test_assignment_collection_dict_conversion.py deleted file mode 100644 index 16d38de82..000000000 --- a/tests/test_assignment_collection_dict_conversion.py +++ /dev/null @@ -1,32 +0,0 @@ -import pystencils - - -def test_assignment_collection_dict_conversion(): - x, y = pystencils.fields('x,y: [2D]') - - collection_normal = pystencils.AssignmentCollection( - [pystencils.Assignment(x.center(), y[1, 0] + y[0, 0])], - [] - ) - collection_dict = pystencils.AssignmentCollection( - {x.center(): y[1, 0] + y[0, 0]}, - {} - ) - assert str(collection_normal) == str(collection_dict) - assert collection_dict.main_assignments_dict == {x.center(): y[1, 0] + y[0, 0]} - assert collection_dict.subexpressions_dict == {} - - collection_normal = pystencils.AssignmentCollection( - [pystencils.Assignment(y[1, 0], x.center()), - pystencils.Assignment(y[0, 0], x.center())], - [] - ) - collection_dict = pystencils.AssignmentCollection( - {y[1, 0]: x.center(), - y[0, 0]: x.center()}, - {} - ) - assert str(collection_normal) == str(collection_dict) - assert collection_dict.main_assignments_dict == {y[1, 0]: x.center(), - y[0, 0]: x.center()} - assert collection_dict.subexpressions_dict == {} diff --git a/tests/test_assignment_from_stencil.py b/tests/test_assignment_from_stencil.py deleted file mode 100644 index 879372ae2..000000000 --- a/tests/test_assignment_from_stencil.py +++ /dev/null @@ -1,22 +0,0 @@ -import numpy as np - -import pystencils -from pystencils.sympyextensions.astnodes import assignment_from_stencil - - -def test_assignment_from_stencil(): - - stencil = [ - [0, 0, 4, 1, 0, 0, 0], - [0, 0, 0, 2, 0, 0, 0], - [0, 0, 0, 3, 0, 0, 0] - ] - - x, y = pystencils.fields('x, y: [2D]') - - assignment = assignment_from_stencil(stencil, x, y) - assert isinstance(assignment, pystencils.Assignment) - assert assignment.rhs == x[0, 1] + 4 * x[-1, 1] + 2 * x[0, 0] + 3 * x[0, -1] - - assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) - assert isinstance(assignment, pystencils.Assignment) diff --git a/tests/test_data/datahandling_save_test.npz b/tests/test_data/datahandling_save_test.npz deleted file mode 100644 index d363a8a0aba1bb78a06314a19b887eb4c4975334..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 410 zcmWIWW@Zs#U|`^2U|>*W=q~1y3SnSiU|?lnU}q3vC@xCY%PXj4WDo!gfn>na3=9mj z--y4G7C3n#;8?)gd6S~%#4O2Mx*%_I+QM~<7tEU$9}+ZWhWPyWDU-N__%*eBS-Hg1 zRm7Gs?UYip;&Mn?xpHy9Y6rCkNes>W-xhz-u=VP{^ko?%e#fK~m(bTSj7%cTxWWb$ p6cF6N2%@1O72r**rd|dH2B?n$yjj^mW-u`@F=R0?Fi3$-1OO#vVK)E( diff --git a/tests/test_math_functions.py b/tests/test_math_functions.py deleted file mode 100644 index 6bd80644a..000000000 --- a/tests/test_math_functions.py +++ /dev/null @@ -1,113 +0,0 @@ -import pytest -import sympy as sp -import numpy as np -import pystencils as ps -from pystencils.sympyextensions.fast_approximation import fast_division - - -@pytest.mark.parametrize('dtype', ["float64", "float32"]) -@pytest.mark.parametrize('func', [sp.Pow, sp.atan2]) -@pytest.mark.parametrize('target', [ps.Target.CPU, ps.Target.GPU]) -def test_two_arguments(dtype, func, target): - if target == ps.Target.GPU: - pytest.importorskip("cupy") - dh = ps.create_data_handling(domain_size=(10, 10), periodicity=True, default_target=target) - - x = dh.add_array('x', values_per_cell=1, dtype=dtype) - dh.fill("x", 0.0, ghost_layers=True) - y = dh.add_array('y', values_per_cell=1, dtype=dtype) - dh.fill("y", 1.0, ghost_layers=True) - z = dh.add_array('z', values_per_cell=1, dtype=dtype) - dh.fill("z", 2.0, ghost_layers=True) - - config = ps.CreateKernelConfig(target=target) - - # test sp.Max with one argument - up = ps.Assignment(x.center, func(y.center, z.center)) - ast = ps.create_kernel(up, config=config) - code = ps.get_code_str(ast) - if dtype == 'float32': - assert func.__name__.lower() in code - kernel = ast.compile() - - dh.all_to_gpu() - dh.run_kernel(kernel) - dh.all_to_cpu() - - np.testing.assert_allclose(dh.gather_array("x")[0, 0], float(func(1.0, 2.0).evalf()), - 13 if dtype == 'float64' else 5) - - -@pytest.mark.parametrize('dtype', ["float64", "float32"]) -@pytest.mark.parametrize('func', [sp.sin, sp.cos, sp.sinh, sp.cosh, sp.atan]) -@pytest.mark.parametrize('target', [ps.Target.CPU, ps.Target.GPU]) -def test_single_arguments(dtype, func, target): - if target == ps.Target.GPU: - pytest.importorskip("cupy") - dh = ps.create_data_handling(domain_size=(10, 10), periodicity=True, default_target=target) - - x = dh.add_array('x', values_per_cell=1, dtype=dtype) - dh.fill("x", 0.0, ghost_layers=True) - y = dh.add_array('y', values_per_cell=1, dtype=dtype) - dh.fill("y", 1.0, ghost_layers=True) - - config = ps.CreateKernelConfig(target=target) - - # test sp.Max with one argument - up = ps.Assignment(x.center, func(y.center)) - ast = ps.create_kernel(up, config=config) - code = ps.get_code_str(ast) - if dtype == 'float32': - assert func.__name__.lower() in code - kernel = ast.compile() - - dh.all_to_gpu() - dh.run_kernel(kernel) - dh.all_to_cpu() - - np.testing.assert_allclose(dh.gather_array("x")[0, 0], float(func(1.0).evalf()), - rtol=10**-3 if dtype == 'float32' else 10**-5) - - -@pytest.mark.parametrize('a', [sp.Symbol('a'), ps.fields('a: float64[2d]').center]) -def test_avoid_pow(a): - x = ps.fields('x: float64[2d]') - - up = ps.Assignment(x.center_vector[0], 2 * a ** 2 / 3) - ast = ps.create_kernel(up) - - code = ps.get_code_str(ast) - - assert "pow" not in code - - -def test_avoid_pow_fast_div(): - x = ps.fields('x: float64[2d]') - a = ps.fields('a: float64[2d]').center - - up = ps.Assignment(x.center_vector[0], fast_division(1, (a**2))) - ast = ps.create_kernel(up, config=ps.CreateKernelConfig(target=ps.Target.GPU)) - # ps.show_code(ast) - - code = ps.get_code_str(ast) - - assert "pow" not in code - - -def test_avoid_pow_move_constants(): - # At the end of the kernel creation the function move_constants_before_loop will be called - # This function additionally contains substitutions for symbols with the same value - # Thus it simplifies the equations again - x = ps.fields('x: float64[2d]') - a, b, c = sp.symbols("a, b, c") - - up = [ps.Assignment(a, 0.0), - ps.Assignment(b, 0.0), - ps.Assignment(c, 0.0), - ps.Assignment(x.center_vector[0], a**2/18 - a*b/6 - a/18 + b**2/18 + b/18 - c**2/36)] - ast = ps.create_kernel(up) - - code = ps.get_code_str(ast) - ps.show_code(ast) - - assert "pow" not in code diff --git a/tests/test_quicktests.py b/tests/test_quicktests.py index d694b30b4..506e2bf2c 100644 --- a/tests/test_quicktests.py +++ b/tests/test_quicktests.py @@ -1,8 +1,7 @@ import numpy as np +import pytest import pystencils as ps -from pystencils.cpu.vectorization import get_supported_instruction_sets -from pystencils.cpu.vectorization import replace_inner_stride_with_one, vectorize def test_basic_kernel(): @@ -33,6 +32,7 @@ def test_basic_kernel(): assert (dh.reduce_int_sequence(int_seq, op) == int_seq).all() +@pytest.mark.xfail(reason="Staggered kernels and blocking not implemented yet") def test_basic_blocking_staggered(): f = ps.fields("f: double[2D]") stag = ps.fields("stag(2): double[2D]", field_type=ps.FieldType.STAGGERED) @@ -52,6 +52,7 @@ def test_basic_blocking_staggered(): np.testing.assert_almost_equal(stag_arr, stag_ref) +@pytest.mark.xfail(reason="Vectorization not implemented yet") def test_basic_vectorization(): supported_instruction_sets = get_supported_instruction_sets() if supported_instruction_sets: diff --git a/tests/test_struct_types.py b/tests/test_struct_types.py deleted file mode 100644 index 5d8de3da6..000000000 --- a/tests/test_struct_types.py +++ /dev/null @@ -1,44 +0,0 @@ -import numpy as np - -from pystencils import Assignment, Field, create_kernel - - -def test_fixed_sized_field(): - for order in ('f', 'c'): - for align in (True, False): - dt = np.dtype([('e1', np.float32), ('e2', np.double), ('e3', np.double)], align=align) - arr = np.zeros((3, 2), dtype=dt, order=order) - - f = Field.create_from_numpy_array("f", arr) - d = Field.create_from_numpy_array("d", arr) - update_rules = [Assignment(d[0, 0]['e2'], f[0, 0]['e3'])] - result = arr.copy(order=order) - assert result.strides == arr.strides - arr['e2'] = 0 - arr['e3'] = np.random.rand(3, 2) - - kernel = create_kernel(update_rules).compile() - kernel(f=arr, d=result) - np.testing.assert_almost_equal(result['e2'], arr['e3']) - np.testing.assert_equal(arr['e2'], np.zeros((3, 2))) - - -def test_variable_sized_field(): - for order in ('f', 'c'): - for align in (True, False): - dt = np.dtype([('e1', np.float32), ('e2', np.double), ('e3', np.double)], align=align) - - f = Field.create_generic("f", 2, dt, layout=order) - d = Field.create_generic("d", 2, dt, layout=order) - update_rules = [Assignment(d[0, 0]['e2'], f[0, 0]['e3'])] - - arr = np.zeros((3, 2), dtype=dt, order=order) - result = arr.copy(order=order) - - arr['e2'] = 0 - arr['e3'] = np.random.rand(3, 2) - - kernel = create_kernel(update_rules).compile() - kernel(f=arr, d=result) - np.testing.assert_almost_equal(result['e2'], arr['e3']) - np.testing.assert_equal(arr['e2'], np.zeros((3, 2))) diff --git a/tests/nbackend/types/__init__.py b/tests/types/__init__.py similarity index 100% rename from tests/nbackend/types/__init__.py rename to tests/types/__init__.py diff --git a/tests/nbackend/types/test_types.py b/tests/types/test_types.py similarity index 100% rename from tests/nbackend/types/test_types.py rename to tests/types/test_types.py -- GitLab