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] [test] Improve code coverage in SNode #1214

Merged
merged 15 commits into from
Jun 23, 2020

Conversation

archibate
Copy link
Collaborator

@archibate archibate commented Jun 10, 2020

Related issue = #... (if any)

Thanks to Codecov, I found some of the Matrix functions like one and var wasn't functional at all..

Sleepy now, ff2mtoyo :)

Copy link
Collaborator

@rexwangcc rexwangcc left a comment

Choose a reason for hiding this comment

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

👍 for ⬆️ code coverage! I left my 2 cents.

python/taichi/lang/expr.py Show resolved Hide resolved
tests/python/test_linalg.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #1214 into master will decrease coverage by 0.28%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1214      +/-   ##
==========================================
- Coverage   85.60%   85.31%   -0.29%     
==========================================
  Files          18       18              
  Lines        3285     3297      +12     
  Branches      621      614       -7     
==========================================
+ Hits         2812     2813       +1     
- Misses        345      349       +4     
- Partials      128      135       +7     
Impacted Files Coverage Δ
python/taichi/lang/__init__.py 73.52% <100.00%> (+0.39%) ⬆️
python/taichi/lang/expr.py 89.75% <100.00%> (+1.69%) ⬆️
python/taichi/lang/impl.py 90.35% <100.00%> (+0.15%) ⬆️
python/taichi/lang/matrix.py 85.35% <100.00%> (-4.82%) ⬇️
python/taichi/lang/snode.py 86.81% <100.00%> (+9.47%) ⬆️
python/taichi/lang/common_ops.py 90.60% <0.00%> (-3.26%) ⬇️
python/taichi/lang/ops.py 93.65% <0.00%> (+0.82%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1bebc23...d0bb76f. Read the comment docs.

@archibate archibate requested a review from rexwangcc June 11, 2020 06:05
@archibate archibate changed the title [lang] [test] Improve code coverage in Matrix and fix some methods [lang] [test] Improve code coverage in Matrix and SNode Jun 11, 2020
Comment on lines 145 to 147
def try_materialize(self):
if not self.layout_materialized:
self.materialize_layout_callback()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@yuanming-hu What's the difference between directly self.materialize which has a if not guard too, isn't it? What's the point of Expr.layout_materialized at the first place?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why not response me so long :(

Copy link
Member

Choose a reason for hiding this comment

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

I believe he's extremely busy these days, especially last week, since he mentioned he had a paper deadline..

Copy link
Member

Choose a reason for hiding this comment

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

Sorry about the delayed reply. @archibate could you clarify your question? I'm not sure if I get you correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why you use a separate variable Expr.layout_materialized instead of simple use the existing ti.get_runtime().materialized? What the point of this design at first place?

Copy link
Member

Choose a reason for hiding this comment

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

I see - good point. I don't remember why I did that TBH. Maybe we should try to remove Expr.layout_materilized and use ti.get_runtime().materialized instead, and see if anything goes wrong (of course, in a future PR).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, I will. So far ti.get_runtime().layout_materialized is good enough in this PR, right? Or you want to revert that now?

@archibate archibate added the large changeset The PR contains a large changeset and reviewing may take times label Jun 11, 2020
@archibate archibate requested review from rexwangcc and removed request for rexwangcc June 11, 2020 15:51
@archibate archibate removed the skip ci label Jun 14, 2020
@archibate archibate requested a review from k-ye June 16, 2020 02:50
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

My feeling as a reviewer is that this PR once again tries to do too much. Initially I thought we were just going to fix some Matrix helpers that were not covered by tests. But then I found out it also touched materialize_layout and parent. Note that materialize_layout is a critical part of the system that requires careful reviews. Mixing it in will inevitably result in slow reviews...

I've left some comments, but I don't expect that will be enough to get this PR approved. I'd strongly suggest you not to touch the layout materialization part in this PR..

docs/syntax.rst Outdated Show resolved Hide resolved
docs/syntax.rst Outdated Show resolved Hide resolved
docs/syntax.rst Outdated Show resolved Hide resolved
Comment on lines 145 to 147
def try_materialize(self):
if not self.layout_materialized:
self.materialize_layout_callback()
Copy link
Member

Choose a reason for hiding this comment

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

I believe he's extremely busy these days, especially last week, since he mentioned he had a paper deadline..

tests/python/test_tensor_reflection.py Outdated Show resolved Hide resolved
p = self.ptr
for i in range(n):
p = p.parent
if p.type == impl.taichi_lang_core.SNodeType.root:
Copy link
Member

Choose a reason for hiding this comment

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

IIRC, the parent of root is nullptr, so I think we should return None instead of making a cycle?

@archibate archibate requested review from k-ye and removed request for k-ye June 17, 2020 12:30
Comment on lines 125 to 126
Expr.materialize_layout_callback = self.materialize
self.materialize_layout_callback = self.materialize
self.layout_materialized = False
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IIUC, Expr.layout_materialized is always equal to self.materialized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Brain fried by noise, TTYL.

@archibate archibate changed the title [lang] [test] Improve code coverage in Matrix and SNode [lang] [test] Improve code coverage in SNode Jun 18, 2020
@archibate
Copy link
Collaborator Author

Hi, I moved the Matrix part to #1275, hope this helps reduce your review work :)

@archibate archibate requested a review from k-ye June 18, 2020 16:09
@archibate
Copy link
Collaborator Author

Hello? Do you think this PR needs further break down? IMHO it's ready for review now.

Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

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

Sorry about my delayed review. I recently got too many things to do. This PR is actually pretty well-written. Thanks! Please address a few minor concerns.

docs/snode.rst Outdated

Equivalent to ``len(tensor.shape())``.
Equivalent to ``snode.shape()[i]``, used in Taichi-scope to prevent `[...]` being transformed to tensor access.
Copy link
Member

Choose a reason for hiding this comment

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

IIRC snode.shape gives you a tuple and using [] on that doesn't get transformed to tensor access?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Seems we treated specially in ti.subscript? Cool!

Before preprocessing:
@ti.kernel
def func():
    print(x.snode().shape()[1])

After preprocessing:
def func():
  ti.ti_print(ti.subscript(x.snode().shape(), 1))

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So can we deprecate get_shape(i) and use shape()[i] now according to the python exactly-one-way-to-do-one-thing rule?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Maybe we should directly use shape as a @property, so that users can simply do a.shape instead of a.shape().

In this way, we can deprecate dim() as well, since that's simply len(a.shape). (I think users tend to think dim is the dimensionality of vectors/matrices instead of tensors.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can't agree more, many users are confusing dim with vector dimensions. Things we could do in another PR:

  • deprecate dim().
  • make shape() a @property.
  • document mat.n, mat.m in meta.rst.

tests/python/test_tensor_reflection.py Outdated Show resolved Hide resolved
tests/python/test_tensor_reflection.py Outdated Show resolved Hide resolved
@archibate archibate requested a review from yuanming-hu June 23, 2020 16:49
Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@archibate archibate added the LGTM label Jun 23, 2020
@archibate
Copy link
Collaborator Author

Thank for approve, the 13 day PR finally draw it's end...

@archibate archibate merged commit 307b676 into taichi-dev:master Jun 23, 2020
@FantasyVR FantasyVR mentioned this pull request Jun 24, 2020
Rullec pushed a commit to Rullec/taichi that referenced this pull request Jun 26, 2020
* [lang] [test] Improve code coverage in Matrix and fix some methods

* [skip ci] enforce code format

* Improve tensor_reflection test

* Better SNode with __repr__

* [skip ci] apply

* [skip ci] Apply suggestions from code review

Co-authored-by: Ye Kuang <[email protected]>

* revert k-ye

* Revert {Expr => PyTaichi}.materalized_layout_callback

* Revert "[lang] [test] Improve code coverage in Matrix"

This reverts commit 00a05b2.

* [skip ci] Fix Matrix.snode() not found

fix

* [skip ci] loop_range().snode()

* improve & deprecate duplicated functions

* [skip ci] enforce code format

Co-authored-by: Taichi Gardener <[email protected]>
Co-authored-by: Ye Kuang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
large changeset The PR contains a large changeset and reviewing may take times
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants