Skip to content

Commit abfef7b

Browse files
committed
adding comments
1 parent e37e769 commit abfef7b

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

pydra/engine/helpers_state.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def iter_splits(iterable, keys):
363363

364364

365365
def input_shape(inp, cont_dim=1):
366-
"""Get input shape."""
366+
"""Get input shape, depends on the container dimension, if not specify it is assumed to be 1 """
367367
# TODO: have to be changed for inner splitter (sometimes different length)
368368
cont_dim -= 1
369369
shape = [len(inp)]
@@ -396,6 +396,9 @@ def splits(splitter_rpn, inputs, inner_inputs=None, cont_dim=None):
396396
input variables
397397
inner_inputs: dict, optional
398398
inner input specification
399+
cont_dim: dict, optional
400+
container dimension for input variable, specifies how nested is the intput,
401+
if not specified 1 will be used for all inputs (so will not be flatten)
399402
400403
401404
Returns

pydra/engine/state.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def prepare_states(self, inputs, cont_dim=None):
357357
specific elements from inputs that can be used running interfaces
358358
359359
"""
360+
# container dimension for each input, specifies how nested the input is
360361
if cont_dim is None:
361362
self.cont_dim = {}
362363
else:

pydra/engine/tests/test_helpers_state.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def test_splits_groups_comb(
267267
),
268268
(
269269
(["a", "v"], "x"),
270-
{"x": 2},
270+
{"x": 2}, # input x is treated as 2d container, so x will be flatten
271271
[((0, 0), 0), ((0, 1), 1), ((1, 0), 2), ((1, 1), 3)],
272272
["a", "v", "x"],
273273
[
@@ -306,7 +306,7 @@ def test_splits_1b(splitter, cont_dim, values, keys, splits):
306306
((["a", "v"], "c"), None, {"a": [1, 2], "v": ["a", "b"], "c": [3, 4]}, True),
307307
(
308308
(["a", "v"], "c"),
309-
{"c": 2},
309+
{"c": 2}, # c is treated as 2d container
310310
{"a": [1, 2], "v": ["a", "b"], "c": [[3, 4], [5, 6]]},
311311
False,
312312
),
@@ -442,7 +442,7 @@ def test_splits_2(splitter_rpn, inner_inputs, values, keys, splits):
442442
# [["d211", "d212"], ["d221", "d222"]],
443443
# ],
444444
}
445-
cont_dim = {"NB.b": 2}
445+
cont_dim = {"NB.b": 2} # will be treated as 2d container
446446
values_out, keys_out, _ = hlpst.splits(
447447
splitter_rpn, inputs, inner_inputs=inner_inputs, cont_dim=cont_dim
448448
)

pydra/engine/tests/test_state.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ def test_state_connect_innerspl_1():
566566

567567
st2.prepare_states(
568568
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]]},
569-
cont_dim={"NB.b": 2},
569+
cont_dim={"NB.b": 2}, # will be treated as 2d container
570570
)
571571

572572
assert st2.states_ind == [
@@ -613,7 +613,7 @@ def test_state_connect_innerspl_1a():
613613

614614
st2.prepare_states(
615615
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]]},
616-
cont_dim={"NB.b": 2},
616+
cont_dim={"NB.b": 2}, # will be treated as 2d container
617617
)
618618

619619
assert st2.states_ind == [
@@ -667,7 +667,7 @@ def test_state_connect_innerspl_2():
667667

668668
st2.prepare_states(
669669
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]], "NB.c": [13, 17]},
670-
cont_dim={"NB.b": 2},
670+
cont_dim={"NB.b": 2}, # will be treated as 2d container
671671
)
672672
assert st2.states_ind == [
673673
{"NB.c": 0, "NA.a": 0, "NB.b": 0},
@@ -732,7 +732,7 @@ def test_state_connect_innerspl_2a():
732732

733733
st2.prepare_states(
734734
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]], "NB.c": [13, 17]},
735-
cont_dim={"NB.b": 2},
735+
cont_dim={"NB.b": 2}, # will be treated as 2d container
736736
)
737737

738738
assert st2.states_ind == [
@@ -803,7 +803,7 @@ def test_state_connect_innerspl_3():
803803
"NB.c": [13, 17],
804804
"NC.d": [33, 77],
805805
},
806-
cont_dim={"NB.b": 2},
806+
cont_dim={"NB.b": 2}, # will be treated as 2d container
807807
)
808808

809809
assert st2.states_ind == [
@@ -943,7 +943,7 @@ def test_state_connect_innerspl_4():
943943
"NC.f": [[23, 27], [33, 37]],
944944
"NC.d": [1, 2],
945945
},
946-
cont_dim={"NC.f": 2},
946+
cont_dim={"NC.f": 2}, # will be treated as 2d container
947947
)
948948
assert st3.states_ind == [
949949
{"NA.a": 0, "NB.b": 0, "NB.c": 0, "NC.d": 0},
@@ -1209,7 +1209,7 @@ def test_state_connect_innerspl_combine_1():
12091209

12101210
st2.prepare_states(
12111211
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]], "NB.c": [13, 17]},
1212-
cont_dim={"NB.b": 2},
1212+
cont_dim={"NB.b": 2}, # will be treated as 2d container
12131213
)
12141214
# NOW TODO: checking st2.states_ind_final!!!
12151215
assert st2.states_ind == [
@@ -1283,7 +1283,7 @@ def test_state_connect_innerspl_combine_2():
12831283

12841284
st2.prepare_states(
12851285
inputs={"NA.a": [3, 5], "NB.b": [[1, 10, 100], [2, 20, 200]], "NB.c": [13, 17]},
1286-
cont_dim={"NB.b": 2},
1286+
cont_dim={"NB.b": 2}, # will be treated as 2d container
12871287
)
12881288
assert st2.states_ind == [
12891289
{"NB.c": 0, "NA.a": 0, "NB.b": 0},

0 commit comments

Comments
 (0)