Taichi: Problems with SNodes

Created on 11 Aug 2020  路  2Comments  路  Source: taichi-dev/taichi

First, thanks for the awesome work! I've just started to use Taichi, so I am not entirely sure if this might be a bug or just not enough understanding from my side. I hope I don't bother you with a completely silly question

Describe the bug
If I try to reproduce the example for snode.shape() from the documentation of the Structural nodes I do not get the expected dimensions. The child node seems to influence the parent node

A second issue is, that the example for snode.place() throws an assertion error, which from my understanding I feel it shouldn't

To Reproduce

w = ti.field(ti.f32)
x = ti.field(ti.f32)
y = ti.field(ti.f32)
z = ti.field(ti.f32)

blk1 = ti.root
blk2 = blk1.dense(ti.i,  3)
blk3 = blk2.dense(ti.jk, (5, 2))
blk4 = blk3.dense(ti.k,  2)

blk1.place(w)
blk2.place(x)
blk3.place(y)
blk4.place(z)

print(w.shape)
print(x.shape)
print(y.shape)
print(z.shape)
````
Output

[Taichi] Starting on arch=x64
[Taichi] materializing...
()
(3,)
(3, 5, 4)
(3, 5, 4)

From my understanding `y.shape` should yield `(3,5,2)` since the child nodes inherit the structure from the parents, but do not influence them



Regarding the second point: The following code throws an assertion error on my machine (example from the documentation)

x = ti.field(dtype=ti.i32)
y = ti.field(dtype=ti.f32)
ti.root.place(x, y)
assert x.snode == y.snode
```

potential bug

Most helpful comment

Hi, I don't know if this has been fixed, but

x.snode.parent == y.snode.parent 

evaluates to False for this example as well. I've printed the types of the objects for convenience. I must confess that I don't fully understand how SNodes work yet, so I don't know if this is a silly question or something of interest. Anyway, here's what I ran:

import taichi as ti 

ti.init()

x = ti.field(dtype=ti.i32)
y = ti.field(dtype=ti.f32)
ti.root.place(x, y)

print(0, x.snode == y.snode, type(x.snode))
print(1, x.snode.parent() == y.snode.parent(), type(x.snode.parent()))
print(2, x.snode.parent(2) == y.snode.parent(2), type(x.snode.parent(2)))

And here's the output:

[Taichi] mode=release
[Taichi] version 0.6.25, llvm 10.0.0, commit 7fec59d4, python 3.7.6
[Taichi] Starting on arch=x64
0 False <class 'taichi.lang.snode.SNode'>
[Taichi] materializing...
1 False <class 'taichi.lang.snode.SNode'>
2 True <class 'taichi.lang.impl.Root'>

Thank you for all your work!

All 2 comments

Hi, thank for reporting.
The first one is likely introduced in #1558. Not sure if this is a bug or a feature. @yuanming-hu Any idea?

The second one:

x = ti.field(dtype=ti.i32)
y = ti.field(dtype=ti.f32)
ti.root.place(x, y)
assert x.snode == y.snode

It seems to me that the doc is wrong. This is because x.snode and y.snode is of SNodeType::place.
We should use assert x.snode.parent == y.snode.parent instead. Where the parent is of SNodeType::root. Thank for pointing out!

Hi, I don't know if this has been fixed, but

x.snode.parent == y.snode.parent 

evaluates to False for this example as well. I've printed the types of the objects for convenience. I must confess that I don't fully understand how SNodes work yet, so I don't know if this is a silly question or something of interest. Anyway, here's what I ran:

import taichi as ti 

ti.init()

x = ti.field(dtype=ti.i32)
y = ti.field(dtype=ti.f32)
ti.root.place(x, y)

print(0, x.snode == y.snode, type(x.snode))
print(1, x.snode.parent() == y.snode.parent(), type(x.snode.parent()))
print(2, x.snode.parent(2) == y.snode.parent(2), type(x.snode.parent(2)))

And here's the output:

[Taichi] mode=release
[Taichi] version 0.6.25, llvm 10.0.0, commit 7fec59d4, python 3.7.6
[Taichi] Starting on arch=x64
0 False <class 'taichi.lang.snode.SNode'>
[Taichi] materializing...
1 False <class 'taichi.lang.snode.SNode'>
2 True <class 'taichi.lang.impl.Root'>

Thank you for all your work!

Was this page helpful?
0 / 5 - 0 ratings