@@ -368,6 +368,18 @@ def test_task_nostate_1(plugin):
368
368
# checking the results
369
369
results = nn .result ()
370
370
assert results .output .out == 5
371
+ # checking the return_inputs option, either is return_inputs is True, or "val",
372
+ # it should give values of inputs that corresponds to the specific element
373
+ results_verb = nn .result (return_inputs = True )
374
+ results_verb_val = nn .result (return_inputs = "val" )
375
+ assert results_verb [0 ] == results_verb_val [0 ] == {"NA.a" : 3 }
376
+ assert results_verb [1 ].output .out == results_verb_val [1 ].output .out == 5
377
+ # checking the return_inputs option return_inputs="ind"
378
+ # it should give indices of inputs (instead of values) for each element
379
+ results_verb_ind = nn .result (return_inputs = "ind" )
380
+ assert results_verb_ind [0 ] == {"NA.a" : None }
381
+ assert results_verb_ind [1 ].output .out == 5
382
+
371
383
# checking the output_dir
372
384
assert nn .output_dir .exists ()
373
385
@@ -709,6 +721,22 @@ def test_task_state_1(plugin):
709
721
expected = [({"NA.a" : 3 }, 5 ), ({"NA.a" : 5 }, 7 )]
710
722
for i , res in enumerate (expected ):
711
723
assert results [i ].output .out == res [1 ]
724
+
725
+ # checking the return_inputs option, either return_inputs is True or "val",
726
+ # it should give values of inputs that corresponds to the specific element
727
+ results_verb = nn .result (return_inputs = True )
728
+ results_verb_val = nn .result (return_inputs = "val" )
729
+ for i , res in enumerate (expected ):
730
+ assert (results_verb [i ][0 ], results_verb [i ][1 ].output .out ) == res
731
+ assert (results_verb_val [i ][0 ], results_verb_val [i ][1 ].output .out ) == res
732
+
733
+ # checking the return_inputs option return_inputs="ind"
734
+ # it should give indices of inputs (instead of values) for each element
735
+ results_verb_ind = nn .result (return_inputs = "ind" )
736
+ expected_ind = [({"NA.a" : 0 }, 5 ), ({"NA.a" : 1 }, 7 )]
737
+ for i , res in enumerate (expected_ind ):
738
+ assert (results_verb_ind [i ][0 ], results_verb_ind [i ][1 ].output .out ) == res
739
+
712
740
# checking the output_dir
713
741
assert nn .output_dir
714
742
for odir in nn .output_dir :
@@ -737,13 +765,14 @@ def test_task_state_1a(plugin):
737
765
738
766
739
767
@pytest .mark .parametrize (
740
- "splitter, state_splitter, state_rpn, expected" ,
768
+ "splitter, state_splitter, state_rpn, expected, expected_ind " ,
741
769
[
742
770
(
743
771
("a" , "b" ),
744
772
("NA.a" , "NA.b" ),
745
773
["NA.a" , "NA.b" , "." ],
746
774
[({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
775
+ [({"NA.a" : 0 , "NA.b" : 0 }, 13 ), ({"NA.a" : 1 , "NA.b" : 1 }, 25 )],
747
776
),
748
777
(
749
778
["a" , "b" ],
@@ -755,11 +784,19 @@ def test_task_state_1a(plugin):
755
784
({"NA.a" : 5 , "NA.b" : 10 }, 15 ),
756
785
({"NA.a" : 5 , "NA.b" : 20 }, 25 ),
757
786
],
787
+ [
788
+ ({"NA.a" : 0 , "NA.b" : 0 }, 13 ),
789
+ ({"NA.a" : 0 , "NA.b" : 1 }, 23 ),
790
+ ({"NA.a" : 1 , "NA.b" : 0 }, 15 ),
791
+ ({"NA.a" : 1 , "NA.b" : 1 }, 25 ),
792
+ ],
758
793
),
759
794
],
760
795
)
761
796
@pytest .mark .parametrize ("plugin" , Plugins )
762
- def test_task_state_2 (plugin , splitter , state_splitter , state_rpn , expected ):
797
+ def test_task_state_2 (
798
+ plugin , splitter , state_splitter , state_rpn , expected , expected_ind
799
+ ):
763
800
""" Tasks with two inputs and a splitter (no combiner)"""
764
801
nn = fun_addvar (name = "NA" ).split (splitter = splitter , a = [3 , 5 ], b = [10 , 20 ])
765
802
@@ -777,6 +814,21 @@ def test_task_state_2(plugin, splitter, state_splitter, state_rpn, expected):
777
814
results = nn .result ()
778
815
for i , res in enumerate (expected ):
779
816
assert results [i ].output .out == res [1 ]
817
+
818
+ # checking the return_inputs option, either return_inputs is True or "val",
819
+ # it should give values of inputs that corresponds to the specific element
820
+ results_verb = nn .result (return_inputs = True )
821
+ results_verb_val = nn .result (return_inputs = "val" )
822
+ for i , res in enumerate (expected ):
823
+ assert (results_verb [i ][0 ], results_verb [i ][1 ].output .out ) == res
824
+ assert (results_verb_val [i ][0 ], results_verb_val [i ][1 ].output .out ) == res
825
+
826
+ # checking the return_inputs option return_inputs="ind"
827
+ # it should give indices of inputs (instead of values) for each element
828
+ results_verb_ind = nn .result (return_inputs = "ind" )
829
+ for i , res in enumerate (expected_ind ):
830
+ assert (results_verb_ind [i ][0 ], results_verb_ind [i ][1 ].output .out ) == res
831
+
780
832
# checking the output_dir
781
833
assert nn .output_dir
782
834
for odir in nn .output_dir :
@@ -982,11 +1034,25 @@ def test_task_state_comb_1(plugin):
982
1034
983
1035
# checking the results
984
1036
results = nn .result ()
985
-
986
1037
# fully combined (no nested list)
987
1038
combined_results = [res .output .out for res in results ]
988
-
989
1039
assert combined_results == [5 , 7 ]
1040
+
1041
+ expected = [({"NA.a" : 3 }, 5 ), ({"NA.a" : 5 }, 7 )]
1042
+ expected_ind = [({"NA.a" : 0 }, 5 ), ({"NA.a" : 1 }, 7 )]
1043
+ # checking the return_inputs option, either return_inputs is True or "val",
1044
+ # it should give values of inputs that corresponds to the specific element
1045
+ results_verb = nn .result (return_inputs = True )
1046
+ results_verb_val = nn .result (return_inputs = "val" )
1047
+ for i , res in enumerate (expected ):
1048
+ assert (results_verb [i ][0 ], results_verb [i ][1 ].output .out ) == res
1049
+ assert (results_verb_val [i ][0 ], results_verb_val [i ][1 ].output .out ) == res
1050
+ # checking the return_inputs option return_inputs="ind"
1051
+ # it should give indices of inputs (instead of values) for each element
1052
+ results_verb_ind = nn .result (return_inputs = "ind" )
1053
+ for i , res in enumerate (expected_ind ):
1054
+ assert (results_verb_ind [i ][0 ], results_verb_ind [i ][1 ].output .out ) == res
1055
+
990
1056
# checking the output_dir
991
1057
assert nn .output_dir
992
1058
for odir in nn .output_dir :
@@ -995,7 +1061,7 @@ def test_task_state_comb_1(plugin):
995
1061
996
1062
@pytest .mark .parametrize (
997
1063
"splitter, combiner, state_splitter, state_rpn, state_combiner, state_combiner_all, "
998
- "state_splitter_final, state_rpn_final, expected" ,
1064
+ "state_splitter_final, state_rpn_final, expected, expected_val " ,
999
1065
[
1000
1066
(
1001
1067
("a" , "b" ),
@@ -1006,7 +1072,8 @@ def test_task_state_comb_1(plugin):
1006
1072
["NA.a" , "NA.b" ],
1007
1073
None ,
1008
1074
[],
1009
- [({}, [13 , 25 ])],
1075
+ [13 , 25 ],
1076
+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
1010
1077
),
1011
1078
(
1012
1079
("a" , "b" ),
@@ -1017,7 +1084,8 @@ def test_task_state_comb_1(plugin):
1017
1084
["NA.a" , "NA.b" ],
1018
1085
None ,
1019
1086
[],
1020
- [({}, [13 , 25 ])],
1087
+ [13 , 25 ],
1088
+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
1021
1089
),
1022
1090
(
1023
1091
["a" , "b" ],
@@ -1028,7 +1096,11 @@ def test_task_state_comb_1(plugin):
1028
1096
["NA.a" ],
1029
1097
"NA.b" ,
1030
1098
["NA.b" ],
1031
- [({"NA.b" : 10 }, [13 , 15 ]), ({"NA.b" : 20 }, [23 , 25 ])],
1099
+ [[13 , 15 ], [23 , 25 ]],
1100
+ [
1101
+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 10 }, 15 )],
1102
+ [({"NA.a" : 3 , "NA.b" : 20 }, 23 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
1103
+ ],
1032
1104
),
1033
1105
(
1034
1106
["a" , "b" ],
@@ -1039,7 +1111,11 @@ def test_task_state_comb_1(plugin):
1039
1111
["NA.b" ],
1040
1112
"NA.a" ,
1041
1113
["NA.a" ],
1042
- [({"NA.a" : 3 }, [13 , 23 ]), ({"NA.a" : 5 }, [15 , 25 ])],
1114
+ [[13 , 23 ], [15 , 25 ]],
1115
+ [
1116
+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 3 , "NA.b" : 20 }, 23 )],
1117
+ [({"NA.a" : 5 , "NA.b" : 10 }, 15 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
1118
+ ],
1043
1119
),
1044
1120
(
1045
1121
["a" , "b" ],
@@ -1050,7 +1126,13 @@ def test_task_state_comb_1(plugin):
1050
1126
["NA.a" , "NA.b" ],
1051
1127
None ,
1052
1128
[],
1053
- [({}, [13 , 23 , 15 , 25 ])],
1129
+ [13 , 23 , 15 , 25 ],
1130
+ [
1131
+ ({"NA.a" : 3 , "NA.b" : 10 }, 13 ),
1132
+ ({"NA.a" : 3 , "NA.b" : 20 }, 23 ),
1133
+ ({"NA.a" : 5 , "NA.b" : 10 }, 15 ),
1134
+ ({"NA.a" : 5 , "NA.b" : 20 }, 25 ),
1135
+ ],
1054
1136
),
1055
1137
],
1056
1138
)
@@ -1066,6 +1148,7 @@ def test_task_state_comb_2(
1066
1148
state_splitter_final ,
1067
1149
state_rpn_final ,
1068
1150
expected ,
1151
+ expected_val ,
1069
1152
):
1070
1153
""" Tasks with scalar and outer splitters and partial or full combiners"""
1071
1154
nn = (
@@ -1080,19 +1163,32 @@ def test_task_state_comb_2(
1080
1163
assert nn .state .splitter_rpn == state_rpn
1081
1164
assert nn .state .combiner == state_combiner
1082
1165
1166
+ with Submitter (plugin = plugin ) as sub :
1167
+ sub (nn )
1168
+
1083
1169
assert nn .state .splitter_final == state_splitter_final
1084
1170
assert nn .state .splitter_rpn_final == state_rpn_final
1085
1171
assert set (nn .state .right_combiner_all ) == set (state_combiner_all )
1086
1172
1087
- with Submitter (plugin = plugin ) as sub :
1088
- sub (nn )
1089
-
1090
1173
# checking the results
1091
1174
results = nn .result ()
1175
+ # checking the return_inputs option, either return_inputs is True or "val",
1176
+ # it should give values of inputs that corresponds to the specific element
1177
+ results_verb = nn .result (return_inputs = True )
1178
+
1179
+ if nn .state .splitter_rpn_final :
1180
+ for i , res in enumerate (expected ):
1181
+ assert [res .output .out for res in results [i ]] == res
1182
+ # results_verb
1183
+ for i , res_l in enumerate (expected_val ):
1184
+ for j , res in enumerate (res_l ):
1185
+ assert (results_verb [i ][j ][0 ], results_verb [i ][j ][1 ].output .out ) == res
1186
+ # if the combiner is full expected is "a flat list"
1187
+ else :
1188
+ assert [res .output .out for res in results ] == expected
1189
+ for i , res in enumerate (expected_val ):
1190
+ assert (results_verb [i ][0 ], results_verb [i ][1 ].output .out ) == res
1092
1191
1093
- combined_results = [[res .output .out for res in res_l ] for res_l in results ]
1094
- for i , res in enumerate (expected ):
1095
- assert combined_results [i ] == res [1 ]
1096
1192
# checking the output_dir
1097
1193
assert nn .output_dir
1098
1194
for odir in nn .output_dir :
@@ -1130,7 +1226,7 @@ def test_task_state_comb_singl_1(plugin):
1130
1226
1131
1227
1132
1228
@pytest .mark .parametrize ("plugin" , Plugins )
1133
- def test_task_state_comb_2 (plugin ):
1229
+ def test_task_state_comb_3 (plugin ):
1134
1230
""" task with the simplest splitter, the input is an empty list"""
1135
1231
nn = fun_addtwo (name = "NA" ).split (splitter = "a" , a = []).combine (combiner = ["a" ])
1136
1232
0 commit comments