Skip to content

Commit

Permalink
validate task inputs and outputs when creating task
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 2, 2024
1 parent fdc9972 commit 4e4e5e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 2 additions & 6 deletions aiida_workgraph/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def create_task(tdata):

tdata["type_mapping"] = type_mapping
tdata["metadata"]["node_type"] = tdata["metadata"].pop("task_type")
tdata["inputs"] = validate_task_inout(tdata["inputs"], "inputs")
tdata["outputs"] = validate_task_inout(tdata["outputs"], "outputs")
return create_node(tdata)


Expand Down Expand Up @@ -130,12 +132,6 @@ def build_task(
"""Build task from executor."""
from aiida_workgraph.workgraph import WorkGraph

if inputs:
inputs = validate_task_inout(inputs, "inputs")

if outputs:
outputs = validate_task_inout(outputs, "outputs")

if isinstance(executor, WorkGraph):
return build_task_from_workgraph(executor)
elif isinstance(executor, str):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
from typing import Callable


def test_custom_outputs():
"""Test custom outputs."""

@task(outputs=["sum", {"name": "product", "identifier": "workgraph.any"}])
def add_multiply(x, y):
return {"sum": x + y, "product": x * y}

n = add_multiply.task()
assert "sum" in n.outputs.keys()
assert "product" in n.outputs.keys()


@pytest.fixture(params=["decorator_factory", "decorator"])
def task_calcfunction(request):
if request.param == "decorator_factory":
Expand Down

0 comments on commit 4e4e5e9

Please sign in to comment.