如何在pp(并行python)包中修复此错误消息

时间:2019-05-01 21:30:47

标签: python-3.x parallel-processing

我是新来使用并行python的人,但我惊讶的是关于它的文档很少。我正在尝试并行化自己实现的随机森林。由于我的代码在不使用pp的情况下运行良好,因此我认为使用pp的方法不正确。

我正在尝试总共创建500棵树,以便每个核心都可以构建100棵树。因此,在“ job_submission”的for循环之外,我创建了ntree参数为100的随机森林对象。但是,我一直遇到此错误。

    import pp

    class randomforest():
        '''
        SOME METHODS
        '''
        def _grow(self, D):
            '''
            Build a tree
            '''
            return tree

    if __name__ == '__main__':
        '''
        Initialize X_train, Y_train, D
        '''
        job_server = pp.Server(5)
        rf = RandomForest(X_train, Y_train, ntree=100)

        result = []
        forest = []
        n, _ = np.shape(rf.x)
        D = [rf.x[i] + [rf.y[i]] for i in range(n)]
        for i in range(5):
            f = job_server.submit(rf._grow, (D,), ('numpy',))
            result.append(f)
        for job in result:
            forest.append(job())
        rf.forest_ = forest

我回溯了这些文件,但我不明白为什么我在文件第1行中遇到了最后一个错误。

SyntaxError: invalid syntax
 A fatal error has occured during the function execution
Traceback (most recent call last):
  File "/anaconda3/envs/mvi/lib/python3.6/site-packages/ppworker.py", line 90, in run
    __fname, __fobjs = self.t.creceive(preprocess)
  File "/anaconda3/envs/mvi/lib/python3.6/site-packages/pptransport.py", line 124, in creceive
    self.rcache[hash1] = tuple(map(preprocess, (msg, )))[0]
  File "/anaconda3/envs/mvi/lib/python3.6/site-packages/ppworker.py", line 56, in preprocess
    fobjs = [compile(fsource, '<string>', 'exec') for fsource in fsources]
  File "/anaconda3/envs/mvi/lib/python3.6/site-packages/ppworker.py", line 56, in <listcomp>
    fobjs = [compile(fsource, '<string>', 'exec') for fsource in fsources]
  File "<string>", line 1
    ow(self, dataset):

0 个答案:

没有答案