How to print debug messages?

Hello! I’m trying to re-implement my javascript 3d mpm code in Taichi. At the moment i don’t get the same results, and I’m trying to find the cause for the difference. However, I can’t find a way of printing debugging messages in the code. For example, print("p2g") inside a ti.kernel throws

TypeError: make_const_expr_f32(): incompatible function arguments. The following argument types are supported:
    1. (arg0: float) -> taichi_core.Expr

Invoked with: 'p2g'.

Is there a way of doing it?

thank you!

For now, taichi doesn’t support printing strings inside a kernel. Only numbers are allowed due to hardware limitations. (sadly)
Btw, you can print debug info by setting environment variables:
TI_LOG_LEVEL=debug python


thank you @archibate!
I found the print command reading the docs one more time :smiley: and also realised that it only works with numbers. So, for printing a vector I do several separate prints: print(x[0]); print(x[1]); etc., and for matrices print(m[0,0]), etc.
I managed to debug my code and even running on the CPU it’s impressively fast!

1 Like

Btw, we are trying to implement print for matrix/vector/string now, see!

1 Like

cool! i’ll check it out. Thank you : )

News: printing a matrix or string is now supported in v0.6.6!

1 Like

Thank you so much!! (I’m a very optimistic person: I took my first online course of Mandarin to try to understand your Taichi-con videos :star_struck:! If we meet one day, I should be able to introduce myself :stuck_out_tongue: )

1 Like

Sounds cool! Feel free to ask help from native speakers when you need. I’m looking forward to meet you too :wink: Btw, it’s heard that @yuanming would like to held the TaichiCon 1 in English, would you like to participate? I will be there as an audience of course :smile:

I would love to participate! I’ve been using a script based on @yuanming’s 88-lines code for MPM, first transformed to 3D, and now using Taichi, for simulating brain growth and folding. I’d love to have your input!



你是否在使用ti.init(ti.gpu)? 可否给出重现代码?

def kern():



import taichi as ti
ti.init(arch = ti.cpu)

def myprint():
    x = 233
    print(x)  #没有输出
    print(5)  #没有输出
    print("输出") #没有输出




了解!谢谢 :wink: