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

[error] Fix wrong error message when using vector as if condition #1417

Conversation

archibate
Copy link
Collaborator

@archibate archibate commented Jul 5, 2020

Related issue = #

[Click here for the format server]


It seems that when pybind11 got an type mismatch, it will try to invoke repr to show the object...
So we have to make it happy with a dummy string in Matrix.__repr__ instead of cannot be called from Python-scope.

import taichi as ti
ti.init()

@ti.kernel
def func():
    x = ti.Vector([2, 3])
    if x:
        pass

func()

Before:

Traceback (most recent call last):
  File "w.py", line 12, in <module>
    func()
  File "/root/taichi/python/taichi/lang/kernel.py", line 553, in wrapped
    return primal(*args, **kwargs)
  File "/root/taichi/python/taichi/lang/kernel.py", line 483, in __call__
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/root/taichi/python/taichi/lang/kernel.py", line 363, in materialize
    taichi_kernel = taichi_kernel.define(taichi_ast_generator)
  File "/root/taichi/python/taichi/lang/util.py", line 210, in wrapped
    assert in_python_scope(), \
AssertionError: __repr__ cannot be called in Taichi-scope

After:

Traceback (most recent call last):
  File "w.py", line 12, in <module>
    func()
  File "/root/taichi/python/taichi/lang/kernel.py", line 553, in wrapped
    return primal(*args, **kwargs)
  File "/root/taichi/python/taichi/lang/kernel.py", line 483, in __call__
    self.materialize(key=key, args=args, arg_features=arg_features)
  File "/root/taichi/python/taichi/lang/kernel.py", line 363, in materialize
    taichi_kernel = taichi_kernel.define(taichi_ast_generator)
  File "/root/taichi/python/taichi/lang/kernel.py", line 360, in taichi_ast_generator
    compiled()
  File "w.py", line 8, in func
    if x:
  File "/root/taichi/python/taichi/lang/expr.py", line 29, in __init__
    self.ptr = make_constant_expr(arg).ptr
  File "/root/taichi/python/taichi/lang/util.py", line 200, in wrapped
    return func(*args, **kwargs)
  File "/root/taichi/python/taichi/lang/impl.py", line 224, in make_constant_expr
    return Expr(taichi_lang_core.make_const_expr_f32(val))
TypeError: make_const_expr_f32(): incompatible function arguments. The following argument types are supported:
    1. (arg0: float) -> taichi_core.Expr

Invoked with: <Taichi 2x1 Matrix>

@pybind Hi, I know that printing Invoked with: xxx is nice to debug, but do you know that it's also possible for the repr of xxx to fail?
Can we catch it and say: During processing the above exception, another exception occurred instead of a corrupt stack backtrace?

@archibate archibate requested review from xumingkuan, yuanming-hu, rexwangcc and taichi-gardener and removed request for xumingkuan and yuanming-hu July 5, 2020 09:29
@codecov

This comment has been minimized.

Copy link
Contributor

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

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

LGTM!

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.

LGTM!

@archibate archibate merged commit fabcc56 into taichi-dev:master Jul 6, 2020
@FantasyVR FantasyVR mentioned this pull request Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants