我正在尝试使用多处理来加速代码的性能以及使用numba jitclass。 jitted函数中包含jitclass实例,此函数是多处理池的目标。 当我运行代码时,我收到了以下错误消息:
cPickle.PicklingError: Can't pickle <class 'numba.jitclass.boxing.MyClass'>: attribute lookup numba.jitclass.boxing.MyClass failed
我试图在python3中运行代码,它也有同样的问题:
_pickle.PicklingError: Can't pickle <class 'numba.jitclass.boxing.MyClass'>: attribute lookup numba.jitclass.boxing.MyClass failed
我甚至尝试过“pathos.multiprocessing”或“multiprocessing_on_dill”模块,而不是原来的“多处理”模块,它们都没有工作。 我该如何处理这个问题?提前谢谢。
以下是我的测试代码。
import numba as nb
from scipy.integrate import odeint
import multiprocessing as mp
@nb.jit(nopython=True)
def odeSystem(x, t, a):
v = a.func(x, t)
return 1-x+v
@nb.jitclass([])
class B(object):
def __init__(self):
pass
spec = [("b", B.class_type.instance_type),("c", nb.f8)]
@nb.jitclass(spec)
class A(object):
def __init__(self, b, c):
self.b = b
self.c = c
def func(self, x, t):
return 0
def odeSolve(x, t, a):
sol = odeint(odeSystem, x, t, args=(a,))
return sol
if __name__ == "__main__":
a = A(B(), 3)
from functools import partial
initialx = range(10)
ode = partial(odeSolve, t=range(0, 10), a=a)
nProcess = 1
pool = mp.Pool(nProcess)
sol = pool.map(ode, initialx)
print sol
如果我运行这个,我收到错误消息:
cPickle.PicklingError: Can't pickle <class 'numba.jitclass.boxing.A'>: attribute lookup numba.jitclass.boxing.A failed