Open agoscinski opened 3 weeks ago
Indeed the AiiDA ORM data can not be pickled. You need to move the code into the graph builder.
@task.graph_builder(outputs = [{"name": "cat_task", "from": "cat_task.stdout"}])
def cat_wg():
# load the code here
cat_code = orm.InstalledCode(
computer=orm.load_computer('localhost'),
filepath_executable='cat',
).store()
# Create a WorkGraph
wg = WorkGraph()
wg.add_task("ShellJob", command=cat_code, name="cat_task")
# don't forget to return the `wg`
return wg
The above code will work because the cat_code
is only loaded when the daemon runs the graph_builder task. Then the cat_code
is used as the input of the WorkGraph, which will be serialized to a json format before submitting the WorkGraph to the engine.
We should point out this in the document explictiy.
Edit: or pass the code as an argument of the graph_builder:
# load the code here
cat_code = orm.InstalledCode(
computer=orm.load_computer('localhost'),
filepath_executable='cat',
).store()
@task.graph_builder(outputs = [{"name": "cat_task", "from": "cat_task.stdout"}])
def cat_wg(code):
# Create a WorkGraph
wg = WorkGraph()
wg.add_task("ShellJob", command=code, name="cat_task")
# don't forget to return the `wg`
return wg
returns
while using
works fine