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

Use calcfunction for getitem in For loop workgraph #283

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions aiida_workgraph/engine/workgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
construct_awaitable,
)
from aiida.engine.processes.workchains.workchain import Protect, WorkChainSpec
from aiida.engine import run_get_node
from aiida.engine import calcfunction, run_get_node
from aiida_workgraph.utils import create_and_pause_process
from aiida_workgraph.task import Task
from aiida_workgraph.utils import get_nested_dict, update_nested_dict
Expand Down Expand Up @@ -920,7 +920,19 @@ def check_for_conditions(self) -> bool:
if should_run:
self.reset()
self.set_tasks_state(condition_tasks, "SKIPPED")
self.ctx["i"] = self.ctx._sequence[self.ctx._count]

@calcfunction
def __getitem__(sequence, count):
value = sequence[count.value]
# only convert value f not already orm type because sequence
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
# only convert value f not already orm type because sequence
# only convert value if not already orm type because sequence

# might be builtin collection with orm types so a conversion is
# not needed and would raise an error
if isinstance(value, orm.Data):
return value
else:
return orm.to_aiida_type(value)

self.ctx["i"] = __getitem__(self.ctx._sequence, self.ctx._count)
self.ctx._count += 1
return should_run

Expand Down
Loading