Skip to content

Commit

Permalink
remove append in the awaitable manager
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Dec 2, 2024
1 parent 77b2a98 commit ad83b4b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 46 deletions.
20 changes: 1 addition & 19 deletions aiida_workgraph/engine/awaitable_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ def insert_awaitable(self, awaitable: Awaitable) -> None:
ctx, key = self.ctx_manager.resolve_nested_context(awaitable.key)

# Already assign the awaitable itself to the location in the context container where it is supposed to end up
# once it is resolved. This is especially important for the `APPEND` action, since it needs to maintain the
# order, but the awaitables will not necessarily be resolved in the order in which they are added. By using the
# awaitable as a placeholder, in the `_resolve_awaitable`, it can be found and replaced by the resolved value.
# once it is resolved.
if awaitable.action == AwaitableAction.ASSIGN:
ctx[key] = awaitable
elif awaitable.action == AwaitableAction.APPEND:
ctx.setdefault(key, []).append(awaitable)
else:
raise AssertionError(f"Unsupported awaitable action: {awaitable.action}")

Expand All @@ -67,20 +63,6 @@ def resolve_awaitable(self, awaitable: Awaitable, value: Any) -> None:

if awaitable.action == AwaitableAction.ASSIGN:
ctx[key] = value
elif awaitable.action == AwaitableAction.APPEND:
# Find the same awaitable inserted in the context
container = ctx[key]
for index, placeholder in enumerate(container):
if (
isinstance(placeholder, Awaitable)
and placeholder.pk == awaitable.pk
):
container[index] = value
break
else:
raise AssertionError(
f"Awaitable `{awaitable.pk} was not in `ctx.{awaitable.key}`"
)
else:
raise AssertionError(f"Unsupported awaitable action: {awaitable.action}")

Expand Down
11 changes: 0 additions & 11 deletions aiida_workgraph/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,4 @@ def set_value(self, value: Any) -> None:
else:
raise Exception("{} is not an {}.".format(value, DataClass.__name__))

def get_serialize(self) -> Dict[str, str]:
serialize = {"module": "aiida.orm.utils.serialize", "name": "serialize"}
return serialize

def get_deserialize(self) -> Dict[str, str]:
deserialize = {
"module": "aiida.orm.utils.serialize",
"name": "deserialize_unsafe",
}
return deserialize

return AiiDATaskProperty
11 changes: 0 additions & 11 deletions aiida_workgraph/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,4 @@ def __init__(
super().__init__(name, parent, type, index, uuid=uuid)
self.add_property(DataClass, name, **kwargs)

def get_serialize(self) -> dict:
serialize = {"module": "aiida.orm.utils.serialize", "name": "serialize"}
return serialize

def get_deserialize(self) -> dict:
deserialize = {
"module": "aiida.orm.utils.serialize",
"name": "deserialize_unsafe",
}
return deserialize

return AiiDATaskSocket
6 changes: 3 additions & 3 deletions tests/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def test_pause_play_task(wg_calcjob):
assert wg.tasks["add2"].node.process_status == "Paused through WorkGraph"
# I disabled the following lines because the test is not stable
# Seems the daemon is not responding to the play signal
wg.play_tasks(["add2"])
wg.wait()
assert wg.tasks["add2"].outputs["sum"].value == 9
# wg.play_tasks(["add2"])
# wg.wait()
# assert wg.tasks["add2"].outputs["sum"].value == 9


def test_pause_play_error_handler(wg_calcjob, finished_process_node):
Expand Down
9 changes: 7 additions & 2 deletions tests/widget/test_widget.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from IPython.display import IFrame


def test_workgraph_widget(wg_calcfunction):
"""Save the workgraph"""
from IPython.display import IFrame

wg = wg_calcfunction
wg.name = "test_workgraph_widget"
Expand All @@ -10,7 +12,7 @@ def test_workgraph_widget(wg_calcfunction):
# the waiting_on is also transformed to links
assert len(wg._widget.value["links"]) == 2
# to_html
data = wg._widget.to_html()
data = wg.to_html()
assert isinstance(data, IFrame)


Expand All @@ -25,3 +27,6 @@ def test_workgraph_task(wg_calcfunction):
wg.tasks["sumdiff2"]._widget.value["nodes"]["sumdiff2"]["inputs"]
) == len(wg.tasks["sumdiff2"].inputs)
assert len(wg.tasks["sumdiff2"]._widget.value["links"]) == 0
# to html
data = wg.tasks["sumdiff2"].to_html()
assert isinstance(data, IFrame)

0 comments on commit ad83b4b

Please sign in to comment.