Skip to content

Commit 309c68f

Browse files
authored
No running cache hit (#714)
* Add return hint Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com> * Don't cache hit with running children Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com> * Simplify slurm test The parent workflows should fail to cache hit now anyway, since the child is running at the relevant times Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com> --------- Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
1 parent 69546e3 commit 309c68f

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

pyiron_workflow/node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ def run_data_tree(self, run_parent_trees_too=False) -> None:
704704
c1.connect(c2)
705705

706706
@property
707-
def cache_hit(self):
707+
def cache_hit(self) -> bool:
708708
try:
709709
return self.inputs.to_value_dict() == self._cached_inputs
710710
except Exception:

pyiron_workflow/nodes/composite.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ def use_cache(self, value: bool):
188188
for c in self.children.values():
189189
c.use_cache = value
190190

191+
@property
192+
def cache_hit(self) -> bool:
193+
return not any(c.running for c in self.children.values()) and super().cache_hit
194+
191195
def _on_cache_miss(self) -> None:
192196
super()._on_cache_miss()
193197
# Reset provenance and run status trackers

tests/cluster/slurm_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ def submission():
4949
print("submitting")
5050
print(time.time())
5151
wf.n2.executor = (CacheSlurmClusterExecutor, (), {"resource_dict": resource_dict})
52-
wf.n2.use_cache = False
5352
out = wf.run_in_thread()
5453
print("run return", out)
5554
state_check(wf, True, True)

tests/unit/nodes/test_composite.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,14 @@ def test_cache(self):
422422
"setting it recursively on all children",
423423
)
424424

425+
def test_cache_hit(self):
426+
self.comp.direct_child = Composite.create.function_node(plus_one)
427+
self.assertFalse(self.comp.cache_hit, msg="Sanity check")
428+
self.comp.run()
429+
self.assertTrue(self.comp.cache_hit, msg="Cache hit should be set")
430+
self.comp.direct_child.running = True # fake it
431+
self.assertFalse(self.comp.cache_hit, msg="If a child is running, cache miss")
432+
425433
def test_push_child(self):
426434
self.comp.n1 = self.comp.create.function_node(plus_one)
427435
self.comp.n2 = self.comp.create.function_node(plus_one, x=self.comp.n1)

0 commit comments

Comments
 (0)