Skip to content

Add helpers to create task inputs and execute/submit one task#63

Open
poautran wants to merge 1 commit into
mainfrom
task-helper
Open

Add helpers to create task inputs and execute/submit one task#63
poautran wants to merge 1 commit into
mainfrom
task-helper

Conversation

@poautran

Copy link
Copy Markdown
Member

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

This PR proposes to add a few helpers to run workflow with a single task and to write list of task inputs.

I didn't put tests for submit_task since it would need a worker.

Assignees: tvincent

Reviewers: @woutdenolf

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

@poautran

Copy link
Copy Markdown
Member Author

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

requested review from @woutdenolf

@poautran

Copy link
Copy Markdown
Member Author

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

mentioned in merge request ewokscore!263

@poautran

Copy link
Copy Markdown
Member Author

Discussion in GitLab:

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

CI fails for an unrelated issue:

FAILED src/ewoks/tests/test_projects.py::test_import[ewoksorange] - DeprecationWarning: import 'orangecanvas.localization', not 'orangecanvas.utils.localization'

In GitLab by @woutdenolf on Dec 20, 2024, 11:43 GMT+1:

https://gitlab.esrf.fr/workflow/ewoks/ewoks/-/merge_requests/188

@poautran

Copy link
Copy Markdown
Member Author

In GitLab by @woutdenolf on Dec 20, 2024, 17:12 GMT+1:

approved this merge request

@poautran

Copy link
Copy Markdown
Member Author

In GitLab by @woutdenolf on Dec 21, 2024, 15:39 GMT+1:

unapproved this merge request

Comment thread src/ewoks/task_utils.py
inputs: Optional[Union[Mapping, List[Mapping]]] = None,
task_type: str = "class",
**options,
):

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 21, 2024, 15:42 GMT+1:

Suppose we want to run this function with ewoks

# mytasks.py

def sumfunc(a, b):
    return a+b

If the idea is to provide an API that is as close to calling a normal python function, how about this?

sumab = execute_task("mytasks.sumfunc", task_type="method")(a=10, b=20)

And if the default task_type is "method"

sumab = execute_task("mytasks.sumfunc")(a=10, b=20)

And since we can handle positional arguments as well

sumab = execute_task("mytasks.sumfunc")(10, 20)

which is as close as it gets to

sumab = sumfunc(10, 20)

essentially

sumfunc = execute_task("mytasks.sumfunc")

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 21, 2024, 15:49 GMT+1:

Same goes for submit_task.

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 Jan 6, 2025, 10:31 GMT+1:

Makes sense!

As it is, I made it similar to execute_graph and submit_graph API but it would be more pythonic this way like the first attempt for this (https://gitlab.esrf.fr/workflow/ewoks/ewokscore/-/merge_requests/263).

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 Jan 6, 2025, 14:21 GMT+1:

And if the default task_type is "method"

I used "class" type by default since for execute_task at least it is of limited interest to call method task.

Best IMO would be to see if a "auto" task_type is possible: It sound possible for class, method, graph, script and notebook types at least.

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 Jan 6, 2025, 14:26 GMT+1:

Using positional only args can also be considered:

def execute_task(task, task_type: str = "class", options: Optional[dict] = None, /, **kwargs):
    ...

sumab = execute_task("mytasks.sumfunc", "method", a=10, b=20)

sumab = execute_task("mytasks.sumtask", a=10, b=20)

though it's a bit cumbersome to pass extra options (here the task_type MUST also be provided)

Comment thread src/ewoks/task_utils.py
if task_identifier is not None:
task_selector["task_identifier"] = task_identifier

return [{**task_selector, "name": k, "value": v} for k, v in inputs.items()]

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 21, 2024, 15:49 GMT+1:

Since task_inputs is public, in which situation would you use it?

Note that ewoks is not installed in the bliss side. If you need it in blissoda then ewoksutils is the best option (dependency of ewoksjob[client] which is installed on the bliss side).

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 Jan 6, 2025, 10:31 GMT+1:

That would be useful in blissoda and scripts/GUI like in https://gitlab.esrf.fr/workflow/workflowhub/id31workflows.

I'll make a PR with it on ewoksutils.

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 Jan 6, 2025, 13:54 GMT+1:

PR in ewoksutils: https://gitlab.esrf.fr/workflow/ewoks/ewoksutils/-/merge_requests/32

@poautran

Copy link
Copy Markdown
Member Author

In GitLab by @tvincent on Jan 6, 2025, 13:54 GMT+1:

mentioned in merge request ewoksutils!32

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