From b249abfef168e466952abf23d4199b41e9d418db Mon Sep 17 00:00:00 2001 From: liamhuber Date: Tue, 13 Aug 2024 15:29:26 -0700 Subject: [PATCH] Simplify setup and allow loading and running at init --- pyiron_workflow/node.py | 24 +++++++----------------- tests/unit/test_node.py | 34 +++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/pyiron_workflow/node.py b/pyiron_workflow/node.py index 72e30a226..e53f6f21c 100644 --- a/pyiron_workflow/node.py +++ b/pyiron_workflow/node.py @@ -342,33 +342,23 @@ def _after_node_setup( ): if delete_existing_savefiles: self.delete_storage(backend=autoload) - do_load = False - else: - do_load = autoload is not None and self.any_storage_has_contents(autoload) - - if do_load and autorun: - raise ValueError( - f"{self.full_label} can't both load _and_ run after init -- either" - f" delete the save file (e.g. with with the `delete_existing_savefiles=True` " - f"kwarg), change the node label to work in a new space, or give up on " - f"running after init." - ) - elif do_load: + + if autoload is not None and self.any_storage_has_contents(autoload): logger.info( f"A saved file was found for the node {self.full_label} -- " f"attempting to load it...(To delete the saved file instead, use " f"`delete_existing_savefiles=True`)" ) self.load(backend=autoload) - self.set_input_values(*args, **kwargs) - elif autorun: + + self.set_input_values(*args, **kwargs) + + if autorun: try: - self.set_input_values(*args, **kwargs) self.run() except ReadinessError: pass - else: - self.set_input_values(*args, **kwargs) + self.graph_root.tidy_working_directory() @property diff --git a/tests/unit/test_node.py b/tests/unit/test_node.py index 721de19fd..3db43c5f3 100644 --- a/tests/unit/test_node.py +++ b/tests/unit/test_node.py @@ -436,17 +436,29 @@ def test_storage(self): ) run_right_away.save() - with self.assertRaises( - ValueError, - msg="Should not be able to both immediately run _and_ load a " - "node at once" - ): - ANode( - label=self.n1.label, - x=x, - autorun=True, - autoload=backend - ) + load_and_rerun_origal_input = ANode( + label=self.n1.label, + autorun=True, + autoload=backend + ) + self.assertEqual( + load_and_rerun_origal_input.outputs.y.value, + run_right_away.outputs.y.value, + msg="Loading and then running immediately is fine, and should " + "recover existing input" + ) + load_and_rerun_new_input = ANode( + label=self.n1.label, + x=x + 1, + autorun=True, + autoload=backend + ) + self.assertEqual( + load_and_rerun_new_input.outputs.y.value, + run_right_away.outputs.y.value + 1, + msg="Loading and then running immediately is fine, and should " + "notice the new input" + ) force_run = ANode( label=self.n1.label,