From 26620b229a9b02751a2239175dfb15ac512f5313 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 30 Jan 2024 12:16:59 -0800 Subject: [PATCH 1/3] Purge and restore starting nodes from the state To minimize the number of complex instance objects stored in the state --- pyiron_workflow/composite.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pyiron_workflow/composite.py b/pyiron_workflow/composite.py index 6a08bbee..ee36ca2f 100644 --- a/pyiron_workflow/composite.py +++ b/pyiron_workflow/composite.py @@ -657,6 +657,11 @@ def __getstate__(self): state["node_labels"] = list(self.nodes.keys()) for node in self: state[node.label] = node + + # Also remove the starting node instances + del state["starting_nodes"] + state["starting_node_labels"] = [n.label for n in self.starting_nodes] + return state def __setstate__(self, state): @@ -677,6 +682,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__ From eb862b1741a6c5e9896d1b295644dcc3df3e9970 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Wed, 31 Jan 2024 09:25:19 -0800 Subject: [PATCH 2/3] Guarantee storage key availability --- pyiron_workflow/composite.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyiron_workflow/composite.py b/pyiron_workflow/composite.py index 6bbb732b..e21b8bed 100644 --- a/pyiron_workflow/composite.py +++ b/pyiron_workflow/composite.py @@ -641,6 +641,12 @@ def _child_signal_connections( def node_labels(self) -> tuple[str]: return (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__() # Store connections as strings @@ -668,7 +674,7 @@ def __getstate__(self): # Also remove the starting node instances del state["starting_nodes"] - state["starting_node_labels"] = [n.label for n in self.starting_nodes] + state["_starting_node_labels"] = self._starting_node_labels return state @@ -692,7 +698,7 @@ def __setstate__(self, state): # Restore starting nodes state["starting_nodes"] = [ - state[label] for label in state.pop("starting_node_labels") + state[label] for label in state.pop("_starting_node_labels") ] super().__setstate__(state) From 48141ac76cfe90f30e39289785821098f1d866e0 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Wed, 31 Jan 2024 09:25:44 -0800 Subject: [PATCH 3/3] :bug: hotfix generator to tuple conversion --- pyiron_workflow/composite.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyiron_workflow/composite.py b/pyiron_workflow/composite.py index e21b8bed..e63bc00b 100644 --- a/pyiron_workflow/composite.py +++ b/pyiron_workflow/composite.py @@ -639,7 +639,7 @@ 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):