From 85f26094c72e727101fc2c18edd24ebf7e9f970d Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Fri, 17 Nov 2023 11:09:08 +0800 Subject: [PATCH 1/6] [Lang] Remove deprecated graph arguments --- python/taichi/graph/_graph.py | 42 +++++++++------------------- tests/python/test_deprecation.py | 48 ++++++++++++++++---------------- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/python/taichi/graph/_graph.py b/python/taichi/graph/_graph.py index 0cc1c14f56845..76b497b632a65 100644 --- a/python/taichi/graph/_graph.py +++ b/python/taichi/graph/_graph.py @@ -106,12 +106,10 @@ def _deprecate_arg_args(kwargs: Dict[str, Any]): if tag == ArgKind.SCALAR: if "element_shape" in kwargs: - warnings.warn( - "The element_shape argument for scalar is deprecated in v1.6.0, and will be removed in v1.7.0. " - "Please remove them.", - DeprecationWarning, + raise TaichiRuntimeError( + "The element_shape argument for scalar is deprecated in v1.6.0, and is removed in v1.7.0. " + "Please remove them." ) - del kwargs["element_shape"] if tag == ArgKind.NDARRAY: if "element_shape" not in kwargs: @@ -123,15 +121,10 @@ def _deprecate_arg_args(kwargs: Dict[str, Any]): else: kwargs["element_shape"] = () else: - warnings.warn( - "The element_shape argument for ndarray is deprecated in v1.6.0, and it will be removed in v1.7.0. " - "Please use vector or matrix data type instead.", - DeprecationWarning, + raise TaichiRuntimeError( + "The element_shape argument for ndarray is deprecated in v1.6.0, and it is removed in v1.7.0. " + "Please use vector or matrix data type instead." ) - if "dtype" not in kwargs: - dtype = kwargs["dtype"] - if isinstance(dtype, MatrixType): - raise TaichiRuntimeError("Please do not specify element_shape when dtype is a matrix type.") if tag == ArgKind.RWTEXTURE or tag == ArgKind.TEXTURE: if "dtype" in kwargs: @@ -142,13 +135,10 @@ def _deprecate_arg_args(kwargs: Dict[str, Any]): del kwargs["dtype"] if "shape" in kwargs: - warnings.warn( - "The shape argument for texture is deprecated in v1.6.0, and it will be removed in v1.7.0. " - "Please use ndim instead. (Note that you no longer need the exact texture size.)", - DeprecationWarning, + raise TaichiRuntimeError( + "The shape argument for texture is deprecated in v1.6.0, and it is removed in v1.7.0. " + "Please use ndim instead. (Note that you no longer need the exact texture size.)" ) - kwargs["ndim"] = len(kwargs["shape"]) - del kwargs["shape"] if "channel_format" in kwargs or "num_channels" in kwargs: if "fmt" in kwargs: @@ -158,21 +148,15 @@ def _deprecate_arg_args(kwargs: Dict[str, Any]): if tag == ArgKind.RWTEXTURE: fmt = TY_CH2FORMAT[(kwargs["channel_format"], kwargs["num_channels"])] kwargs["fmt"] = fmt - warnings.warn( + raise TaichiRuntimeError( "The channel_format and num_channels arguments for texture are deprecated in v1.6.0, " - "and they will be removed in v1.7.0. Please use fmt instead.", - DeprecationWarning, + "and they are removed in v1.7.0. Please use fmt instead." ) else: - warnings.warn( + raise TaichiRuntimeError( "The channel_format and num_channels arguments are no longer required for non-RW textures " - "since v1.6.0, and they will be removed in v1.7.0. Please remove them.", - DeprecationWarning, + "since v1.6.0, and they are removed in v1.7.0. Please remove them." ) - if "channel_format" in kwargs: - del kwargs["channel_format"] - if "num_channels" in kwargs: - del kwargs["num_channels"] def _check_args(kwargs: Dict[str, Any], allowed_kwargs: List[str]): diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index b1dd882f970c7..2672f8095352f 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -9,41 +9,41 @@ @test_utils.test() -def test_deprecate_element_shape_scalar(): - with pytest.warns( - DeprecationWarning, - match="The element_shape argument for scalar is deprecated in v1.6.0, and will be removed in v1.7.0. " +def test_remove_element_shape_scalar(): + with pytest.raises( + ti.TaichiRuntimeError, + match="The element_shape argument for scalar is deprecated in v1.6.0, and is removed in v1.7.0. " "Please remove them.", ): sym_x = ti.graph.Arg(ti.graph.ArgKind.SCALAR, "x", dtype=ti.f32, element_shape=()) @test_utils.test() -def test_deprecate_element_shape_ndarray_arg(): - with pytest.warns( - DeprecationWarning, - match="The element_shape argument for ndarray is deprecated in v1.6.0, and it will be removed in v1.7.0. " +def test_remove_element_shape_ndarray_arg(): + with pytest.raises( + ti.TaichiRuntimeError, + match="The element_shape argument for ndarray is deprecated in v1.6.0, and it is removed in v1.7.0. " "Please use vector or matrix data type instead.", ): ti.graph.Arg(ti.graph.ArgKind.NDARRAY, "x", ti.f32, ndim=1, element_shape=(1,)) @test_utils.test() -def test_deprecate_texture_channel_format_num_channels(): - with pytest.warns( - DeprecationWarning, +def test_remove_texture_channel_format_num_channels(): + with pytest.raises( + ti.TaichiRuntimeError, match="The channel_format and num_channels arguments are no longer required for non-RW textures " - "since v1.6.0, and they will be removed in v1.7.0. Please remove them.", + "since v1.6.0, and they are removed in v1.7.0. Please remove them.", ): ti.graph.Arg(ti.graph.ArgKind.TEXTURE, "x", ndim=2, channel_format=ti.f32, num_channels=1) @test_utils.test() -def test_deprecate_rwtexture_channel_format_num_channels(): - with pytest.warns( - DeprecationWarning, +def test_remove_rwtexture_channel_format_num_channels(): + with pytest.raises( + ti.TaichiRuntimeError, match="The channel_format and num_channels arguments for texture are deprecated in v1.6.0, " - "and they will be removed in v1.7.0. Please use fmt instead.", + "and they are removed in v1.7.0. Please use fmt instead.", ): ti.graph.Arg( ti.graph.ArgKind.RWTEXTURE, @@ -55,20 +55,20 @@ def test_deprecate_rwtexture_channel_format_num_channels(): @test_utils.test() -def test_deprecate_texture_ndim(): - with pytest.warns( - DeprecationWarning, - match=r"The shape argument for texture is deprecated in v1.6.0, and it will be removed in v1.7.0. " +def test_remove_texture_ndim(): + with pytest.raises( + ti.TaichiRuntimeError, + match=r"The shape argument for texture is deprecated in v1.6.0, and it is removed in v1.7.0. " r"Please use ndim instead. \(Note that you no longer need the exact texture size.\)", ): ti.graph.Arg(ti.graph.ArgKind.TEXTURE, "x", shape=(128, 128), channel_format=ti.f32) @test_utils.test() -def test_deprecate_rwtexture_ndim(): - with pytest.warns( - DeprecationWarning, - match=r"The shape argument for texture is deprecated in v1.6.0, and it will be removed in v1.7.0. " +def test_remove_rwtexture_ndim(): + with pytest.raises( + ti.TaichiRuntimeError, + match=r"The shape argument for texture is deprecated in v1.6.0, and it is removed in v1.7.0. " r"Please use ndim instead. \(Note that you no longer need the exact texture size.\)", ): ti.graph.Arg(ti.graph.ArgKind.RWTEXTURE, "x", shape=(128, 128), fmt=ti.Format.r32f) From 1400dd657d529d6bac8a8bf757df088a954125e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Nov 2023 03:10:55 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/python/test_deprecation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index 2672f8095352f..623d4ed573751 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -67,7 +67,7 @@ def test_remove_texture_ndim(): @test_utils.test() def test_remove_rwtexture_ndim(): with pytest.raises( - ti.TaichiRuntimeError, + ti.TaichiRuntimeError, match=r"The shape argument for texture is deprecated in v1.6.0, and it is removed in v1.7.0. " r"Please use ndim instead. \(Note that you no longer need the exact texture size.\)", ): From 57e7648e6cd8280395ed41cead8a4267c36a0558 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Mon, 20 Nov 2023 11:10:26 +0800 Subject: [PATCH 3/6] Update C-Graph API for CapiTest.GraphTestVulkanTextureGraph --- .../aot/python_scripts/texture_aot_test_.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/cpp/aot/python_scripts/texture_aot_test_.py b/tests/cpp/aot/python_scripts/texture_aot_test_.py index dba20cfd6d6df..23377634ed34b 100644 --- a/tests/cpp/aot/python_scripts/texture_aot_test_.py +++ b/tests/cpp/aot/python_scripts/texture_aot_test_.py @@ -44,30 +44,24 @@ def run2( _tex0 = ti.graph.Arg( ti.graph.ArgKind.TEXTURE, "tex0", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, ) _rw_tex0 = ti.graph.Arg( ti.graph.ArgKind.RWTEXTURE, "rw_tex0", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, + fmt=ti.Format.r32f, ) _tex1 = ti.graph.Arg( ti.graph.ArgKind.TEXTURE, "tex1", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, ) _rw_tex1 = ti.graph.Arg( ti.graph.ArgKind.RWTEXTURE, "rw_tex1", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, + fmt=ti.Format.r32f, ) _arr = ti.graph.Arg(ti.graph.ArgKind.NDARRAY, "arr", dtype=ti.f32, ndim=2) From 3346e154433b1e2c4cb10f7f31300821afe697f5 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Mon, 20 Nov 2023 13:39:38 +0800 Subject: [PATCH 4/6] fix test_graph.py --- tests/python/test_graph.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/python/test_graph.py b/tests/python/test_graph.py index 6e68344a7d112..a472bb7af0b84 100644 --- a/tests/python/test_graph.py +++ b/tests/python/test_graph.py @@ -373,16 +373,13 @@ def paint( _rw_tex = ti.graph.Arg( ti.graph.ArgKind.RWTEXTURE, "rw_tex", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, + fmt=ti.Format.r32f, ) _tex = ti.graph.Arg( ti.graph.ArgKind.TEXTURE, "tex", - channel_format=ti.f32, - shape=(128, 128), - num_channels=1, + ndim=2, ) g_builder = ti.graph.GraphBuilder() @@ -452,9 +449,8 @@ def read(tex: ti.types.texture(num_dimensions=2), arr: ti.types.ndarray()): sym_tex = ti.graph.Arg( ti.graph.ArgKind.RWTEXTURE, "tex", - channel_format=ti.f32, - shape=res, - num_channels=1, + fmt=ti.Format.r32f, + ndim=2, ) sym_arr = ti.graph.Arg(ti.graph.ArgKind.NDARRAY, "arr", ti.f32, ndim=2) From a47408f82e33ff567e83139bca03e9439848b162 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Mon, 20 Nov 2023 13:42:37 +0800 Subject: [PATCH 5/6] bug fix --- .github/workflows/scripts/aot-demo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/aot-demo.sh b/.github/workflows/scripts/aot-demo.sh index 14ecf441f9aa9..4c12111156304 100755 --- a/.github/workflows/scripts/aot-demo.sh +++ b/.github/workflows/scripts/aot-demo.sh @@ -6,13 +6,13 @@ export TI_CI=1 # IF YOU PIN THIS TO A COMMIT/BRANCH, YOU'RE RESPONSIBLE TO REVERT IT BACK TO MASTER ONCE MERGED. export TAICHI_AOT_DEMO_URL=https://github.com/taichi-dev/taichi-aot-demo -export TAICHI_AOT_DEMO_BRANCH=master +export TAICHI_AOT_DEMO_BRANCH=update_cgraph_api export TAICHI_UNITY2_URL=https://github.com/taichi-dev/taichi-unity2 export TAICHI_UNITY2_BRANCH=main export TAICHI_UNITY_EXAMPLE_URL=https://github.com/taichi-dev/Taichi-UnityExample -export TAICHI_UNITY_EXAMPLE_BRANCH=main +export TAICHI_UNITY_EXAMPLE_BRANCH=update_cgraph_api . $(dirname $0)/common-utils.sh From ad7341b10caa6a908b17672ad7256541f2cf74a6 Mon Sep 17 00:00:00 2001 From: jim19930609 Date: Wed, 22 Nov 2023 10:21:11 +0800 Subject: [PATCH 6/6] bug fix --- .github/workflows/scripts/aot-demo.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/scripts/aot-demo.sh b/.github/workflows/scripts/aot-demo.sh index 4c12111156304..14ecf441f9aa9 100755 --- a/.github/workflows/scripts/aot-demo.sh +++ b/.github/workflows/scripts/aot-demo.sh @@ -6,13 +6,13 @@ export TI_CI=1 # IF YOU PIN THIS TO A COMMIT/BRANCH, YOU'RE RESPONSIBLE TO REVERT IT BACK TO MASTER ONCE MERGED. export TAICHI_AOT_DEMO_URL=https://github.com/taichi-dev/taichi-aot-demo -export TAICHI_AOT_DEMO_BRANCH=update_cgraph_api +export TAICHI_AOT_DEMO_BRANCH=master export TAICHI_UNITY2_URL=https://github.com/taichi-dev/taichi-unity2 export TAICHI_UNITY2_BRANCH=main export TAICHI_UNITY_EXAMPLE_URL=https://github.com/taichi-dev/Taichi-UnityExample -export TAICHI_UNITY_EXAMPLE_BRANCH=update_cgraph_api +export TAICHI_UNITY_EXAMPLE_BRANCH=main . $(dirname $0)/common-utils.sh