MyGit

v0.9.0

taichi-dev/taichi

版本发布时间: 2022-02-22 20:14:16

taichi-dev/taichi最新发布版本:v1.7.2(2024-08-22 16:59:46)

Highlights

New features

1. Dynamic indexing of matrices (experimental)

In previous versions of Taichi, a matrix can be accessed only with a constant index. As a result, you cannot perform operations such as clamp the minimum element in a vector to 0:

@ti.kernel
def clamp():
    ...  # assume we have a n-d vector A
    min_index = 0
    for i in range(n):
        if A[i] < A[min_index]:
            min_index = i
    A[min_index] = 0

Of course, you may use the following workaround leveraging loop unrolling. It is, however, neither intuitive nor efficient:

@ti.kernel
def clamp():
    ...  # assume we have a n-d vector A
    min_index = 0
    for i in ti.static(range(n)):
        if A[i] < A[min_index]:
            min_index = i
    for i in ti.static(range(n)):
        if i == min_index:
            A[i] = 0

With this new experimental feature of dynamic indexing of matrices, you can now run the former code snippet smoothly. The feature can be enabled by setting ti.init(dynamic_index=True).

In v0.9.0, a new implicit FEM (Finite Element Method) example (https://github.com/taichi-dev/taichi/blob/master/python/taichi/examples/simulation/implicit_fem.py) is added, which also illustrates the benefit of having this feature. In this example, a huge (12 × 12) Hessian matrix is constructed for implicit time integration. Without dynamic indexing, the whole matrix construction loop needs to be unrolled, which takes 70 seconds to compile; with dynamic indexing, a traditional loop version can be applied, and the compilation time is shortened to 2.5 seconds.

2. Vulkan backend on macOS

Adds support for the ti.vulkan backend on macOS 10.15+ and now you can run GGUI on your macBook. Run the following GGUI examples to try for yourself.

# prerequisites: taichi >= v0.9.0 and macOS >= 10.15
# run GGUI examples
ti example fractal3d_ggui 
ti example fem128_ggui

3. Compatibility with Google Colab

The system would crash if you run Taichi of an earlier version in the Google Colab notebook environment (see #235 for more information). In this release, we refactored our compiler implementation so that Taichi is compatible with Google Colab.

Feel free to run !pip install taichi to install Taichi and start your Colab journey with it.

Improvements

1. More stabilized, better-organized APIs

Ensuring the developers use the right set of APIs is critical to the long-term stability of Taichi's APIs. In this release, we started to reorganize its package structure and deprecate some obsolete or internal APIs. The following table lists some critical APIs that may concern you.

Category Deprecated API Replaced with
Builtin max() ti.max()
Builtin min() ti.min()
Atomic operation obj.atomic_add() ti.atomic_add()
Image-specific ti.imread() ti.tools.imread()
Image-specific ti.imwrite() ti.tools.imwrite()
Image-specific ti.imshow() ti.tools.imshow()
Profiler-specific ti.print_profile_info() ti.profiler.print_scoped_profiler_info()
Profiler-specific ti.print_kernel_profile_info() ti.profiler.print_kernel_profiler_info()

For a representative list of APIs deprecated in this release, see this Google doc.

2. Better error reporting

Lengthy traceback in an error report, for most of the time, can be distracting, making it hard to locate the code causing the error. In this release, we've removed the trivial traceback that does not concern developers in our error reporting to improve the debugging experience.

Taking the following code snippet as an example:

import taichi as ti

ti.init()

@ti.func
def bar(a):
    a = a + 2j

@ti.kernel
def foo():
    bar(1)

foo()

Before v0.9.0, the error message looks like this:

[Taichi] Starting on arch=x64
Traceback (most recent call last):
  File "error.py", line 13, in <module>
    foo()
  File "/path_to_taichi/lang/kernel_impl.py", line 709, in wrapped
    return primal(*args, **kwargs)
  File "/path_to_taichi/lang/kernel_impl.py", line 636, in __call__
    key = self.ensure_compiled(*args)
  File "/path_to_taichi/lang/kernel_impl.py", line 627, in ensure_compiled
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/path_to_taichi/lang/kernel_impl.py", line 493, in materialize
    taichi_kernel = _ti_core.create_kernel(taichi_ast_generator,
  File "/path_to_taichi/lang/kernel_impl.py", line 488, in taichi_ast_generator
    compiled()
  File "error.py", line 11, in foo
    bar(1)
  File "/path_to_taichi/lang/kernel_impl.py", line 76, in decorated
    return fun.__call__(*args)
  File "/path_to_taichi/lang/kernel_impl.py", line 156, in __call__
    ret = self.compiled(*args)
  File "error.py", line 7, in bar
    a = a + 2j
  File "/path_to_taichi/lang/common_ops.py", line 16, in __add__
    return ti.add(self, other)
  File "/path_to_taichi/lang/ops.py", line 78, in wrapped
    return imp_foo(a, b)
  File "/path_to_taichi/lang/ops.py", line 63, in imp_foo
    return foo(x, y)
  File "/path_to_taichi/lang/ops.py", line 427, in add
    return _binary_operation(_ti_core.expr_add, _bt_ops_mod.add, a, b)
  File "/path_to_taichi/lang/ops.py", line 173, in _binary_operation
    a, b = wrap_if_not_expr(a), wrap_if_not_expr(b)
  File "/path_to_taichi/lang/ops.py", line 36, in wrap_if_not_expr
    return Expr(a) if not is_taichi_expr(a) else a
  File "/path_to_taichi/lang/expr.py", line 33, in __init__
    self.ptr = impl.make_constant_expr(arg).ptr
  File "/path_to_taichi/lang/util.py", line 196, in wrapped
    return func(*args, **kwargs)
  File "/path_to_taichi/lang/impl.py", line 414, in make_constant_expr
    raise ValueError(f'Invalid constant scalar expression: {type(val)}')
ValueError: Invalid constant scalar expression: <class 'complex'>

In v0.9.0, the error message looks like this:

Traceback (most recent call last):
  File "/path_to_test/error.py", line 13, in <module>
    foo()
  File "/path_to_taichi/lang/kernel_impl.py", line 732, in wrapped
    raise type(e)('\n' + str(e)) from None
taichi.lang.exception.TaichiTypeError: 
On line 11 of file "/path_to_test/error.py", in foo:
    bar(1)
    ^^^^^^
On line 7 of file "/path_to_test/error.py", in bar:
    a = a + 2j
        ^^^^^^
Invalid constant scalar data type: <class 'complex'>

3. Revamped Taichi's documentation site

To improve the readability and user-friendliness of our documentation, we restructured Taichi's documentation site and incorporated API reference into it.

Join our discussions to build the next Taichi release for you!

We believe that our community plays a pivotal role in the development of the Taichi programming language. In that spirit, we encourage you to take an active part in our GitHub Discussions, propose potential changes, and contribute your ideas. Together, we improve the Taichi language release by release, for you and for every developer.

The following is a selected list of hot topics for you to start with:

Specifically, because beginners to Taichi sometimes get lost in different APIs such as ti.Vector, ti.types.vector, ti.Vector.field, we plan to make them clearer and would like to have your opinions on these proposed practices:

API changes

See this Google doc for a representative list of APIs deprecated in this release.

Deprecation notice

Python 3.6 has reached EOL as of December 2021. The next major Taichi release (e.g. v1.0) will be the last official release for Python3.6 and we're actively working on adding support for Python3.10.

Full changelog:

相关地址:原始地址 下载(tar) 下载(zip)

查看:2022-02-22发行的版本