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

[misc] Remove deprecated Python APIs #3725

Merged
merged 7 commits into from
Dec 7, 2021
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
13 changes: 2 additions & 11 deletions misc/demo_warning.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import taichi as ti

x = ti.Vector([2, 3])
x = ti.Vector([2, 2])

x.transposed(x)


@ti.kernel
def func():
x = 0
x = 0.1


func()
ti.dot(x, x)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file was used to demo the deprecated warning message. Shall well remove it then? ;)

Copy link
Contributor Author

@izackwu izackwu Dec 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, as I have removed the deprecated APi (transposed), this demo would break. So I just picked another deprecated API (yes, there're still some more APIs to deprecate in the codebase and they are not included in this PR) for the demo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha I see, makes sense! Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ailzhang Do we need another issue for other deprecated APIs not covered here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

glad to help if we're going to remove all remaining deprecated APIs :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@izackwu awesome thanks! Would you mind opening an issue as well? Thanks a lot!

27 changes: 2 additions & 25 deletions python/taichi/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
chain_compare, current_cfg, expr_init,
expr_init_func, expr_init_list, field,
get_runtime, global_subscript_with_offset,
grouped, indices, insert_expr_stmt_if_ti_func,
grouped, insert_expr_stmt_if_ti_func,
local_subscript_with_offset,
materialize_callback, ndarray, one, root, static,
static_assert, static_print, stop_grad,
subscript, ti_assert, ti_float, ti_format,
ti_int, ti_print, var, zero)
ti_int, ti_print, zero)
from taichi.lang.kernel_arguments import SparseMatrixProxy
from taichi.lang.kernel_impl import (KernelArgError, KernelDefError,
data_oriented, func, kernel, pyfunc)
Expand Down Expand Up @@ -133,11 +133,6 @@
type_factory_ = _ti_core.get_type_factory_instance()


@deprecated('kernel_profiler_print()', 'print_kernel_profile_info()')
def kernel_profiler_print():
return print_kernel_profile_info()


def print_kernel_profile_info(mode='count'):
"""Print the profiling results of Taichi kernels.

Expand Down Expand Up @@ -220,11 +215,6 @@ def query_kernel_profile_info(name):
return get_default_kernel_profiler().query_info(name)


@deprecated('kernel_profiler_clear()', 'clear_kernel_profile_info()')
def kernel_profiler_clear():
return clear_kernel_profile_info()


def clear_kernel_profile_info():
"""Clear all KernelProfiler records."""
get_default_kernel_profiler().clear_info()
Expand Down Expand Up @@ -334,11 +324,6 @@ def collect_kernel_profile_metrics(metric_list=default_cupti_metrics):
get_default_kernel_profiler().set_metrics()


@deprecated('memory_profiler_print()', 'print_memory_profile_info()')
def memory_profiler_print():
return print_memory_profile_info()


def print_memory_profile_info():
"""Memory profiling tool for LLVM backends with full sparse support.

Expand Down Expand Up @@ -703,11 +688,6 @@ def mesh_local(*args):
_ti_core.SNodeAccessFlag.mesh_local, v.ptr)


@deprecated('ti.cache_shared', 'ti.block_local')
def cache_shared(*args):
block_local(*args)


def cache_read_only(*args):
for a in args:
for v in a.get_field_members():
Expand Down Expand Up @@ -738,9 +718,6 @@ def loop_unique(val, covers=None):
global_thread_idx = _ti_core.insert_thread_idx_expr
mesh_patch_idx = _ti_core.insert_patch_idx_expr

inversed = deprecated('ti.inversed(a)', 'a.inverse()')(Matrix.inversed)
transposed = deprecated('ti.transposed(a)', 'a.transpose()')(Matrix.transposed)


def polar_decompose(A, dt=None):
"""Perform polar decomposition (A=UP) for arbitrary size matrix.
Expand Down
18 changes: 2 additions & 16 deletions python/taichi/lang/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from taichi.lang.util import (cook_dtype, is_taichi_class, python_scope,
taichi_scope)
from taichi.snode.fields_builder import FieldsBuilder
from taichi.tools.util import deprecated, get_traceback, warning
from taichi.tools.util import get_traceback, warning
from taichi.types.primitive_types import f16, f32, f64, i32, i64, u32, u64

import taichi as ti
Expand Down Expand Up @@ -242,7 +242,7 @@ def global_subscript_with_offset(_var, _indices, shape, is_aos):
def chain_compare(comparators, ops):
_taichi_skip_traceback = 1
assert len(comparators) == len(ops) + 1, \
f'Chain comparison invoked with {len(comparators)} comparators but {len(ops)} operators'
f'Chain comparison invoked with {len(comparators)} comparators but {len(ops)} operators'
ret = True
for i, op in enumerate(ops):
lhs = comparators[i]
Expand Down Expand Up @@ -594,12 +594,6 @@ def create_field_member(dtype, name):
return x, x_grad


@deprecated('ti.var', 'ti.field')
def var(dt, shape=None, offset=None, needs_grad=False):
_taichi_skip_traceback = 1
return field(dt, shape, offset, needs_grad)


@python_scope
def field(dtype, shape=None, name="", offset=None, needs_grad=False):
"""Defines a Taichi field
Expand Down Expand Up @@ -837,14 +831,6 @@ def axes(*x: Iterable[int]):
return [_ti_core.Axis(i) for i in x]


@deprecated("ti.indices", "ti.axes")
def indices(*x):
"""Same as :func:`~taichi.lang.impl.axes`."""
return [_ti_core.Axis(i) for i in x]


index = indices

Axis = _ti_core.Axis


Expand Down
29 changes: 0 additions & 29 deletions python/taichi/lang/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,6 @@ def normalized(self, eps=0):
invlen = 1 / (self.norm() + eps)
return invlen * self

@staticmethod
@deprecated('ti.Matrix.transposed(a)', 'a.transpose()')
def transposed(a):
return a.transpose()

@deprecated('a.T()', 'a.transpose()')
def T(self):
return self.transpose()

@kern_mod.pyfunc
def transpose(self):
"""Get the transpose of a matrix.
Expand Down Expand Up @@ -900,27 +891,12 @@ def field(cls,
shape).place(entries_grad, offset=offset)
return entries

@classmethod
@python_scope
@deprecated('ti.Matrix.var', 'ti.Matrix.field')
def var(cls, n, m, dt, *args, **kwargs):
"""ti.Matrix.var"""
_taichi_skip_traceback = 1
return cls.field(n, m, dt, *args, **kwargs)

@classmethod
def _Vector_field(cls, n, dtype, *args, **kwargs):
"""ti.Vector.field"""
_taichi_skip_traceback = 1
return cls.field(n, 1, dtype, *args, **kwargs)

@classmethod
@deprecated('ti.Vector.var', 'ti.Vector.field')
def _Vector_var(cls, n, dt, *args, **kwargs):
"""ti.Vector.var"""
_taichi_skip_traceback = 1
return cls._Vector_field(n, dt, *args, **kwargs)

@classmethod
@python_scope
def ndarray(cls, n, m, dtype, shape, layout=Layout.AOS):
Expand Down Expand Up @@ -1097,7 +1073,6 @@ def Vector(n, dt=None, **kwargs):
return Matrix(n, 1, dt=dt, **kwargs)


Vector.var = Matrix._Vector_var
Vector.field = Matrix._Vector_field
Vector.ndarray = Matrix._Vector_ndarray
Vector.zero = Matrix.zero
Expand Down Expand Up @@ -1143,10 +1118,6 @@ def __init__(self, _vars, n, m):
self.n = n
self.m = m

@deprecated('x(i, j)', 'x.get_scalar_field(i, j)')
def __call__(self, *indices):
return self.get_scalar_field(*indices)

def get_scalar_field(self, *indices):
"""Creates a ScalarField using a specific field member. Only used for quant.

Expand Down
29 changes: 1 addition & 28 deletions python/taichi/lang/snode.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from taichi.core.util import ti_core as _ti_core
from taichi.lang import impl
from taichi.lang.field import Field
from taichi.tools.util import deprecated


class SNode:
Expand Down Expand Up @@ -102,10 +101,6 @@ def bitmasked(self, axes, dimensions):
self.ptr.bitmasked(axes, dimensions,
impl.current_cfg().packed))

@deprecated('_bit_struct', 'bit_struct')
def _bit_struct(self, num_bits):
return self.bit_struct(num_bits)

def bit_struct(self, num_bits: int):
"""Adds a bit_struct SNode as a child component of `self`.

Expand All @@ -117,10 +112,6 @@ def bit_struct(self, num_bits: int):
"""
return SNode(self.ptr.bit_struct(num_bits, impl.current_cfg().packed))

@deprecated('_bit_array', 'bit_array')
def _bit_array(self, axes, dimensions, num_bits):
return self.bit_array(axes, dimensions, num_bits)

def bit_array(self, axes, dimensions, num_bits):
"""Adds a bit_array SNode as a child component of `self`.

Expand Down Expand Up @@ -209,14 +200,6 @@ def dtype(self):
"""
return self.ptr.data_type()

@deprecated('x.data_type()', 'x.dtype')
def data_type(self):
return self.dtype

@deprecated('x.dim()', 'len(x.shape)')
def dim(self):
return len(self.shape)

@property
def id(self):
"""Gets the id of `self`.
Expand All @@ -234,20 +217,10 @@ def shape(self):
Tuple[int]: The number of elements from root in each axis of `self`.
"""
dim = self.ptr.num_active_indices()
ret = [self.ptr.get_shape_along_axis(i) for i in range(dim)]

class callable_tuple(tuple):
@deprecated('x.shape()', 'x.shape')
def __call__(self):
return self
ret = tuple(self.ptr.get_shape_along_axis(i) for i in range(dim))

ret = callable_tuple(ret)
return ret

@deprecated('x.get_shape(i)', 'x.shape[i]')
def get_shape(self, i):
return self.shape[i]

def loop_range(self):
"""Gets the taichi_core.Expr wrapping the taichi_core.GlobalVariableExpression corresponding to `self` to serve as loop range.

Expand Down
10 changes: 0 additions & 10 deletions python/taichi/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,6 @@ def clear_profile_info():
_ti_core.clear_profile_info()


@deprecated('ti.vec(x, y)', 'ti.core_vec(x, y)')
def vec(*args, **kwargs):
return core_vec(*args, **kwargs)


@deprecated('ti.veci(x, y)', 'ti.core_veci(x, y)')
def veci(*args, **kwargs):
return core_veci(*args, **kwargs)


def dump_dot(filepath=None, rankdir=None, embed_states_threshold=0):
d = _ti_core.dump_dot(rankdir, embed_states_threshold)
if filepath is not None:
Expand Down
34 changes: 15 additions & 19 deletions python/taichi/ui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import taichi.lang
from taichi.core import ti_core as _ti_core
from taichi.lang.field import Field, ScalarField
from taichi.tools.util import core_veci, deprecated
from taichi.tools.util import core_veci

import taichi as ti

Expand Down Expand Up @@ -112,7 +112,7 @@ def __del__(self):
def close(self):
self.core = None # dereference to call GUI::~GUI()

## Widget system
# Widget system

class WidgetValue:
def __init__(self, gui, wid):
Expand Down Expand Up @@ -185,7 +185,7 @@ def button(self, text, event_name=None):
self.core.make_button(text, event_name)
return event_name

## Drawing system
# Drawing system

def clear(self, color=None):
"""Clear the canvas with the color provided.
Expand Down Expand Up @@ -249,13 +249,13 @@ def set_image(self, img):

if self.fast_gui:
assert isinstance(img, taichi.lang.matrix.MatrixField), \
"Only ti.Vector.field is supported in GUI.set_image when fast_gui=True"
"Only ti.Vector.field is supported in GUI.set_image when fast_gui=True"
assert img.shape == self.res, \
"Image resolution does not match GUI resolution"
"Image resolution does not match GUI resolution"
assert img.n in [3, 4] and img.m == 1, \
"Only RGB images are supported in GUI.set_image when fast_gui=True"
"Only RGB images are supported in GUI.set_image when fast_gui=True"
assert img.dtype in [ti.f32, ti.f64, ti.u8], \
"Only f32, f64, u8 are supported in GUI.set_image when fast_gui=True"
"Only f32, f64, u8 are supported in GUI.set_image when fast_gui=True"

taichi.lang.meta.vector_to_fast_image(img, self.img)
return
Expand All @@ -267,7 +267,7 @@ def set_image(self, img):
else:
# Type matched! We can use an optimized copy kernel.
assert img.shape \
== self.res, "Image resolution does not match GUI resolution"
== self.res, "Image resolution does not match GUI resolution"
taichi.lang.meta.tensor_to_image(img, self.img)
ti.sync()

Expand All @@ -276,10 +276,10 @@ def set_image(self, img):
self.img = self.cook_image(img.to_numpy())
else:
# Type matched! We can use an optimized copy kernel.
assert img.shape == self.res, \
"Image resolution does not match GUI resolution"
assert img.shape == self.res, \
"Image resolution does not match GUI resolution"
assert img.n in [2, 3, 4] and img.m == 1, \
"Only greyscale, RG, RGB or RGBA images are supported in GUI.set_image"
"Only greyscale, RG, RGB or RGBA images are supported in GUI.set_image"

taichi.lang.meta.vector_to_image(img, self.img)
ti.sync()
Expand Down Expand Up @@ -665,7 +665,7 @@ def show(self, file=None):
self.frame += 1
self.clear()

## Event system
# Event system

class EventFilter:
def __init__(self, *e_filter):
Expand Down Expand Up @@ -793,12 +793,6 @@ def get_cursor_pos(self):
pos = self.core.get_cursor_pos()
return pos[0], pos[1]

@deprecated('gui.has_key_pressed()', 'gui.get_event()')
def has_key_pressed(self):
if self.has_key_event():
self.get_key_event() # pop to update self.key_pressed
return len(self.key_pressed) != 0

@property
def running(self):
"""Get the property of whether the gui is running.
Expand Down Expand Up @@ -846,7 +840,9 @@ def rgb_to_hex(c):
The hex representation of color.

"""
to255 = lambda x: np.clip(np.int32(x * 255), 0, 255)
def to255(x):
return np.clip(np.int32(x * 255), 0, 255)

return (to255(c[0]) << 16) + (to255(c[1]) << 8) + to255(c[2])


Expand Down
2 changes: 1 addition & 1 deletion tests/python/bls_test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def bls_test_template(dim,
dense=False):
x, y, y2 = ti.field(ti.i32), ti.field(ti.i32), ti.field(ti.i32)

index = ti.indices(*range(dim))
index = ti.axes(*range(dim))
mismatch = ti.field(ti.i32, shape=())

if not isinstance(bs, (tuple, list)):
Expand Down
Loading