Skip to content

Draft: "method" task with multiple outputs#99

Open
poautran wants to merge 7 commits into
mainfrom
method-output
Open

Draft: "method" task with multiple outputs#99
poautran wants to merge 7 commits into
mainfrom
method-output

Conversation

@poautran

Copy link
Copy Markdown
Member

In GitLab by @tvincent on Dec 16, 2024, 15:31 GMT+1:

This MR proposes a way to define a Task with multiple outputs from a Python function.

For me the goal is two-fold:

  • Hopefully have a simpler way to define a Task based on Python syntax.
  • Write Tasks that can also be used directly outside ewoks and called directly from Python as well.

I can imagine different ways to do this, this MR proposes one approach: Use the function return type annotation to define the task output fields.

As it is, by default there is a single "return_value" output and the use of return type is enabled through a decorator.
I'm not sure about the best default and the way to choose to "unpack" outputs or keep a single one, but I'd expect allowing both is needed.

Related to #46

Migrated from GitLab: https://gitlab.esrf.fr/workflow/ewoks/ewokscore/-/merge_requests/262

def serialize(self) -> Dict[str, str]:
if self.uri is None:
return None
return self.uri.serialize()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @tvincent on Dec 16, 2024, 15:32 GMT+1:

Tests broke here, I didn't fully understand why...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 16, 2024, 17:38 GMT+1:

This is caused by hacking the inputs to support the same argument to be positional and named.

If we want to support this, we need to support it on a fundamental level, this cannot be patched.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @tvincent on Dec 16, 2024, 17:50 GMT+1:

OK, then I propose to support named only (and eventually positional only) = A single way to pass arguments.
This would also avoids the required/optional input names workaround I had to do, but would change the current behavior.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 17, 2024, 09:59 GMT+1:

We can support it, it just needs to be native support where a variable can have two id's (a string and an integer). But it is outside the scope of this MR. So named-only would be best.

class MethodExecutorTask(Task):
_METHOD_REQUIRED_INPUTS = tuple()
_METHOD_OPTIONAL_INPUTS = tuple()
_METHOD_UNPACK_OUTPUTS = False

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 16, 2024, 16:40 GMT+1:

The base class already has

    _INPUT_NAMES = set()
    _OPTIONAL_INPUT_NAMES = set()
    _OUTPUT_NAMES = set()
    _N_REQUIRED_POSITIONAL_INPUTS = 0

Why no use those?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 16, 2024, 16:42 GMT+1:

Ok it is because of required inputs are optional to support passing them as positional inputs

Comment thread src/ewokscore/methodtask.py Outdated


def task_outputs(function: FunctionType) -> FunctionType:
"""Function decorator so ewoks extract task outputs from return type elements/attributes"""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 16, 2024, 16:44 GMT+1:

    """Function decorator so ewoks extracts task outputs from return type elements/attributes"""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @tvincent on Dec 16, 2024, 16:51 GMT+1:

changed this line in version 2 of the diff

@poautran

Copy link
Copy Markdown
Member Author

In GitLab by @tvincent on Dec 16, 2024, 16:51 GMT+1:

added 1 commit

Compare with previous version (link unavailable after force-push)

Task, input_names=[METHOD_ARGUMENT], output_names=["return_value"]
):
METHOD_ARGUMENT = METHOD_ARGUMENT
def __init_subclass__(cls, task_identifier: str):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In GitLab by @woutdenolf on Dec 16, 2024, 16:53 GMT+1:

pass **kwargs to super().__init_subclass__

@poautran poautran force-pushed the main branch 2 times, most recently from 8dcd50a to b58fb90 Compare February 13, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants