diff --git a/pystencils/config.py b/pystencils/config.py index 9ef7b62dda30595b725a05e11bcd935d30415507..7c2be7a66f3d9d9ec0f3c4e6f4a406bbea471caa 100644 --- a/pystencils/config.py +++ b/pystencils/config.py @@ -1,4 +1,3 @@ -import warnings from copy import copy from collections import defaultdict from dataclasses import dataclass, field @@ -155,11 +154,9 @@ class CreateKernelConfig: def __post_init__(self): # ---- Legacy parameters - if isinstance(self.target, str): - new_target = Target[self.target.upper()] - warnings.warn(f'Target "{self.target}" as str is deprecated. Use {new_target} instead', - category=DeprecationWarning) - self.target = new_target + if not isinstance(self.target, Target): + raise ValueError("target must be provided by the 'Target' enum") + # ---- Auto Backend if not self.backend: if self.target == Target.CPU: @@ -169,6 +166,9 @@ class CreateKernelConfig: else: raise NotImplementedError(f'Target {self.target} has no default backend') + if not isinstance(self.backend, Backend): + raise ValueError("backend must be provided by the 'Backend' enum") + # Normalise data types for dtype in [self.data_type, self.default_number_float, self.default_number_int]: self._check_type(dtype) diff --git a/pystencils_tests/test_config.py b/pystencils_tests/test_config.py index 31f6f9ec983227a3166e556958aac822e0531cfc..4a57758ab9a54e44848df58f99c08145f762433f 100644 --- a/pystencils_tests/test_config.py +++ b/pystencils_tests/test_config.py @@ -60,6 +60,16 @@ def test_config(): assert config.default_number_int == BasicType('int64') +def test_config_target_as_string(): + with pytest.raises(ValueError): + CreateKernelConfig(target='cpu') + + +def test_config_backend_as_string(): + with pytest.raises(ValueError): + CreateKernelConfig(backend='C') + + def test_config_python_types(): with pytest.raises(ValueError): CreateKernelConfig(data_type=float) diff --git a/pystencils_tests/test_create_kernel_backwards_compability.py b/pystencils_tests/test_create_kernel_backwards_compability.py deleted file mode 100644 index 53137e9103c076b5693a585faf93c1c517fa616d..0000000000000000000000000000000000000000 --- a/pystencils_tests/test_create_kernel_backwards_compability.py +++ /dev/null @@ -1,38 +0,0 @@ -import pytest - -import pystencils as ps -import numpy as np - - -# This test aims to trigger deprication warnings. Thus the warnings should not be displayed in the warning summary. -import pystencils.config - - -def test_create_kernel_backwards_compatibility(): - size = (30, 20) - - src_field_string = np.random.rand(*size) - src_field_enum = np.copy(src_field_string) - src_field_config = np.copy(src_field_string) - dst_field_string = np.zeros(size) - dst_field_enum = np.zeros(size) - dst_field_config = np.zeros(size) - - f = ps.Field.create_from_numpy_array("f", src_field_enum) - d = ps.Field.create_from_numpy_array("d", dst_field_enum) - - jacobi = ps.Assignment(d[0, 0], (f[1, 0] + f[-1, 0] + f[0, 1] + f[0, -1]) / 4) - ast_enum = ps.create_kernel(jacobi, target=ps.Target.CPU).compile() - with pytest.warns(DeprecationWarning): - ast_string = ps.create_kernel(jacobi, target='cpu').compile() - # noinspection PyTypeChecker - with pytest.warns(DeprecationWarning): - ast_config = ps.create_kernel(jacobi, config=pystencils.config.CreateKernelConfig(target='cpu')).compile() - ast_enum(f=src_field_enum, d=dst_field_enum) - ast_string(f=src_field_string, d=dst_field_string) - ast_config(f=src_field_config, d=dst_field_config) - - error = np.sum(np.abs(dst_field_enum - dst_field_string)) - np.testing.assert_almost_equal(error, 0.0) - error = np.sum(np.abs(dst_field_enum - dst_field_config)) - np.testing.assert_almost_equal(error, 0.0)