Skip to content

Commit

Permalink
Merge pull request #188 from pyiron/purge_starting_node_instances
Browse files Browse the repository at this point in the history
Purge and restore starting nodes from the state
  • Loading branch information
liamhuber authored Jan 31, 2024
2 parents 4df004b + 48141ac commit edac929
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion pyiron_workflow/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,13 @@ def _child_signal_connections(

@property
def node_labels(self) -> tuple[str]:
return (n.label for n in self)
return tuple(n.label for n in self)

@property
def _starting_node_labels(self):
# As a property so it appears in `__dir__` and thus is guaranteed to not
# conflict with a child node name in the state
return tuple(n.label for n in self.starting_nodes)

def __getstate__(self):
state = super().__getstate__()
Expand All @@ -665,6 +671,11 @@ def __getstate__(self):
state[node.label] = node
# This key is guaranteed to be available in the state, since children are
# forbidden from having labels that clash with their parent's __dir__

# Also remove the starting node instances
del state["starting_nodes"]
state["_starting_node_labels"] = self._starting_node_labels

return state

def __setstate__(self, state):
Expand All @@ -685,6 +696,11 @@ def __setstate__(self, state):
{label: state[label] for label in state.pop("node_labels")}
)

# Restore starting nodes
state["starting_nodes"] = [
state[label] for label in state.pop("_starting_node_labels")
]

super().__setstate__(state)

# Nodes purge their _parent information in their __getstate__
Expand Down

0 comments on commit edac929

Please sign in to comment.