Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PythonJob supports list of AiiDA node as output #190

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

superstar54
Copy link
Member

@superstar54 superstar54 commented Jul 19, 2024

It would be very helpful (user-friendly) for PythonJob to support a list of AiiDA nodes as the output. In order to do that:

  • When parsing the list output, give a special name as the key, list_data_{i}
  • When preparing the submission, if the key of a dict item starts with list_data_, we assume that this should convert to a list.

Note that this will be handled internally by the PythonJob, so the user will not be aware of this.

Use the example of EOS from @mbercx ,

from aiida_workgraph import task, WorkGraph
from ase import Atoms
from ase.build import bulk

@task.pythonjob(outputs=[{"name": "structure_lst", "identifier": "Namespace"}])
def generate_structures(structure: Atoms, factor_lst: list) -> list[Atoms]:
    structure_lst = []
    for factor in factor_lst:
        structure_strain = structure.copy()
        structure_strain.set_cell(
            structure_strain.cell * factor,
            scale_atoms=True
        )
        structure_lst.append(structure_strain)
    return structure_lst

# user can also decorate a existing function
#generate_structures = task.pythonjob(outputs=[{"name": "structure_lst", "identifier": "Namespace"}])(generate_structures)


atoms = bulk("Si")
wg = WorkGraph("EOS-WG")
generate_structures_task = wg.add_task(
        generate_structures,
        name="generate_structures",
        factor_lst=[0.95, 1.0, 1.05],
        structure=atoms,
    )
wg.submit()

@superstar54 superstar54 marked this pull request as draft July 19, 2024 14:42
@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2024

Codecov Report

Attention: Patch coverage is 91.17647% with 3 lines in your changes missing coverage. Please review.

Project coverage is 75.71%. Comparing base (5937b88) to head (3b3487c).
Report is 15 commits behind head on main.

Files Patch % Lines
tests/test_python.py 83.33% 2 Missing ⚠️
aiida_workgraph/utils/__init__.py 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #190      +/-   ##
==========================================
- Coverage   75.75%   75.71%   -0.04%     
==========================================
  Files          70       69       -1     
  Lines        4615     4732     +117     
==========================================
+ Hits         3496     3583      +87     
- Misses       1119     1149      +30     
Flag Coverage Δ
python-3.11 75.61% <91.17%> (-0.06%) ⬇️
python-3.9 75.68% <91.17%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Parse list output, give a special name as key, `list_data_{i}`
- When prepre the submission, if the key of a dict item start with `list_data_`, we assume that this should convert to a list.
@superstar54 superstar54 changed the title add NamespaceList PythonJob supports list of AiiDA data as output Jul 19, 2024
@superstar54 superstar54 marked this pull request as ready for review July 19, 2024 15:44
@superstar54 superstar54 linked an issue Jul 19, 2024 that may be closed by this pull request
@superstar54 superstar54 changed the title PythonJob supports list of AiiDA data as output PythonJob supports list of AiiDA node as output Jul 19, 2024
@superstar54 superstar54 requested a review from mbercx July 19, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PythonJob supports list of AiiDA node as output.
2 participants