Skip to content

Commit bce5ca3

Browse files
committed
fixing _ordering and small fix to the state class (using left_combiner_all instead of left_combiner)
1 parent 164e6b1 commit bce5ca3

File tree

4 files changed

+48
-15
lines changed

4 files changed

+48
-15
lines changed

pydra/engine/helpers_state.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def _ordering(
5959
splitter=other_states[node_nm][0].splitter_final, name=node_nm
6060
)
6161
el = (splitter_mod, el[1])
62-
if other_states[node_nm][0].other_states:
63-
other_states.update(other_states[node_nm][0].other_states)
62+
if other_states[node_nm][0].other_states:
63+
other_states.update(other_states[node_nm][0].other_states)
6464
if type(el[1]) is str and el[1].startswith("_"):
6565
node_nm = el[1][1:]
6666
if node_nm not in other_states and state_fields:
@@ -74,8 +74,8 @@ def _ordering(
7474
splitter=other_states[node_nm][0].splitter_final, name=node_nm
7575
)
7676
el = (el[0], splitter_mod)
77-
if other_states[node_nm][0].other_states:
78-
other_states.update(other_states[node_nm][0].other_states)
77+
if other_states[node_nm][0].other_states:
78+
other_states.update(other_states[node_nm][0].other_states)
7979
_iterate_list(
8080
el,
8181
".",

pydra/engine/state.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ def splitter_final(self):
136136

137137
@property
138138
def splitter_rpn(self):
139-
# TODO NOW: this also changes other_states (properly, but should be explicite)
140139
_splitter_rpn = hlpst.splitter2rpn(
141140
self.splitter, other_states=self.other_states
142141
)
@@ -215,11 +214,6 @@ def left_combiner(self):
215214
else:
216215
return list(set(self.combiner) - set(self.right_combiner))
217216

218-
# TODO: should i have setter
219-
@left_combiner.setter
220-
def left_combiner(self, left_combiner):
221-
self._left_combiner = left_combiner
222-
223217
@property
224218
def right_combiner_all(self):
225219
if hasattr(self, "_right_combiner_all"):
@@ -232,11 +226,11 @@ def left_combiner_all(self):
232226
if hasattr(self, "_left_combiner_all"):
233227
return self._left_combiner_all
234228
else:
235-
return []
229+
return self.left_combiner
236230

237231
@left_combiner_all.setter
238232
def left_combiner_all(self, left_combiner_all):
239-
self._left_combiner_all = left_combiner_all
233+
self._left_combiner_all = list(set(left_combiner_all))
240234

241235
@property
242236
def other_states(self):
@@ -395,8 +389,7 @@ def _merge_previous_states(self):
395389
self.group_for_inputs_final = {}
396390
self.keys_final = []
397391
if self.left_combiner:
398-
# TODO: should I update left_combiner somewhere else? (it changes when scallar splitter)
399-
_, _, _, self.left_combiner = hlpst.splits_groups(
392+
_, _, _, self.left_combiner_all = hlpst.splits_groups(
400393
self.left_splitter_rpn, combiner=self.left_combiner
401394
)
402395
for i, left_nm in enumerate(self.left_splitter_rpn_compact):
@@ -414,7 +407,7 @@ def _merge_previous_states(self):
414407
st = self.other_states[left_nm[1:]][0]
415408
# checking if left combiner contains any element from the st splitter
416409
st_combiner = [
417-
comb for comb in self.left_combiner if comb in st.splitter_rpn_final
410+
comb for comb in self.left_combiner_all if comb in st.splitter_rpn_final
418411
]
419412
if st_combiner:
420413
# keys and groups from previous states

pydra/engine/tests/test_state.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,8 @@ def test_state_connect_combine_3():
11431143
assert st2.splitter == ["_NA", "NB.d"]
11441144
assert st2.splitter_rpn == ["NA.b", "NB.d", "*"]
11451145
assert st2.splitter_rpn_final == ["NA.b"]
1146+
assert st2.left_combiner_all == st2.left_combiner == []
1147+
assert st2.right_combiner_all == st2.right_combiner == ["NB.d"]
11461148
assert st2.group_for_inputs_final == {"NA.b": 0}
11471149
assert st2.groups_stack_final == [[0]]
11481150

@@ -1203,6 +1205,8 @@ def test_state_connect_innerspl_combine_1():
12031205
assert st2.splitter_rpn == ["NA.a", "NB.c", "NB.b", "*", "*"]
12041206
assert st2.splitter_final == ["NA.a", "NB.c"]
12051207
assert st2.splitter_rpn_final == ["NA.a", "NB.c", "*"]
1208+
assert st2.left_combiner_all == st2.left_combiner == []
1209+
assert st2.right_combiner_all == st2.right_combiner == ["NB.b"]
12061210
assert st2.group_for_inputs_final == {"NA.a": 0, "NB.c": 1}
12071211
assert st2.groups_stack_final == [[0], [1]]
12081212
# TODO: i think at the end I should merge [0] and [1], because there are no inner splitters anymore
@@ -1377,6 +1381,8 @@ def test_state_connect_combine_left_2():
13771381
assert st2.splitter == "_NA"
13781382
assert st2.splitter_rpn == ["NA.a", "NA.b", "*"]
13791383
assert st2.combiner == ["NA.a"]
1384+
assert st2.left_combiner_all == st2.left_combiner == ["NA.a"]
1385+
assert st2.right_combiner_all == st2.right_combiner == []
13801386
assert st2.splitter_rpn_final == ["NA.b"]
13811387

13821388
assert st2.group_for_inputs_final == {"NA.b": 0}
@@ -1454,6 +1460,8 @@ def test_state_connect_combine_left_4():
14541460
assert st3.splitter == ["_NA", "_NB"]
14551461
assert st3.splitter_rpn == ["NA.a", "NB.a", "*"]
14561462
assert st3.splitter_rpn_final == ["NB.a"]
1463+
assert st3.left_combiner_all == st3.left_combiner == ["NA.a"]
1464+
assert st3.right_combiner_all == st3.right_combiner == []
14571465
assert st3.group_for_inputs_final == {"NB.a": 0}
14581466
assert st3.groups_stack_final == [[0]]
14591467

@@ -1499,6 +1507,9 @@ def test_state_connect_combine_left_5():
14991507
assert st3.splitter == ("_NA", "_NB")
15001508
assert st3.splitter_rpn == ["NA.a", "NB.a", "."]
15011509
assert st3.splitter_rpn_final == []
1510+
assert set(st3.left_combiner_all) == set(["NA.a", "NB.a"])
1511+
assert st3.left_combiner == ["NA.a"]
1512+
assert st3.right_combiner_all == st3.right_combiner == []
15021513
assert st3.group_for_inputs_final == {}
15031514
assert st3.groups_stack_final == []
15041515

@@ -1525,6 +1536,8 @@ def test_state_connect_combine_left_6():
15251536
assert st2.splitter == ["_NA", "NB.c"]
15261537
assert st2.splitter_rpn == ["NA.a", "NA.b", "*", "NB.c", "*"]
15271538
assert st2.combiner == ["NA.a"]
1539+
assert st2.left_combiner_all == st2.left_combiner == ["NA.a"]
1540+
assert st2.right_combiner_all == st2.right_combiner == []
15281541
assert st2.splitter_rpn_final == ["NA.b", "NB.c", "*"]
15291542

15301543
assert st2.group_for_inputs_final == {"NA.b": 0, "NB.c": 1}

pydra/engine/tests/test_workflow.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,33 @@ def test_wf_3nd_ndst_5(plugin):
11651165
assert wf.output_dir.exists()
11661166

11671167

1168+
@pytest.mark.parametrize("plugin", Plugins)
1169+
def test_wf_3nd_ndst_6(plugin):
1170+
""" workflow with three tasks, third one connected to two previous tasks,
1171+
the third one uses scalar splitter from the previous ones and a combiner
1172+
"""
1173+
wf = Workflow(name="wf_ndst_9", input_spec=["x", "y"])
1174+
wf.add(add2(name="add2x", x=wf.lzin.x).split("x"))
1175+
wf.add(add2(name="add2y", x=wf.lzin.y).split("x"))
1176+
wf.add(
1177+
multiply(name="mult", x=wf.add2x.lzout.out, y=wf.add2y.lzout.out)
1178+
.split(("_add2x", "_add2y"))
1179+
.combine("add2y.x")
1180+
)
1181+
wf.inputs.x = [1, 2]
1182+
wf.inputs.y = [11, 12]
1183+
wf.set_output([("out", wf.mult.lzout.out)])
1184+
wf.plugin = plugin
1185+
1186+
with Submitter(plugin=plugin) as sub:
1187+
sub(wf)
1188+
1189+
results = wf.result()
1190+
assert results.output.out == [39, 56]
1191+
# checking the output directory
1192+
assert wf.output_dir.exists()
1193+
1194+
11681195
# workflows with Left and Right part in splitters A -> B (L&R parts of the splitter)
11691196

11701197

0 commit comments

Comments
 (0)