Skip to content

Commit

Permalink
🔥 🐛 Don't pull on input nodes (#318)
Browse files Browse the repository at this point in the history
* 🔥 🐛 Don't pull on input nodes

A simple call invokes a pull, including pulling the parent tree -- this blows up when the loop is inside a parent scope instead of alone. Since we _know_ these are just user input nodes with direct value connections to the loop macro's scope, we never need to run the pull, or indeed even a fetch the value.

* Format black

---------

Co-authored-by: pyiron-runner <pyiron@mpie.de>
  • Loading branch information
liamhuber and pyiron-runner committed May 8, 2024
1 parent 083e9fb commit 233dd56
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pyiron_workflow/for_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,13 @@ def _clean_existing_subgraph(self):
# -- it will see data it can work with, but if that data happens to
# have the wrong length it may successfully auto-run on the wrong thing
# and throw an error!
self.children[label]()
self.children[label].run(
run_data_tree=False,
run_parent_trees_too=False,
fetch_input=False,
# Data should simply be coming from the value link
# We just want to refresh the output
)
# TODO: Instead of deleting _everything_ each time, try and re-use stuff

def _build_collector_node(self, row_number):
Expand Down
40 changes: 39 additions & 1 deletion tests/unit/test_for_loop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import random
from concurrent.futures import ThreadPoolExecutor
from itertools import product
from time import perf_counter
Expand All @@ -12,7 +13,9 @@
MapsToNonexistentOutputError
)
from pyiron_workflow.function import as_function_node
from pyiron_workflow.node_library.standard import Sleep
from pyiron_workflow.macro import as_macro_node
from pyiron_workflow.node_library.standard import Add, Sleep
from pyiron_workflow.transform import inputs_to_list


class TestDictionaryToIndexMaps(unittest.TestCase):
Expand Down Expand Up @@ -315,6 +318,41 @@ def test_body_node_executor(self):
f"Expected limit {grace} x {t_sleep} = {grace * t_sleep} -- got {dt}"
)

def test_with_connections(self):
length_y = 3

@as_macro_node()
def LoopInside(self, x: list, y: int):
self.to_list = inputs_to_list(
length_y, y, y, y
)
self.loop = for_node(
Add,
iter_on=("obj", "other",),
obj=x,
other=self.to_list
)
return self.loop

x, y = [1], 2
li = LoopInside([1], 2)
df = li().loop
self.assertIsInstance(df, DataFrame)
self.assertEqual(length_y * len(x), len(df))
self.assertEqual(
x[0] + y,
df["add"][0],
msg="Just make sure the loop is actually running"
)
x, y = [2, 3], 4
df = li(x, y).loop
self.assertEqual(length_y * len(x), len(df))
self.assertEqual(
x[-1] + y,
df["add"][len(df) - 1],
msg="And make sure that we can vary the length still"
)


if __name__ == "__main__":
unittest.main()

0 comments on commit 233dd56

Please sign in to comment.