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

Pickle the input value if it is a function #262

Closed superstar54 closed 2 weeks ago

superstar54 commented 2 weeks ago

In workgraph, we use aiida.orm.utils.serialize.serialize (yaml serialize) to serialize the input data of a workgraph and save it to the node.base.extras. However, the yaml seralizer can not handle the local function properly, as shown in #261 .

This PR provide a solution. If a Python function is used as a task input, we first serialize it using pickle, then use yaml.

We created a PickledLocalFunction class to serialize the function, and this class is the same as the PickledFunction. We use a different name just to label it, so that later we know we need to deserialize it and get the Python function back, before we pass it as a task input.

Test

I change the test_shell_workflow to test_shell_graph_builder and defined the parser inside the graph_bulder.

codecov-commenter commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 97.77778% with 1 line in your changes missing coverage. Please review.

Project coverage is 80.15%. Comparing base (5937b88) to head (d8ba291). Report is 45 commits behind head on main.

Files Patch % Lines
aiida_workgraph/utils/analysis.py 80.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #262 +/- ## ========================================== + Coverage 75.75% 80.15% +4.39% ========================================== Files 70 65 -5 Lines 4615 4872 +257 ========================================== + Hits 3496 3905 +409 + Misses 1119 967 -152 ``` | [Flag](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/262/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/262/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | `80.06% <97.77%> (+4.40%)` | :arrow_up: | | [python-3.12](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/262/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | `80.04% <97.77%> (?)` | | | [python-3.9](https://app.codecov.io/gh/aiidateam/aiida-workgraph/pull/262/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidateam) | `80.08% <97.77%> (+4.34%)` | :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.