taichi: IDLE still doesn't work for me
Describe the bug I saw this post today https://github.com/taichi-dev/taichi/pull/1222 and I realized this is already in 0.6.14 release, and I decided to try it out, but it still doesn’t work for me. To Reproduce the codes are these:
import taichi as ti
ti.init()
a = 1
@ti.kernel
def test_kernel_print():
print(a)
test_kernel_print()
Log/Screenshots When I do it in IDLE concole, it still gives me this:
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
test_kernel_print()
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\site-packages\taichi\lang\kernel.py", line 559, in wrapped
return primal(*args, **kwargs)
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\site-packages\taichi\lang\kernel.py", line 488, in __call__
self.materialize(key=key, args=args, arg_features=arg_features)
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\site-packages\taichi\lang\kernel.py", line 300, in materialize
src = remove_indent(oinspect.getsource(self.func))
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\inspect.py", line 985, in getsource
lines, lnum = getsourcelines(object)
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\inspect.py", line 967, in getsourcelines
lines, lnum = findsource(object)
File "C:\Users\Eary\AppData\Local\Programs\Python\Python38\lib\inspect.py", line 798, in findsource
raise OSError('could not get source code')
OSError: could not get source code
When I try it in IDLE with a file, it kind of runs but it prints nothing.
[Taichi] mode=release
[Taichi] version 0.6.18, llvm 10.0.0, commit 35845482, python 3.8.1
[Taichi] Starting on arch=x64
>>>
After reading the manual’s “warning” section at https://taichi.readthedocs.io/en/stable/debugging.html?highlight=idle#run-time-print-in-kernels , I tried to change the ti.init() to ti.init(arch=ti.opengl)
but it doesn’t work.
[Taichi] mode=release
[Taichi] version 0.6.18, llvm 10.0.0, commit 35845482, python 3.8.1
[Taichi] Starting on arch=opengl
>>>
Another thing, it works in PyCharm with ti.init() ti.init(arch=ti.cuda) etc., it will print a 1 for me. But when using ti.init(arch=ti.opengl), PyCharm also prints nothing at all.
I try it in Blender’s scripting workspace as well. (I assume this is related based on @yuanming-hu 's reply at https://github.com/taichi-dev/taichi_elements/issues/54#issuecomment-645720321) It gives me the same error in both the console and the file:
[Taichi] mode=release
[Taichi] version 0.6.18, llvm 10.0.0, commit 35845482, python 3.7.7
[Taichi] Starting on arch=x64
Traceback (most recent call last):
File "\Text", line 13, in <module>
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\site-packages\taichi\lang\kernel.py", line 559, in wrapped
return primal(*args, **kwargs)
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\site-packages\taichi\lang\kernel.py", line 488, in __call__
self.materialize(key=key, args=args, arg_features=arg_features)
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\site-packages\taichi\lang\kernel.py", line 300, in materialize
src = remove_indent(oinspect.getsource(self.func))
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\inspect.py", line 973, in getsource
lines, lnum = getsourcelines(object)
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\inspect.py", line 955, in getsourcelines
lines, lnum = findsource(object)
File "C:\Users\Eary\Desktop\blender-2.90.0-taichi-branch\blender-2.90.0-4db63b648643-windows64\2.90\python\lib\inspect.py", line 778, in findsource
raise OSError('source code not available')
OSError: source code not available
Also I noticed Blender is still crashing when using ti.init(arch=opengl), so I guess that was the reason for https://github.com/taichi-dev/taichi_elements/issues/54 then?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 31
Great! For the 1 and 4, that’s because of IDLE limitation, we can’t get source code in interactive mode. However, using IPython and Jupyter have no such problem. In fact, I used to make a PR #1308 to perform a dirty hack into IDLE to make Taichi work with it (succeed!). But I finally closed it since I believe people should be able to install IPython to replace IDLE for development. WDYT? Dirty hack or request people to install IPython?
Fixed in
sourceinspect==0.0.3.Thank for reporting, I’ll try to fix this first.
Yes,
def func(): passworks And yes, Blender file mode also worksIt seems that if we use
def func(): pass(inlined) the issue will be gone? I know how to fix then. Also, does the Blender file mode (the window on the right) work on your end?Oh! Sorry about my typo! Please remove the extra
')at the end of line. Also, do not left indent before__import__, it will not be executed unless__name__ == '__main__'.So I need to manually copy the line to the .py file? That sounds a bit troublesome… But I will try.
Hi, despite it’s now merged into master, the next version 0.6.26 of taichi not released on PyPI yet. It will be likely released in Wed. Sorry 😃
Yes, please see https://github.com/taichi-dev/sourceinspect.git. The package
sourceinspectwill be automatically installed when installingtaichi, thanks topip’s dep resolving mechanism.In fact, it’s really simple, here’s the simplified workflow: I wrote
sourceinspect, providing exactly the same API asinspect(a Python builtin module). In Taichi, we performimport sourceinspect as inspect, now our source code inspection are redirected intosourceinspect. When no Blender detected,sourceinspectsimply redirect invocations back toinspect, nothing changes. When Blender is detected,sourceinspectwill begin to do its own mocks to inspect source code in Blender.Thanking blender devs 😕
Yes, the
ti idle_hackerwill save a backup of the old file, so no worry 😃 We may also have ati idle_hacker -rcommand for easy revert.A quick question here, will there be an option to revert back to the original IDLE in case some problems happen?
My thought is to use taichi in Blender’s scripting module, that’s all I want. It seems very troublesome to use IPython in Blender, so I would vote for dirty hack, if it does not have some serious drawbacks.
For the 2 and 3, could you try adding
ti.sync()at the end of program?Thank for reporting these bugs. IIUC this issue contains 5 issues:
printnot working in IDLE file modeprinton OpenGL not working in PyCharm