Skip to content

Commit

Permalink
[minor] Make the input cache private
Browse files Browse the repository at this point in the history
In optimistic anticipation of tracking the connection of input and output without using an explicit cache (e.g. traitlets to track when channel values change)
  • Loading branch information
liamhuber committed Aug 22, 2024
1 parent 89f71e2 commit cef10fb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions notebooks/deepdive.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@
],
"source": [
"for node in wf:\n",
" print(node.label, node.inputs.to_value_dict(), node.cached_inputs, node.cache_hit)"
" print(node.label, node.inputs.to_value_dict(), node._cached_inputs, node.cache_hit)"
]
},
{
Expand Down Expand Up @@ -1805,15 +1805,15 @@
}
],
"source": [
"wf.a.cached_inputs"
"wf.a._cached_inputs"
]
},
{
"cell_type": "markdown",
"id": "4f7f7cf1-9e94-44a7-8d01-01f38900d2f2",
"metadata": {},
"source": [
"Thus, we're going to encounter the `inputs == cached_inputs` whether we want it or not, so if we try to re-run the workflow nothing will happen:"
"Thus, we're going to encounter the `inputs == _cached_inputs` whether we want it or not, so if we try to re-run the workflow nothing will happen:"
]
},
{
Expand Down Expand Up @@ -2499,7 +2499,7 @@
" 'future': None,\n",
" '_thread_pool_sleep_time': 1e-06,\n",
" 'checkpoint': None,\n",
" 'cached_inputs': {'x': 'start', 'y': '', 'z': 'immediate'},\n",
" '_cached_inputs': {'x': 'start', 'y': '', 'z': 'immediate'},\n",
" '_user_data': {},\n",
" '_inputs': <pyiron_workflow.io.Inputs at 0x131348690>,\n",
" '_outputs': <pyiron_workflow.mixin.injection.OutputsWithInjection at 0x13134b750>}"
Expand Down
6 changes: 3 additions & 3 deletions pyiron_workflow/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def __init__(
parent=parent,
)
self.checkpoint = checkpoint
self.cached_inputs = None
self._cached_inputs = None
self._user_data = {} # A place for power-users to bypass node-injection

self._setup_node()
Expand Down Expand Up @@ -445,7 +445,7 @@ def run(

return self._outputs_to_run_return()
elif self.use_cache: # Write cache and continue
self.cached_inputs = self.inputs.to_value_dict()
self._cached_inputs = self.inputs.to_value_dict()

if self.parent is not None:
self.parent.register_child_starting(self)
Expand Down Expand Up @@ -562,7 +562,7 @@ def run_data_tree(self, run_parent_trees_too=False) -> None:
@property
def cache_hit(self):
try:
return self.inputs.to_value_dict() == self.cached_inputs
return self.inputs.to_value_dict() == self._cached_inputs
except:
return False

Expand Down
8 changes: 4 additions & 4 deletions pyiron_workflow/nodes/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def add_child(
f"Only new {Node.__name__} instances may be added, but got "
f"{type(child)}."
)
self.cached_inputs = None # Reset cache after graph change
self._cached_inputs = None # Reset cache after graph change
return super().add_child(child, label=label, strict_naming=strict_naming)

def remove_child(self, child: Node | str) -> list[tuple[Channel, Channel]]:
Expand All @@ -272,7 +272,7 @@ def remove_child(self, child: Node | str) -> list[tuple[Channel, Channel]]:
disconnected = child.disconnect()
if child in self.starting_nodes:
self.starting_nodes.remove(child)
self.cached_inputs = None # Reset cache after graph change
self._cached_inputs = None # Reset cache after graph change
return disconnected

def replace_child(
Expand Down Expand Up @@ -352,8 +352,8 @@ def replace_child(
sending_channel.value_receiver = receiving_channel

# Clear caches
self.cached_inputs = None
replacement.cached_inputs = None
self._cached_inputs = None
replacement._cached_inputs = None

return owned_node

Expand Down

0 comments on commit cef10fb

Please sign in to comment.