taichi-dev / taichi

Productive, portable, and performant GPU programming in Python.
https://taichi-lang.org
Apache License 2.0
25.52k stars 2.29k forks source link

vfx missing in 2d examples #12

Closed MidoriYakumo closed 7 years ago

MidoriYakumo commented 7 years ago
/taichi/python/examples/2d   master ●  for fn in *.py; do echo $fn;python3 $fn;done
color_schemes.py
composer.py
fluid_simulator.py
Traceback (most recent call last):
  File "fluid_simulator.py", line 1, in <module>
    from .levelset import LevelSet2D
SystemError: Parent module '' not loaded, cannot perform relative import
__init__.py
levelset.py
mcmc.py
16 @9.9999%
^CTraceback (most recent call last):
  File "mcmc.py", line 150, in <module>
    mh()
  File "mcmc.py", line 27, in mh
    acceptance = min(eval(y) / eval(x), 1)
KeyboardInterrupt
mpm_simulator.py
Traceback (most recent call last):
  File "mpm_simulator.py", line 3, in <module>
    from .levelset import LevelSet2D
SystemError: Parent module '' not loaded, cannot perform relative import
polygons.py
run_fluid_fancy.py
Traceback (most recent call last):
  File "run_fluid_fancy.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_fluid.py
Traceback (most recent call last):
  File "run_fluid.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_levelset.py
Traceback (most recent call last):
  File "run_levelset.py", line 1, in <module>
    import pyglet
ImportError: No module named 'pyglet'
run_mpm_balance.py
Traceback (most recent call last):
  File "run_mpm_balance.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_elastic.py
Traceback (most recent call last):
  File "run_mpm_elastic.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand_friction_angle.py
Traceback (most recent call last):
  File "run_mpm_sand_friction_angle.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand_hourglass.py
Traceback (most recent call last):
  File "run_mpm_sand_hourglass.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_sand.py
Traceback (most recent call last):
  File "run_mpm_sand.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow.py
Traceback (most recent call last):
  File "run_mpm_snow.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow_smash.py
Traceback (most recent call last):
  File "run_mpm_snow_smash.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_snow_sticky.py
Traceback (most recent call last):
  File "run_mpm_snow_sticky.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_title.py
Traceback (most recent call last):
  File "run_mpm_title.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_tree.py
Traceback (most recent call last):
  File "run_mpm_tree.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_mpm_words.py
Traceback (most recent call last):
  File "run_mpm_words.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_smoke_ball.py
Traceback (most recent call last):
  File "run_smoke_ball.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
run_smoke.py
Traceback (most recent call last):
  File "run_smoke.py", line 1, in <module>
    from taichi.vfx import *
ImportError: No module named 'taichi.vfx'
simulation_window.py
Traceback (most recent call last):
  File "simulation_window.py", line 4, in <module>
    import pyglet
ImportError: No module named 'pyglet'
simulator.py
yuanming-hu commented 7 years ago

Thanks. I wrote the 2d scripts a long time ago and now they are completely in a mess. I'll fix them as soon as possible.

iamyoukou commented 7 years ago

@MidoriYakumo You can modify some files to run those examples.
For example, if you want to run run_mpm_snow.py

  1. in taichi/python/misc/2d/levelset.py
    add import taichi_core as tc

  2. in taichi/python/misc/2d/run_mpm_snow.py

    #from taichi.vfx import *
    from mpm_simulator import *
    from simulation_window import SimulationWindow
    from color_schemes import *
  3. in taichi/python/misc/2d/simulatio_window.py

    #from taichi.misc.util import get_os_name
    from taichi.misc.util import *

    and change VIDEO_OUTPUT_ROOT in get_os_name function to the path you like.

  4. in taichi/python/taichi/misc/util.py @IteratorAdvance On MacOSX, I

    import taichi_core as tc # on my Arch Linux, this causes segmentation fault (core dumped)
    import pyglet

    so, on Arch Linux, I

    import pyglet

    and

    def make_polygon(points, scale):
    import taichi_core as tc # add here
    polygon = tc.Vector2List()
    def const_or_evaluate(f, u, v):
    import taichi_core as tc # add here
    if type(f) in [float, int, tuple, tc.Vector2, tc.Vector3]:
  5. in ~/.bashrc add $TAICHI_ROOT_DIR/taichi/build/ (for taichi_core.so)
    and $TAICHI_ROOT_DIR/taichi/python/misc/2d/
    to your PYTHONPATH environment variable

I tried this method on MacOSX (10.11.6) and Arch Linux (4.8.13) and it works well. This works for run_mpm_snow_smash.py and run_mpm_snow_sticky.py, too.

yuanming-hu commented 7 years ago

Hi @iamyoukou, It's like magic for me that you get these scripts working...I haven't touched them for more than one month, during which period Taichi was under drastic refactoring. Thank you very much.

I've fixed the 2D MPM examples (in a dirty way) and will fix fluid ones later, since they need dependency on ANN, which I would like to remove.

You are welcome to contribute on issues with tag 'contributions welcome', and I will probably deal with the rest myself - just because I'm more familiar with my own legacy (dirty) code and you don't have to waste your precious time on these historical problems.

iamyoukou commented 7 years ago

Gotcha : )

yuanming-hu commented 7 years ago

I've fixed all the examples. Thanks.