@@ -368,6 +368,18 @@ def test_task_nostate_1(plugin):
368368 # checking the results
369369 results = nn .result ()
370370 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+
371383 # checking the output_dir
372384 assert nn .output_dir .exists ()
373385
@@ -709,6 +721,22 @@ def test_task_state_1(plugin):
709721 expected = [({"NA.a" : 3 }, 5 ), ({"NA.a" : 5 }, 7 )]
710722 for i , res in enumerate (expected ):
711723 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+
712740 # checking the output_dir
713741 assert nn .output_dir
714742 for odir in nn .output_dir :
@@ -737,13 +765,14 @@ def test_task_state_1a(plugin):
737765
738766
739767@pytest .mark .parametrize (
740- "splitter, state_splitter, state_rpn, expected" ,
768+ "splitter, state_splitter, state_rpn, expected, expected_ind " ,
741769 [
742770 (
743771 ("a" , "b" ),
744772 ("NA.a" , "NA.b" ),
745773 ["NA.a" , "NA.b" , "." ],
746774 [({"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 )],
747776 ),
748777 (
749778 ["a" , "b" ],
@@ -755,11 +784,19 @@ def test_task_state_1a(plugin):
755784 ({"NA.a" : 5 , "NA.b" : 10 }, 15 ),
756785 ({"NA.a" : 5 , "NA.b" : 20 }, 25 ),
757786 ],
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+ ],
758793 ),
759794 ],
760795)
761796@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+ ):
763800 """ Tasks with two inputs and a splitter (no combiner)"""
764801 nn = fun_addvar (name = "NA" ).split (splitter = splitter , a = [3 , 5 ], b = [10 , 20 ])
765802
@@ -777,6 +814,21 @@ def test_task_state_2(plugin, splitter, state_splitter, state_rpn, expected):
777814 results = nn .result ()
778815 for i , res in enumerate (expected ):
779816 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+
780832 # checking the output_dir
781833 assert nn .output_dir
782834 for odir in nn .output_dir :
@@ -982,11 +1034,25 @@ def test_task_state_comb_1(plugin):
9821034
9831035 # checking the results
9841036 results = nn .result ()
985-
9861037 # fully combined (no nested list)
9871038 combined_results = [res .output .out for res in results ]
988-
9891039 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+
9901056 # checking the output_dir
9911057 assert nn .output_dir
9921058 for odir in nn .output_dir :
@@ -995,7 +1061,7 @@ def test_task_state_comb_1(plugin):
9951061
9961062@pytest .mark .parametrize (
9971063 "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 " ,
9991065 [
10001066 (
10011067 ("a" , "b" ),
@@ -1006,7 +1072,8 @@ def test_task_state_comb_1(plugin):
10061072 ["NA.a" , "NA.b" ],
10071073 None ,
10081074 [],
1009- [({}, [13 , 25 ])],
1075+ [13 , 25 ],
1076+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
10101077 ),
10111078 (
10121079 ("a" , "b" ),
@@ -1017,7 +1084,8 @@ def test_task_state_comb_1(plugin):
10171084 ["NA.a" , "NA.b" ],
10181085 None ,
10191086 [],
1020- [({}, [13 , 25 ])],
1087+ [13 , 25 ],
1088+ [({"NA.a" : 3 , "NA.b" : 10 }, 13 ), ({"NA.a" : 5 , "NA.b" : 20 }, 25 )],
10211089 ),
10221090 (
10231091 ["a" , "b" ],
@@ -1028,7 +1096,11 @@ def test_task_state_comb_1(plugin):
10281096 ["NA.a" ],
10291097 "NA.b" ,
10301098 ["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+ ],
10321104 ),
10331105 (
10341106 ["a" , "b" ],
@@ -1039,7 +1111,11 @@ def test_task_state_comb_1(plugin):
10391111 ["NA.b" ],
10401112 "NA.a" ,
10411113 ["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+ ],
10431119 ),
10441120 (
10451121 ["a" , "b" ],
@@ -1050,7 +1126,13 @@ def test_task_state_comb_1(plugin):
10501126 ["NA.a" , "NA.b" ],
10511127 None ,
10521128 [],
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+ ],
10541136 ),
10551137 ],
10561138)
@@ -1066,6 +1148,7 @@ def test_task_state_comb_2(
10661148 state_splitter_final ,
10671149 state_rpn_final ,
10681150 expected ,
1151+ expected_val ,
10691152):
10701153 """ Tasks with scalar and outer splitters and partial or full combiners"""
10711154 nn = (
@@ -1080,19 +1163,32 @@ def test_task_state_comb_2(
10801163 assert nn .state .splitter_rpn == state_rpn
10811164 assert nn .state .combiner == state_combiner
10821165
1166+ with Submitter (plugin = plugin ) as sub :
1167+ sub (nn )
1168+
10831169 assert nn .state .splitter_final == state_splitter_final
10841170 assert nn .state .splitter_rpn_final == state_rpn_final
10851171 assert set (nn .state .right_combiner_all ) == set (state_combiner_all )
10861172
1087- with Submitter (plugin = plugin ) as sub :
1088- sub (nn )
1089-
10901173 # checking the results
10911174 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
10921191
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 ]
10961192 # checking the output_dir
10971193 assert nn .output_dir
10981194 for odir in nn .output_dir :
@@ -1130,7 +1226,7 @@ def test_task_state_comb_singl_1(plugin):
11301226
11311227
11321228@pytest .mark .parametrize ("plugin" , Plugins )
1133- def test_task_state_comb_2 (plugin ):
1229+ def test_task_state_comb_3 (plugin ):
11341230 """ task with the simplest splitter, the input is an empty list"""
11351231 nn = fun_addtwo (name = "NA" ).split (splitter = "a" , a = []).combine (combiner = ["a" ])
11361232
0 commit comments