-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
[pyc] use pyc file instead py file is not working #2217
Comments
Maybe this issue is related, I do not know. I just begin to use taichi, maybe there are some options to find out. |
Hi, Wang:
Taichi doesn't support to be run from .pyc at this moment due to the fact that it needs to get the source of functions to work properly. In fact, Taichi uses the `inspect` module to extract the source of function @ti.kernel is decorated, then modify the source using `ast` module in order to translate Python syntax into Taichi API calls, then re-compile the modifed source into binary code (pyc) and run it.
NOTE: It might be possible to support Taichi in .pyc, that is to store the 'modifed' code object, but not sure it worth the complicity to do this change..
无法顺畅的大口呼吸,是活着的最好证明
…---Original---
From: "Walker ***@***.***>
Date: Wed, Mar 17, 2021 18:43 PM
To: ***@***.***>;
Cc: ***@***.***>;
Subject: Re: [taichi-dev/taichi] [pyc] use pyc file instead py file is not working (#2217)
Maybe this issue is related, I do not know.
#1186
I just begin to use taichi, maybe there are some options to find out.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Thank you for the answer! Can you show me a minimal process to do that? I want to evaluate the complexity. |
The |
Thank for your passion! You may need to modify this file: https://github.com/taichi-dev/taichi/blob/python/taichi/lang/kernel.py
Then save / restore the code object it generated to / from a .pyc file.
See also https://taichi.rtfd.io/en/stable/dev_install.html for setting up a develop environment for Taichi.
无法顺畅的大口呼吸,是活着的最好证明
…---Original---
From: "Walker ***@***.***>
Date: Wed, Mar 17, 2021 19:15 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [taichi-dev/taichi] [pyc] use pyc file instead py file is not working (#2217)
Thank you for the answer!
Can you show me a minimal process to do that? I want to evaluate the complexity.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Hi, The entire python AST transformation is done in https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/transformer.py. Specifically for your questions:
As @archibate has pointed out, things that are inside @ti.kernel is completely cut off from Python, and the complexity to make it work in |
> ti.print ti.range
Exactly! That's how Taichi works. Please try appending this after `import taichi`:
```py
ti.init(print_preprocessed=True)
```
and running it (as .py) will print the transformed source code (including the `ti.ti_print` you've pointed out).
Now if we could store the transformed code into .pyc, Taichi would likely to work without requiring inspect the source at runtime!
无法顺畅的大口呼吸,是活着的最好证明
…---Original---
From: "Walker ***@***.***>
Date: Wed, Mar 17, 2021 19:18 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [taichi-dev/taichi] [pyc] use pyc file instead py file is not working (#2217)
In fact, Taichi uses the inspect module to extract the source of function @ti.kernel is decorated, then modify the source using ast module in order to translate Python syntax into Taichi API calls, then re-compile the modifed source into binary code (pyc) and run it.
The print and range inside the taichi scope make me confusing at begin.
If it is possible to alias them to ti.print and ti.range (What should I do).
Maybe I will find more such needing in the future.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
I think the transform has lost the argument? |
Hi, this is actually intentional. The python source code inside taichi/python/taichi/lang/kernel.py Lines 494 to 500 in 588fc8f
|
Describe the bug
Thank you for creating taichi language. I want to know how to use pyc files in computation.
To Reproduce
Consider 3 files below.
Use
python3 compile.py
and rename files in__pycache__
tohello.pyc
andcore.pyc
then runpython3 hello.pyc
, this will work if using module numpy but not module taichi.Log/Screenshots
Please post the full log of the program (instead of just a few lines around the error message, unless the log is > 1000 lines). This will help us diagnose what's happening. For example:
Additional comments
If possible, please also consider attaching the output of command
ti diagnose
. This produces the detailed environment information and hopefully helps us diagnose faster.The text was updated successfully, but these errors were encountered: