From 1f8de6170d87c66315a17dc6290bc8562dc408f7 Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Tue, 10 Jan 2023 18:25:51 +0800 Subject: [PATCH 1/6] [Error] Raise errors when using metal sparse --- python/taichi/_snode/fields_builder.py | 14 +++++++------- python/taichi/lang/snode.py | 17 +++++++++-------- tests/python/test_deprecation.py | 16 ++++++++-------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/python/taichi/_snode/fields_builder.py b/python/taichi/_snode/fields_builder.py index 191ffdb45ca52..b369f9044aa55 100644 --- a/python/taichi/_snode/fields_builder.py +++ b/python/taichi/_snode/fields_builder.py @@ -76,9 +76,9 @@ def pointer(self, indices: Union[Sequence[_Axis], _Axis], dimensions: Union[Sequence[int], int]): """Same as :func:`taichi.lang.snode.SNode.pointer`""" if impl.current_cfg().arch == _ti_core.metal: - warnings.warn( - "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0.", - DeprecationWarning) + raise TaichiRuntimeError( + "Pointer SNode on metal backend is deprecated and removed." + ) self._check_not_finalized() self.empty = False return self.root.pointer(indices, dimensions) @@ -94,7 +94,7 @@ def dynamic(self, """Same as :func:`taichi.lang.snode.SNode.dynamic`""" if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Dynamic SNode on metal backend is deprecated and removed in this release." + "Dynamic SNode on metal backend is deprecated and removed." ) self._check_not_finalized() self.empty = False @@ -104,9 +104,9 @@ def bitmasked(self, indices: Union[Sequence[_Axis], _Axis], dimensions: Union[Sequence[int], int]): """Same as :func:`taichi.lang.snode.SNode.bitmasked`""" if impl.current_cfg().arch == _ti_core.metal: - warnings.warn( - "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0.", - DeprecationWarning) + raise TaichiRuntimeError( + "Bitmasked SNode on metal backend is deprecated and removed." + ) self._check_not_finalized() self.empty = False return self.root.bitmasked(indices, dimensions) diff --git a/python/taichi/lang/snode.py b/python/taichi/lang/snode.py index 75898e76b856a..e456e60c71e9c 100644 --- a/python/taichi/lang/snode.py +++ b/python/taichi/lang/snode.py @@ -5,6 +5,7 @@ from taichi.lang import expr, impl, matrix from taichi.lang.field import BitpackedFields, Field from taichi.lang.util import get_traceback +from taichi.lang.exception import TaichiRuntimeError class SNode: @@ -49,9 +50,9 @@ def pointer(self, axes, dimensions): The added :class:`~taichi.lang.SNode` instance. """ if impl.current_cfg().arch == _ti_core.metal: - warnings.warn( - "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0.", - DeprecationWarning) + raise TaichiRuntimeError( + "Pointer SNode on metal backend is deprecated and removed." + ) if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( @@ -80,8 +81,8 @@ def dynamic(self, axis, dimension, chunk_size=None): The added :class:`~taichi.lang.SNode` instance. """ if impl.current_cfg().arch == _ti_core.metal: - raise TaichiCompilationError( - "Dynamic SNode on metal backend is deprecated and removed in this release." + raise TaichiRuntimeError( + "Dynamic SNode on metal backend is deprecated and removed." ) assert len(axis) == 1 if chunk_size is None: @@ -101,9 +102,9 @@ def bitmasked(self, axes, dimensions): The added :class:`~taichi.lang.SNode` instance. """ if impl.current_cfg().arch == _ti_core.metal: - warnings.warn( - "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0.", - DeprecationWarning) + raise TaichiRuntimeError( + "Bitmasked SNode on metal backend is deprecated and removed." + ) if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 77ad0ac3210b5..c4f131de55518 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -73,26 +73,26 @@ def test_deprecate_element_shape_ndarray_arg(): ndim=1, element_shape=(1, )) - +# Remove this before v1.5.0 @test_utils.test(arch=ti.metal) def test_deprecate_metal_sparse(): - with pytest.warns( - DeprecationWarning, + with pytest.raises( + ti.TaichiRuntimeError, match= - "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0." + "Pointer SNode on metal backend is deprecated and removed." ): a = ti.root.pointer(ti.i, 10) - with pytest.warns( - DeprecationWarning, + with pytest.raises( + ti.TaichiRuntimeError, match= - "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0." + "Bitmasked SNode on metal backend is deprecated and removed." ): b = a.bitmasked(ti.j, 10) with pytest.raises( ti.TaichiRuntimeError, match= - "Dynamic SNode on metal backend is deprecated and removed in this release." + "Dynamic SNode on metal backend is deprecated and removed." ): ti.root.dynamic(ti.i, 10) From 7f84be84824ae988e8a9cd2a6563b759a3a95ccb Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Tue, 10 Jan 2023 18:34:46 +0800 Subject: [PATCH 2/6] fix pylint --- python/taichi/_snode/fields_builder.py | 1 - python/taichi/lang/snode.py | 1 - 2 files changed, 2 deletions(-) diff --git a/python/taichi/_snode/fields_builder.py b/python/taichi/_snode/fields_builder.py index b369f9044aa55..6525aec1178ae 100644 --- a/python/taichi/_snode/fields_builder.py +++ b/python/taichi/_snode/fields_builder.py @@ -1,4 +1,3 @@ -import warnings from typing import Any, Optional, Sequence, Union from taichi._lib import core as _ti_core diff --git a/python/taichi/lang/snode.py b/python/taichi/lang/snode.py index e456e60c71e9c..8885a4fd2ec77 100644 --- a/python/taichi/lang/snode.py +++ b/python/taichi/lang/snode.py @@ -1,5 +1,4 @@ import numbers -import warnings from taichi._lib import core as _ti_core from taichi.lang import expr, impl, matrix From 31cd39991db2e8f27bbb66e923e34720da5186d1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 10 Jan 2023 10:36:08 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- python/taichi/_snode/fields_builder.py | 9 +++------ python/taichi/lang/snode.py | 11 ++++------- tests/python/test_deprecation.py | 12 ++++-------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/python/taichi/_snode/fields_builder.py b/python/taichi/_snode/fields_builder.py index 6525aec1178ae..da576aa8d4b9a 100644 --- a/python/taichi/_snode/fields_builder.py +++ b/python/taichi/_snode/fields_builder.py @@ -76,8 +76,7 @@ def pointer(self, indices: Union[Sequence[_Axis], _Axis], """Same as :func:`taichi.lang.snode.SNode.pointer`""" if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Pointer SNode on metal backend is deprecated and removed." - ) + "Pointer SNode on metal backend is deprecated and removed.") self._check_not_finalized() self.empty = False return self.root.pointer(indices, dimensions) @@ -93,8 +92,7 @@ def dynamic(self, """Same as :func:`taichi.lang.snode.SNode.dynamic`""" if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Dynamic SNode on metal backend is deprecated and removed." - ) + "Dynamic SNode on metal backend is deprecated and removed.") self._check_not_finalized() self.empty = False return self.root.dynamic(index, dimension, chunk_size) @@ -104,8 +102,7 @@ def bitmasked(self, indices: Union[Sequence[_Axis], _Axis], """Same as :func:`taichi.lang.snode.SNode.bitmasked`""" if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Bitmasked SNode on metal backend is deprecated and removed." - ) + "Bitmasked SNode on metal backend is deprecated and removed.") self._check_not_finalized() self.empty = False return self.root.bitmasked(indices, dimensions) diff --git a/python/taichi/lang/snode.py b/python/taichi/lang/snode.py index 8885a4fd2ec77..15fab24924d80 100644 --- a/python/taichi/lang/snode.py +++ b/python/taichi/lang/snode.py @@ -2,9 +2,9 @@ from taichi._lib import core as _ti_core from taichi.lang import expr, impl, matrix +from taichi.lang.exception import TaichiRuntimeError from taichi.lang.field import BitpackedFields, Field from taichi.lang.util import get_traceback -from taichi.lang.exception import TaichiRuntimeError class SNode: @@ -50,8 +50,7 @@ def pointer(self, axes, dimensions): """ if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Pointer SNode on metal backend is deprecated and removed." - ) + "Pointer SNode on metal backend is deprecated and removed.") if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( @@ -81,8 +80,7 @@ def dynamic(self, axis, dimension, chunk_size=None): """ if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Dynamic SNode on metal backend is deprecated and removed." - ) + "Dynamic SNode on metal backend is deprecated and removed.") assert len(axis) == 1 if chunk_size is None: chunk_size = dimension @@ -102,8 +100,7 @@ def bitmasked(self, axes, dimensions): """ if impl.current_cfg().arch == _ti_core.metal: raise TaichiRuntimeError( - "Bitmasked SNode on metal backend is deprecated and removed." - ) + "Bitmasked SNode on metal backend is deprecated and removed.") if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index c4f131de55518..20d5b43b2d8e2 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -73,27 +73,23 @@ def test_deprecate_element_shape_ndarray_arg(): ndim=1, element_shape=(1, )) + # Remove this before v1.5.0 @test_utils.test(arch=ti.metal) def test_deprecate_metal_sparse(): with pytest.raises( ti.TaichiRuntimeError, - match= - "Pointer SNode on metal backend is deprecated and removed." - ): + match="Pointer SNode on metal backend is deprecated and removed."): a = ti.root.pointer(ti.i, 10) with pytest.raises( ti.TaichiRuntimeError, - match= - "Bitmasked SNode on metal backend is deprecated and removed." + match="Bitmasked SNode on metal backend is deprecated and removed." ): b = a.bitmasked(ti.j, 10) with pytest.raises( ti.TaichiRuntimeError, - match= - "Dynamic SNode on metal backend is deprecated and removed." - ): + match="Dynamic SNode on metal backend is deprecated and removed."): ti.root.dynamic(ti.i, 10) From bcff13b12d7c94906c9817f9feb70710552bf6b1 Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Wed, 11 Jan 2023 12:27:41 +0800 Subject: [PATCH 4/6] fix example --- python/taichi/examples/features/sparse/taichi_bitmasked.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/taichi/examples/features/sparse/taichi_bitmasked.py b/python/taichi/examples/features/sparse/taichi_bitmasked.py index eb19b75e5f0f2..7a5a365e7ce1c 100644 --- a/python/taichi/examples/features/sparse/taichi_bitmasked.py +++ b/python/taichi/examples/features/sparse/taichi_bitmasked.py @@ -2,7 +2,7 @@ import taichi as ti -ti.init(arch=ti.gpu) +ti.init(arch=ti.cuda) n = 256 x = ti.field(ti.f32) From adb7b7b1c2ff86294c1b512444d2815c22a30bff Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Wed, 11 Jan 2023 15:54:38 +0800 Subject: [PATCH 5/6] fix example --- python/taichi/examples/simulation/comet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/taichi/examples/simulation/comet.py b/python/taichi/examples/simulation/comet.py index f0182f77be625..c8064fc64546b 100644 --- a/python/taichi/examples/simulation/comet.py +++ b/python/taichi/examples/simulation/comet.py @@ -2,7 +2,7 @@ import taichi as ti -ti.init(arch=[ti.cuda, ti.metal]) +ti.init(arch=ti.cuda) dim = 3 N = 1024 * 8 From 8f92d76710510cd811179fd460767745079781e7 Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Wed, 11 Jan 2023 20:10:28 +0800 Subject: [PATCH 6/6] fix test --- tests/python/test_deprecation.py | 4 ++-- tests/python/test_matrix.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 20d5b43b2d8e2..195da0cd1aec8 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -80,12 +80,12 @@ def test_deprecate_metal_sparse(): with pytest.raises( ti.TaichiRuntimeError, match="Pointer SNode on metal backend is deprecated and removed."): - a = ti.root.pointer(ti.i, 10) + ti.root.pointer(ti.i, 10) with pytest.raises( ti.TaichiRuntimeError, match="Bitmasked SNode on metal backend is deprecated and removed." ): - b = a.bitmasked(ti.j, 10) + ti.root.bitmasked(ti.j, 10) with pytest.raises( ti.TaichiRuntimeError, diff --git a/tests/python/test_matrix.py b/tests/python/test_matrix.py index 178d5fc6cfc9a..1cc9da49bdf9b 100644 --- a/tests/python/test_matrix.py +++ b/tests/python/test_matrix.py @@ -442,7 +442,7 @@ def test_matrix_field_dynamic_index_different_path_length(): assert v._get_dynamic_index_stride() is None -@test_utils.test() +@test_utils.test(require=ti.extension.sparse, exclude=[ti.metal]) def test_matrix_field_dynamic_index_not_pure_dense(): v = ti.Vector.field(2, ti.i32) x = v.get_scalar_field(0)