如何将多个参数传递给 Luigi 子任务?

guz*_*man 4 python luigi

我有一个路易吉任务,它是requires一个子任务。子任务取决于父任务(即正在执行操作的任务require)传递的参数。我知道您可以通过设置来指定子任务可以使用的参数...

def requires(self):
    return subTask(some_parameter)
Run Code Online (Sandbox Code Playgroud)

...然后在子任务上,通过设置接收参数...

x = luigi.Parameter()
Run Code Online (Sandbox Code Playgroud)

不过,这似乎只允许您传递一个参数。发送任意数量的参数(无论我想要什么类型)的最佳方法是什么?我真的想要这样的东西:

class parentTask(luigi.Task):

    def requires(self):
        return subTask({'file_postfix': 'foo',
                        'file_content': 'bar'
        })

    def run(self):
        return


class subTask(luigi.Task):
    params = luigi.DictParameter()

    def output(self):
        return luigi.LocalTarget("file_{}.csv".format(self.params['file_postfix']))

    def run(self):
        with self.output().open('w') as f:
            f.write(self.params['file_content'])
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我尝试使用luigi.DictParameter而不是直的,但当我运行上面的命令时,luigi.Parameter我是从路易吉内心深处的某个地方得到的。TypeError: unhashable type: 'dict'

运行Python 2.7.11、Luigi 2.1.1

Mat*_*ght 5

发送任意数量的参数(无论我想要什么类型)的最佳方法是什么?

最好的方法是使用命名参数,例如,

#in requires
return MySampleSubTask(x=local_x, y=local_y)

class MySampleSubTask(luigi.Task):
    x = luigi.Parameter()
    y = luigi.Parameter()
Run Code Online (Sandbox Code Playgroud)