Skip to content

Calling node.place(field_1) after field_2.from_numpy() raises RuntimeError "dense node must have at least one child." #8797

Description

@sunjp704

Describe the bug
Calling node.place(field_1) after field_2.from_numpy() raises RuntimeError "dense node must have at least one child."

To Reproduce

import numpy as np
import taichi as ti

ti.init(arch=ti.cuda)

node= ti.root.dense(ti.ij, (3, 2))
field_1 = ti.field(dtype=float)
# node.place(field_1) # moving this line to the end causes problem

field_2 = ti.field(dtype=float, shape=(3,))
field_2.from_numpy(np.array([1, 2, 3]))

node.place(field_1)

field_1 and field_2 are supposed to be independent of each other. But if I call node.place(field_1) after field_2.from_numpy(), it raises RuntimeError: [snode_tree.cpp:taichi::lang::SNodeTree::check_tree_validity@26] dense node must have at least one child.

Log/Screenshots

(taichi) PS D:\codes\TaichiTest> & C:\Programs\miniforge3\envs\taichi\python.exe d:/codes/TaichiTest/tests/test.py
[Taichi] version 1.7.4, llvm 15.0.1, commit b4b956fd, win, python 3.13.12
[Taichi] Starting on arch=cuda
[E 05/21/26 13:56:08.546 21824] [snode_tree.cpp:taichi::lang::SNodeTree::check_tree_validity@26] dense node must have at least one child.


Traceback (most recent call last):
  File "d:\codes\TaichiTest\tests\test.py", line 10, in <module>
    field_2.from_numpy(np.array([1, 2, 3]))
    ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\util.py", line 351, in wrapped
    return func(*args, **kwargs)
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\field.py", line 357, in from_numpy
    self._from_external_arr(arr)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\util.py", line 351, in wrapped
    return func(*args, **kwargs)
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\field.py", line 347, in _from_external_arr
    ext_arr_to_tensor(arr, self)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\kernel_impl.py", line 1113, in wrapped
    return primal(*args, **kwargs)
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\kernel_impl.py", line 1043, in __call__
    key = self.ensure_compiled(*args)
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\kernel_impl.py", line 1011, in ensure_compiled
    self.materialize(key=key, args=args, arg_features=arg_features)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\kernel_impl.py", line 637, in materialize
    self.runtime.materialize()
    ~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\impl.py", line 471, in materialize
    self.materialize_root_fb(not self.materialized)
    ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\lang\impl.py", line 406, in materialize_root_fb
    root.finalize(raise_warning=not is_first_call)
    ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\_snode\fields_builder.py", line 170, in finalize
    return self._finalize(raise_warning, compile_only=False)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Programs\miniforge3\envs\taichi\Lib\site-packages\taichi\_snode\fields_builder.py", line 182, in _finalize
    return SNodeTree(_ti_core.finalize_snode_tree(_snode_registry, self.ptr, impl.get_runtime().prog, compile_only))
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: [snode_tree.cpp:taichi::lang::SNodeTree::check_tree_validity@26] dense node must have at least one child.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions