Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lang] Remove deprecated graph arguments #8410

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 13 additions & 29 deletions python/taichi/graph/_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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]):
Expand Down
18 changes: 6 additions & 12 deletions tests/cpp/aot/python_scripts/texture_aot_test_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
48 changes: 24 additions & 24 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
14 changes: 5 additions & 9 deletions tests/python/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down
Loading