Skip to content

Commit

Permalink
support builtin collections and orm collections; make automatic conve…
Browse files Browse the repository at this point in the history
…rsion more generic
  • Loading branch information
agoscinski committed Sep 2, 2024
1 parent cd38e48 commit becb66a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions aiida_workgraph/engine/workgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

from aiida.engine.processes.exit_code import ExitCode
from aiida.engine.processes.process import Process
from aiida.engine import calcfunction

from aiida.engine.processes.workchains.awaitable import (
Awaitable,
Expand Down Expand Up @@ -922,16 +921,17 @@ def check_for_conditions(self) -> bool:
self.set_tasks_state(condition_tasks, "SKIPPED")

@calcfunction
def getitem(sequence, count):
value = sequence.get_list()[count.value]
# TODO can we make this more generic?
if isinstance(value, int):
return orm.Int(value)
def __getitem__(sequence, count):
value = sequence[count.value]
# only convert 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:
raise TypeError("`sequence` only supports sequence of integers")
return orm.to_aiida_type(value)


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

Expand Down

0 comments on commit becb66a

Please sign in to comment.