Undocumented AssertionError

Hi! I’m trying to implement a simple simulation of a ball moving in a potential field, described by L2 distance between balls position and some target coordinate but I keep getting some weird assertion error (please find the stack trace below). I guess something wrong is happening in the AST parsing, probably because I have not placed some variables wrt sim_steps, but I can’t figure out the exact reason or proper placement procedure

UPD: changing range(0, 20, sim_steps) to range(0, sim_steps) seems to solve the issue, but it is not clear how can I have float timestamps. I’ve tried to use times = ti.Vector(sim_steps, dt=ti.f32); times.from_numpy(np.linspace(0, 20, sim_steps)) and draw timestamps like times[t], but it fails with assert len(ndarray.shape) == self.loop_range().dim() + 2. It seems that I’m missing something crucial in my program, so I would really appreciate any advice on how to work properly with timestamps in Taichi

Code I’m trying to run

Simpler example

Error message (the node.iter.args is 3, according to the debugger)

[Taichi] mode=release
[Taichi] version 0.6.2, supported archs: [cpu, cuda, opengl], commit 66c0b43d, python 3.8.2
Traceback (most recent call last):
  File "/home/gleb/code/ball_in_field.py", line 153, in <module>
    run_simulation(x, v)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/kernel.py", line 484, in wrapped
    primal(*args, **kwargs)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/kernel.py", line 414, in __call__
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/kernel.py", line 261, in materialize
    visitor.visit(tree)
  File "/opt/conda/envs/taichi/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 563, in visit_Module
    self.generic_visit(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 74, in generic_visit
    value = self.visit(value)
  File "/opt/conda/envs/taichi/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 644, in visit_FunctionDef
    self.generic_visit(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 74, in generic_visit
    value = self.visit(value)
  File "/opt/conda/envs/taichi/lib/python3.8/ast.py", line 360, in visit
    return visitor(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 495, in visit_For
    return self.visit_range_for(node)
  File "/opt/conda/envs/taichi/lib/python3.8/site-packages/taichi/lang/transformer.py", line 340, in visit_range_for
    assert len(node.iter.args) in [1, 2]
AssertionError

Process finished with exit code 1

Debugger info at https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/transformer.py#L341

node = {For} <_ast.For object at 0x7f0330458880>
 body = {list: 6} [<_ast.Assign object at 0x7f0330477430>, <_ast.If object at 0x7f03304779d0>, <_ast.Expr object at 0x7f0330477af0>, <_ast.Delete object at 0x7f03304772e0>, <_ast.Delete object at 0x7f0330477b80>, <_ast.Delete object at 0x7f0330477c40>]
 col_offset = {int} 4
 end_col_offset = {int} 15
 end_lineno = {int} 7
 iter = {Call} <_ast.Call object at 0x7f0330458940>
  args = {list: 3} [<_ast.Constant object at 0x7f03304586a0>, <_ast.Constant object at 0x7f03304589a0>, <_ast.Name object at 0x7f0330458a30>]
   0 = {Constant} <_ast.Constant object at 0x7f03304586a0>
    col_offset = {int} 20
    end_col_offset = {int} 21
    end_lineno = {int} 4
    kind = {NoneType} None
    lineno = {int} 4
    n = {int} 0
    s = {int} 0
    value = {int} 0
   1 = {Constant} <_ast.Constant object at 0x7f03304589a0>
    col_offset = {int} 23
    end_col_offset = {int} 25
    end_lineno = {int} 4
    kind = {NoneType} None
    lineno = {int} 4
    n = {int} 20
    s = {int} 20
    value = {int} 20
   2 = {Name} <_ast.Name object at 0x7f0330458a30>
    col_offset = {int} 27
    ctx = {Load} <_ast.Load object at 0x7f03b082de80>
    end_col_offset = {int} 36
    end_lineno = {int} 4
    id = {str} 'sim_steps'
    lineno = {int} 4
   __len__ = {int} 3
  col_offset = {int} 14
  end_col_offset = {int} 37
  end_lineno = {int} 4
  func = {Name} <_ast.Name object at 0x7f0330458970>
  keywords = {list: 0} []
  lineno = {int} 4
 lineno = {int} 4
 orelse = {list: 0} []
 target = {Name} <_ast.Name object at 0x7f03304588e0>
 type_comment = {NoneType} None

Would be grateful for any help

Sorry for the confusing message, it’s because we don’t support step argument for range now: range(0, 20, sim_steps). Please make a walk around like i * 20 :wink:

1 个赞