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

Simplify the implementation of Taichi ops in Python #7447

Closed
3 tasks done
strongoier opened this issue Feb 27, 2023 · 0 comments
Closed
3 tasks done

Simplify the implementation of Taichi ops in Python #7447

strongoier opened this issue Feb 27, 2023 · 0 comments
Labels
refactor Refactor of API or codebases

Comments

@strongoier
Copy link
Contributor

strongoier commented Feb 27, 2023

Currently, Taichi ops in Python are implemented in a complicated way. Matrix, Struct, Expr classes inherit from TaichiOperations to make sure they support the same set of ops. The actual implementation of the ops are in https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/ops.py, which contains complicated dispatching according to whether a value is a Taichi expr or a Python value, a scalar or a compound type value, ... However, much of the logic is unnecessary because only a small set of code paths are actually valid. It will be much cleaner to only keep those valid paths. Therefore, I propose to simplify the logic in the following steps:

  • Deprecate arithmetic ops and fill of Struct in v1.5.0, and remove them in v1.6.0. Such support is simply uncommon and unnecessary.
  • Stop making Struct inherit from TaichiOperations by implementing necessary ops like assign.
  • Replace the internal representation of Matrix with numpy arrays and remove redundant code paths in ops.py.
@strongoier strongoier added the refactor Refactor of API or codebases label Feb 27, 2023
@github-project-automation github-project-automation bot moved this to Untriaged in Taichi Lang Feb 27, 2023
strongoier added a commit that referenced this issue Mar 1, 2023
Issue: #7447

### Brief Summary

This PR corresponds to step 1 of #7447.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@erizmr erizmr moved this from Untriaged to In Progress in Taichi Lang Mar 3, 2023
strongoier added a commit that referenced this issue Mar 13, 2023
Issue: #7447

### Brief Summary

This PR corresponds to step 2 of #7447.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
ailzhang pushed a commit that referenced this issue Mar 17, 2023
… numpy arrays (#7559)

Issue: #7447

### Brief Summary

This PR corresponds to step 3 of #7447. The code paths in `matrix.py`
and `ops.py` have been significantly simplified:
- The `Matrix` class, which is for Python scope, now only contains two
cases, numpy arrays for values and nested lists for host access of
`SNode`/`Ndarray`. Redundant internal functions have been removed. `dt`
now has effects because numpy arrays have types.
- No more `element_wise_xxx`, `uniform_matrix_inputs` and `@unary,
@binary` decorators. The full dispatching logic for ops is in unique
entrances `_unary_operation/_binary_operation`.

Note that Python-scope matrix slicing is temporarily disabled in this PR
because the feature itself is incomplete - only read is supported. It
can be re-supported in a better way in the future. Taichi-scope matrix
slicing still works properly.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@github-project-automation github-project-automation bot moved this from In Progress to Done in Taichi Lang Mar 17, 2023
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…i-dev#7456)

Issue: taichi-dev#7447

### Brief Summary

This PR corresponds to step 1 of taichi-dev#7447.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
…ev#7474)

Issue: taichi-dev#7447

### Brief Summary

This PR corresponds to step 2 of taichi-dev#7447.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
… numpy arrays (taichi-dev#7559)

Issue: taichi-dev#7447

### Brief Summary

This PR corresponds to step 3 of taichi-dev#7447. The code paths in `matrix.py`
and `ops.py` have been significantly simplified:
- The `Matrix` class, which is for Python scope, now only contains two
cases, numpy arrays for values and nested lists for host access of
`SNode`/`Ndarray`. Redundant internal functions have been removed. `dt`
now has effects because numpy arrays have types.
- No more `element_wise_xxx`, `uniform_matrix_inputs` and `@unary,
@binary` decorators. The full dispatching logic for ops is in unique
entrances `_unary_operation/_binary_operation`.

Note that Python-scope matrix slicing is temporarily disabled in this PR
because the feature itself is incomplete - only read is supported. It
can be re-supported in a better way in the future. Taichi-scope matrix
slicing still works properly.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor of API or codebases
Projects
Status: Done
Development

No branches or pull requests

1 participant