Skip to content
Snippets Groups Projects
Commit c8a7c75a authored by Frederik Hennig's avatar Frederik Hennig
Browse files

migrate test suite

parent 1edd2d5c
Branches
Tags
1 merge request!409Migrate Test Suite
Showing
with 81 additions and 14 deletions
...@@ -12,7 +12,7 @@ def test_log(dtype): ...@@ -12,7 +12,7 @@ def test_log(dtype):
assignments = ps.AssignmentCollection({x.center(): sp.log(a)}) 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) code = ps.get_code_str(ast)
kernel = ast.compile() kernel = ast.compile()
......
...@@ -8,8 +8,10 @@ from pystencils import Assignment, Field, create_kernel, fields ...@@ -8,8 +8,10 @@ from pystencils import Assignment, Field, create_kernel, fields
from pystencils.backend.exceptions import KernelConstraintsError from pystencils.backend.exceptions import KernelConstraintsError
@pytest.mark.xfail(reason="Size checks not yet reimplemented in CPU JIT")
def test_size_check(): def test_size_check():
"""Kernel with two fixed-sized fields creating with same size but calling with wrong size""" """Kernel with two fixed-sized fields creating with same size but calling with wrong size"""
src = np.zeros((20, 21, 9)) src = np.zeros((20, 21, 9))
dst = np.zeros_like(src) dst = np.zeros_like(src)
...@@ -24,6 +26,8 @@ def test_size_check(): ...@@ -24,6 +26,8 @@ def test_size_check():
src = np.zeros(new_shape) src = np.zeros(new_shape)
dst = 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: with pytest.raises(ValueError) as e:
func(src=src, dst=dst) func(src=src, dst=dst)
assert 'Wrong shape' in str(e.value) assert 'Wrong shape' in str(e.value)
...@@ -59,6 +63,7 @@ def test_fixed_and_variable_field_check(): ...@@ -59,6 +63,7 @@ def test_fixed_and_variable_field_check():
assert 'Cannot mix fixed- and variable-shape fields' in str(e.value) 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(): def test_two_variable_shaped_fields():
src = np.zeros((20, 21, 9)) src = np.zeros((20, 21, 9))
dst = np.zeros((22, 21, 9)) dst = np.zeros((22, 21, 9))
...@@ -71,6 +76,8 @@ def test_two_variable_shaped_fields(): ...@@ -71,6 +76,8 @@ def test_two_variable_shaped_fields():
ast = create_kernel([update_rule]) ast = create_kernel([update_rule])
func = ast.compile() func = ast.compile()
assert False # TODO: The function call below is not valid
with pytest.raises(TypeError) as e: with pytest.raises(TypeError) as e:
func(src=src, dst=dst) func(src=src, dst=dst)
assert 'must have same' in str(e.value) assert 'must have same' in str(e.value)
......
...@@ -27,3 +27,6 @@ def test_sliced_iteration(): ...@@ -27,3 +27,6 @@ def test_sliced_iteration():
expected_result = np.zeros(size) expected_result = np.zeros(size)
expected_result[1:x_end_value, 1] = 1 expected_result[1:x_end_value, 1] = 1
np.testing.assert_almost_equal(expected_result, dst_arr) np.testing.assert_almost_equal(expected_result, dst_arr)
test_sliced_iteration()
...@@ -10,6 +10,7 @@ from pystencils.enums import Target ...@@ -10,6 +10,7 @@ from pystencils.enums import Target
class TestStaggeredDiffusion: class TestStaggeredDiffusion:
def _run(self, num_neighbors, target=ps.Target.CPU, openmp=False): def _run(self, num_neighbors, target=ps.Target.CPU, openmp=False):
pytest.xfail("Staggered kernels not available yet")
L = (40, 40) L = (40, 40)
D = 0.066 D = 0.066
dt = 1 dt = 1
...@@ -76,6 +77,7 @@ class TestStaggeredDiffusion: ...@@ -76,6 +77,7 @@ class TestStaggeredDiffusion:
self._run(4, openmp=True) self._run(4, openmp=True)
@pytest.mark.xfail(reason="Staggered kernels not available yet")
def test_staggered_subexpressions(): def test_staggered_subexpressions():
dh = ps.create_data_handling((10, 10), periodicity=True, default_target=Target.CPU) 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) j = dh.add_array('j', values_per_cell=2, field_type=ps.FieldType.STAGGERED)
...@@ -85,6 +87,7 @@ def test_staggered_subexpressions(): ...@@ -85,6 +87,7 @@ def test_staggered_subexpressions():
ps.create_staggered_kernel(assignments, target=dh.default_target).compile() ps.create_staggered_kernel(assignments, target=dh.default_target).compile()
@pytest.mark.xfail(reason="Staggered kernels not available yet")
def test_staggered_loop_cutting(): def test_staggered_loop_cutting():
pytest.importorskip('islpy') pytest.importorskip('islpy')
dh = ps.create_data_handling((4, 4), periodicity=True, default_target=Target.CPU) dh = ps.create_data_handling((4, 4), periodicity=True, default_target=Target.CPU)
...@@ -94,6 +97,7 @@ def test_staggered_loop_cutting(): ...@@ -94,6 +97,7 @@ def test_staggered_loop_cutting():
assert not ast.atoms(ps.astnodes.Conditional) assert not ast.atoms(ps.astnodes.Conditional)
@pytest.mark.xfail(reason="Staggered kernels not available yet")
def test_staggered_vector(): def test_staggered_vector():
dim = 2 dim = 2
v = x_staggered_vector(dim) v = x_staggered_vector(dim)
......
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)))
...@@ -15,12 +15,12 @@ import sympy as sp ...@@ -15,12 +15,12 @@ import sympy as sp
import sympy.abc import sympy.abc
import pystencils as ps import pystencils as ps
from pystencils.typing import create_type from pystencils import create_type
@pytest.mark.parametrize('dtype', ["float64", "float32"]) @pytest.mark.parametrize('dtype', ["float64", "float32"])
@pytest.mark.xfail(reason="Sum and product reductions are not available yet")
def test_sum(dtype): def test_sum(dtype):
sum = sp.Sum(sp.abc.k, (sp.abc.k, 1, 100)) sum = sp.Sum(sp.abc.k, (sp.abc.k, 1, 100))
expanded_sum = sum.doit() expanded_sum = sum.doit()
...@@ -46,8 +46,8 @@ def test_sum(dtype): ...@@ -46,8 +46,8 @@ def test_sum(dtype):
@pytest.mark.parametrize('dtype', ["int32", "int64", "float64", "float32"]) @pytest.mark.parametrize('dtype', ["int32", "int64", "float64", "float32"])
@pytest.mark.xfail(reason="Sum and product reductions are not available yet")
def test_product(dtype): def test_product(dtype):
k = ps.TypedSymbol('k', create_type(dtype)) k = ps.TypedSymbol('k', create_type(dtype))
sum = sympy.Product(k, (k, 1, 10)) sum = sympy.Product(k, (k, 1, 10))
......
...@@ -46,6 +46,9 @@ def test_3d_arrays(order, alignment, shape): ...@@ -46,6 +46,9 @@ def test_3d_arrays(order, alignment, shape):
@pytest.mark.parametrize("parallel", [False, True]) @pytest.mark.parametrize("parallel", [False, True])
def test_data_handling(parallel): 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 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 = create_data_handling((6, 7), default_ghost_layers=1, parallel=parallel)
dh.add_array('test', alignment=8 * 4, values_per_cell=1) dh.add_array('test', alignment=8 * 4, values_per_cell=1)
......
File moved
import numpy as np import numpy as np
import pytest import pytest
import pystencils import pystencils as ps
from pystencils.sympyextensions.astnodes import assignment_from_stencil
def test_dtype_check_wrong_type(): def test_dtype_check_wrong_type():
array = np.ones((10, 20)).astype(np.float32) array = np.ones((10, 20)).astype(np.float32)
output = np.zeros_like(array) output = np.zeros_like(array)
x, y = pystencils.fields('x,y: [2D]') x, y = ps.fields('x,y: [2D]')
stencil = [[1, 1, 1], stencil = [[1, 1, 1],
[1, 1, 1], [1, 1, 1],
[1, 1, 1]] [1, 1, 1]]
assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) assignment = ps.assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil))
kernel = pystencils.create_kernel([assignment]).compile() kernel = ps.create_kernel([assignment]).compile()
with pytest.raises(ValueError) as e: with pytest.raises(TypeError) as e:
kernel(x=array, y=output) kernel(x=array, y=output)
assert 'Wrong data type' in str(e.value) assert 'Wrong data type' in str(e.value)
...@@ -23,11 +22,11 @@ def test_dtype_check_wrong_type(): ...@@ -23,11 +22,11 @@ def test_dtype_check_wrong_type():
def test_dtype_check_correct_type(): def test_dtype_check_correct_type():
array = np.ones((10, 20)).astype(np.float64) array = np.ones((10, 20)).astype(np.float64)
output = np.zeros_like(array) output = np.zeros_like(array)
x, y = pystencils.fields('x,y: [2D]') x, y = ps.fields('x,y: [2D]')
stencil = [[1, 1, 1], stencil = [[1, 1, 1],
[1, 1, 1], [1, 1, 1],
[1, 1, 1]] [1, 1, 1]]
assignment = assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil)) assignment = ps.assignment_from_stencil(stencil, x, y, normalization_factor=1 / np.sum(stencil))
kernel = pystencils.create_kernel([assignment]).compile() kernel = ps.create_kernel([assignment]).compile()
kernel(x=array, y=output) kernel(x=array, y=output)
assert np.allclose(output[1:-1, 1:-1], np.ones_like(output[1:-1, 1:-1])) assert np.allclose(output[1:-1, 1:-1], np.ones_like(output[1:-1, 1:-1]))
File added
File moved
...@@ -409,3 +409,5 @@ def test_array_handler(device_number): ...@@ -409,3 +409,5 @@ def test_array_handler(device_number):
assert gpu_array2.base is not None assert gpu_array2.base is not None
assert gpu_array2.strides == cpu_array2.strides assert gpu_array2.strides == cpu_array2.strides
test_access_and_gather()
...@@ -11,7 +11,7 @@ from pystencils.slicing import slice_from_direction ...@@ -11,7 +11,7 @@ from pystencils.slicing import slice_from_direction
from pystencils.datahandling.parallel_datahandling import ParallelDataHandling from pystencils.datahandling.parallel_datahandling import ParallelDataHandling
from pystencils.datahandling import create_data_handling 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) access_and_gather, kernel_execution_jacobi, reduction, synchronization, vtk_output)
SCRIPT_FOLDER = Path(__file__).parent.absolute() SCRIPT_FOLDER = Path(__file__).parent.absolute()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment