aiidateam / aiida-workgraph

Efficiently design and manage flexible workflows with AiiDA, featuring an interactive GUI, checkpoints, provenance tracking, and remote execution capabilities.
https://aiida-workgraph.readthedocs.io/en/latest/
MIT License
9 stars 5 forks source link

Add TaskCollection for waiting_on and children. #223

Closed superstar54 closed 4 weeks ago

superstar54 commented 1 month ago

Although there remains some debate over whether to use the append or replace method for managing the waiting_on list, I've decided to proceed with the append approach based on my past experiences. We are open to revising this if there is strong opposition.

For instance, the code below demonstrates how to append "task1" and "task2" to the waiting_on list for task3, rather than replacing the existing list with ("task1", "task2"):

task3.waiting_on.add(["task1", "task2"])

TaskCollection

Implement a TaskCollection to store a collection of tasks. This is used for the waiting_on and children attributes of the Task class. For example:

self.waiting_on = TaskCollection()
self.children = TaskCollection()

waiting_on

Take waiting_on as an example:

# can use the name of the task, or the task object itself
task3.waiting_on.add(["task1", task2])
task3.waiting_on.remove(["task1", "task2"])
task3.waiting_on.clear()

When adding or removing the task, it will check if the task exists or not.

Children

The children attribute is used to assign tasks to a Zone (e.g., While zone or If zone). For example,

# add task1 and task2 to the while loop
while_task.children.add(["task1", "task2"])
codecov-commenter commented 1 month ago

Codecov Report

Attention: Patch coverage is 93.20388% with 7 lines in your changes missing coverage. Please review.

Project coverage is 79.39%. Comparing base (5937b88) to head (e358fab). Report is 28 commits behind head on main.

Files Patch % Lines
aiida_workgraph/task.py 90.38% 5 Missing :warning:
aiida_workgraph/tasks/builtins.py 85.71% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #223 +/- ## ========================================== + Coverage 75.75% 79.39% +3.63% ========================================== Files 70 61 -9 Lines 4615 4479 -136 ========================================== + Hits 3496 3556 +60 + Misses 1119 923 -196 ``` | [Flag](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/223/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | Coverage Δ | | |---|---|---| | [python-3.11](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/223/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | `79.28% <93.20%> (+3.61%)` | :arrow_up: | | [python-3.9](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/223/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | `79.34% <93.20%> (+3.61%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

edan-bainglass commented 4 weeks ago

I agree, regardless of the debate, good to get the code in for live testing. Maybe experience helps (partially) resolve the debate 🤞