You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I would like to do feed a class that inherits from luigi.Task with a luigi.ListParameters where the items are instances of classes that inherit from luigi.Task as well, like in the following small reproducer:
import luigi
class SubTask(luigi.Task):
param = luigi.Parameter()
def run(self):
with self.output().open('w') as f:
f.write(f"SubTask {self.param}\n")
class MainTask(luigi.Task):
subtasks = luigi.ListParameter()
def requires(self):
return self.subtasks
def run(self):
with self.output().open('w') as f:
f.write("MainTask\n")
if __name__ == "__main__":
subA = SubTask(param='A')
subB = SubTask(param='B')
luigi.build([MainTask(subtasks=[subA, subB])], local_scheduler=True)
However, this seems to raise the following error:
...
TypeError: Object of type SubTask is not JSON serializable
The only way I can think of to make this work consists in instantiating subA and subB before defining MainTask, create a dictionary where the instances are values and then simply pass a list of strings when instantiating MainTask, like e.g.:
import luigi
class SubTask(luigi.Task):
param = luigi.Parameter()
def run(self):
with self.output().open('w') as f:
f.write(f"SubTask {self.param}\n")
subA = SubTask(param='A')
subB = SubTask(param='B')
dct = {
'A': subA,
'B': subB
}
class MainTask(luigi.Task):
subtasks = luigi.ListParameter()
def requires(self):
return [dct[i] for i in self.subtasks]
def run(self):
with self.output().open('w') as f:
f.write("MainTask\n")
luigi.build([MainTask(subtasks=['A', 'B'])], local_scheduler=True)
So I have two questions:
is there a nicest way to do this which does not require to create instances of SubTask before defining MainTask?
would it be a nice addition to luigi the possibility to run the first snippet without incurring in the above mention error?
Thank you,
Massimiliano
The text was updated successfully, but these errors were encountered:
Hi, I would like to do feed a class that inherits from
luigi.Task
with aluigi.ListParameters
where the items are instances of classes that inherit fromluigi.Task
as well, like in the following small reproducer:However, this seems to raise the following error:
The only way I can think of to make this work consists in instantiating
subA
andsubB
before definingMainTask
, create a dictionary where the instances are values and then simply pass a list of strings when instantiatingMainTask
, like e.g.:So I have two questions:
SubTask
before definingMainTask
?luigi
the possibility to run the first snippet without incurring in the above mention error?Thank you,
Massimiliano
The text was updated successfully, but these errors were encountered: