Skip to content

Commit 0a9ace9

Browse files
authored
Prevent parent/detatched path conflict (#711)
* Prevent parent/detatched path conflict For macros with executors. Closes #710 Signed-off-by: liamhuber <[email protected]> * Add new demo node to expected list Signed-off-by: liamhuber <[email protected]> --------- Signed-off-by: liamhuber <[email protected]>
1 parent 8e1acd8 commit 0a9ace9

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed

pyiron_workflow/nodes/composite.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ def _get_state_from_remote_other(self, other_self):
299299
state = other_self.__getstate__()
300300
state.pop("_executor") # Got overridden to None for __getstate__, so keep local
301301
state.pop("_parent") # Got overridden to None for __getstate__, so keep local
302+
state.pop("_detached_parent_path")
302303
return state
303304

304305
def disconnect_run(self) -> list[tuple[InputSignal, OutputSignal]]:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import unittest
2+
from concurrent import futures
3+
4+
import pyiron_workflow as pwf
5+
from pyiron_workflow import _tests
6+
7+
_tests.ensure_tests_in_python_path()
8+
from static import demo_nodes # noqa: E402
9+
10+
11+
class TestNestingExecutors(unittest.TestCase):
12+
def test_executors_at_depth(self):
13+
def build_wf():
14+
wf = pwf.Workflow("exec")
15+
wf.six = demo_nodes.AddSix(0)
16+
return wf
17+
18+
expected = {"six__add_six": 6}
19+
20+
with self.subTest("parent"):
21+
wf = build_wf()
22+
wf.executor = (futures.ProcessPoolExecutor, (), {})
23+
future = wf.run()
24+
future.result()
25+
self.assertDictEqual(expected, wf.outputs.to_value_dict())
26+
27+
with self.subTest("child"):
28+
wf = build_wf()
29+
wf.six.executor = (futures.ProcessPoolExecutor, (), {})
30+
self.assertDictEqual(expected, wf.run())
31+
32+
with self.subTest("grandchild"):
33+
wf = build_wf()
34+
wf.six.a.executor = (futures.ProcessPoolExecutor, (), {})
35+
self.assertDictEqual(expected, wf.run())
36+
37+
with self.subTest("function"):
38+
wf = build_wf()
39+
wf.six.a.two.executor = (futures.ProcessPoolExecutor, (), {})
40+
self.assertDictEqual(expected, wf.run())

tests/static/demo_nodes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ def AddThree(self, x: int) -> int:
1919
return self.three
2020

2121

22+
@Workflow.wrap.as_macro_node("add_six")
23+
def AddSix(self, x: int) -> int:
24+
self.a = AddThree(x)
25+
self.b = AddThree(self.a)
26+
return self.b
27+
28+
2229
@Workflow.wrap.as_function_node("add")
2330
def AddPlusOne(obj, other):
2431
"""The same IO labels as `standard.Add`, but with type hints and a boost."""

tests/unit/test_find.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_find_nodes(self):
4646
[o.__name__ for o in found_by_string],
4747
[
4848
demo_nodes.AddPlusOne.__name__,
49+
demo_nodes.AddSix.__name__,
4950
demo_nodes.AddThree.__name__,
5051
demo_nodes.Dynamic.__name__,
5152
demo_nodes.OptionallyAdd.__name__,

0 commit comments

Comments
 (0)