From c04d416e386ba9aaafc33e42a419ddc51502aefa Mon Sep 17 00:00:00 2001 From: superstar54 Date: Sun, 22 Sep 2024 20:42:02 +0200 Subject: [PATCH 1/2] Add the executor to the globals so that it can be used in the task --- aiida_workgraph/engine/workgraph.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/aiida_workgraph/engine/workgraph.py b/aiida_workgraph/engine/workgraph.py index bebe7086..f0975011 100644 --- a/aiida_workgraph/engine/workgraph.py +++ b/aiida_workgraph/engine/workgraph.py @@ -1032,6 +1032,13 @@ def run_tasks(self, names: t.List[str], continue_workgraph: bool = True) -> None self.report(f"Run task: {name}, type: {task['metadata']['node_type']}") executor, _ = get_executor(task["executor"]) + # Add the executor to the globals so that it can be used in the task + # in the case of recursive workgraph + # We also need to rebuild the Task calss and attach it to the executor + if task["metadata"]["node_type"].upper() == "GRAPH_BUILDER": + task_class = Task.from_dict(self.ctx._tasks[name]) + executor.node = executor.task = task_class.__class__ + executor.__globals__[executor.__name__] = executor # print("executor: ", executor) args, kwargs, var_args, var_kwargs, args_dict = self.get_inputs(name) for i, key in enumerate(self.ctx._tasks[name]["args"]): From f8f6fa3fbb94c1713c87c802d0dd636f048a65e0 Mon Sep 17 00:00:00 2001 From: superstar54 Date: Sun, 22 Sep 2024 20:43:17 +0200 Subject: [PATCH 2/2] Use group_inputs and group_outputs when creating Task --- aiida_workgraph/decorator.py | 11 ++++++++--- pyproject.toml | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/aiida_workgraph/decorator.py b/aiida_workgraph/decorator.py index 52de805b..25d98bdb 100644 --- a/aiida_workgraph/decorator.py +++ b/aiida_workgraph/decorator.py @@ -455,9 +455,9 @@ def build_task_from_workgraph(wg: any) -> Task: "type": tdata["metadata"]["task_type"], "is_pickle": False, } + tdata["metadata"]["group_outputs"] = group_outputs tdata["executor"] = executor task = create_task(tdata) - task.group_outputs = group_outputs return task @@ -501,6 +501,8 @@ def generate_tdata( properties: List[Tuple[str, str]], catalog: str, task_type: str, + group_inputs: List[Tuple[str, str]] = None, + group_outputs: List[Tuple[str, str]] = None, additional_data: Optional[Dict[str, Any]] = None, ) -> Dict[str, Any]: """Generate task data for creating a task.""" @@ -524,6 +526,8 @@ def generate_tdata( "task_type": task_type, "catalog": catalog, "node_class": {"module": "aiida_workgraph.task", "name": "Task"}, + "group_inputs": group_inputs or [], + "group_outputs": group_outputs or [], }, "properties": properties, "inputs": _inputs, @@ -634,10 +638,11 @@ def decorator(func): properties or [], catalog, task_type, + group_inputs=inputs, + group_outputs=outputs, ) + task = create_task(tdata) - task.group_inputs = inputs - task.group_outputs = outputs func.task = func.node = task return func diff --git a/pyproject.toml b/pyproject.toml index 584970f2..3ec52a41 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ dependencies = [ "numpy~=1.21", "scipy", "ase", - "node-graph>=0.1.0", + "node-graph==0.1.1", "aiida-core>=2.3", "cloudpickle", "aiida-shell~=0.8",