According to @maajor and @Eydcao , the current implementation requires a materialized MPM_sovler_shell before the importing into the python SOP. The advantage is that no need to redo ti.init() which is unnecessarily time-consuming.
Nonetheless, a materialized shell means many parameters has been determined (such as dx), this limits the flexibility brought by Houdini (i.e. the size of the whole scene always have to be normalized).
A temporal solution proposed by @maajor is directly quoted here
create a class containing all these parameters (with a proper initial value).
# ti_parm.py
import taichi as ti
class TIContext():
def init(self):
self.device = ti.cpu
self.last_device = ti.cpu
context = TIContext()
2. use this global parameter class to init `MPM_solver_shell`
import taichi as ti
import numpy as np
import ti_parm as tp
from taichi_elements.engine.mpm_solver import MPMSolver
if use_gpu:
tp.context.device = ti.cuda
else:
tp.context.device = ti.cpu
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device:
importlib.reload(mpm)
tp.context.last_device = tp.context.device
blablabla
3. finally in the python SOP where 'MPM_solver_shell', by comparing if the current parameter class is the same as an old parameter class, if different, forcefully re-import
import importlib
if use_gpu:
tp.context.device = ti.cuda
else:
tp.context.device = ti.cpu
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device:
importlib.reload(mpm)
tp.context.last_device = tp.context.device
According to @maajor and @Eydcao , the current implementation requires a materialized
MPM_sovler_shell
before the importing into the python SOP. The advantage is that no need to redo ti.init() which is unnecessarily time-consuming.Nonetheless, a materialized shell means many parameters has been determined (such as dx), this limits the flexibility brought by Houdini (i.e. the size of the whole scene always have to be normalized).
A temporal solution proposed by @maajor is directly quoted here
class TIContext(): def init(self): self.device = ti.cpu self.last_device = ti.cpu
context = TIContext()
import taichi as ti import numpy as np import ti_parm as tp from taichi_elements.engine.mpm_solver import MPMSolver
ti.reset() ti.init(tp.context.device, device_memory_GB=4.0)import importlib
if use_gpu: tp.context.device = ti.cuda else: tp.context.device = ti.cpu
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device: importlib.reload(mpm) tp.context.last_device = tp.context.device
blablabla
import importlib
if use_gpu: tp.context.device = ti.cuda else: tp.context.device = ti.cpu
if int(hou.frame()) == 0 and tp.context.last_device != tp.context.device: importlib.reload(mpm) tp.context.last_device = tp.context.device