@@ -794,16 +794,25 @@ def _get_predecessors(workflow, node):
794
794
# recursive method to get predecessors of a given node
795
795
pred = []
796
796
797
- for pnode in workflow .graph .predecessors (node ):
797
+ parents = list (workflow .graph .predecessors (node ))
798
+ for pnode in parents :
798
799
pred = _get_predecessors (workflow , pnode )
799
800
cxns = {x [0 ]: x [2 ]
800
801
for x in workflow .graph .get_edge_data (
801
802
pnode , node )['connections' ].connections }
802
803
data = [pnode , node , cxns ]
803
804
if pred is None :
804
- pred = [data ]
805
- else :
806
- pred .append (data )
805
+ pred = []
806
+
807
+ # making sure that if the node has extra parents they are
808
+ # generated first
809
+ parents .remove (pnode )
810
+ if parents :
811
+ for pnode in parents :
812
+ # [-1] just adding the parent and not its ancestors
813
+ pred .extend ([_get_predecessors (workflow , pnode )[- 1 ]])
814
+
815
+ pred .append (data )
807
816
return pred
808
817
809
818
# Note: we are going to use the final BIOMs to figure out which
@@ -894,8 +903,9 @@ def _get_predecessors(workflow, node):
894
903
# let's just keep one, let's give it preference to the one with the
895
904
# most total_conditions_satisfied
896
905
_ , wk = sorted (workflows , key = lambda x : x [0 ], reverse = True )[0 ]
906
+ GH = wk .graph
897
907
missing_artifacts = dict ()
898
- for node , degree in wk . graph .out_degree ():
908
+ for node , degree in GH .out_degree ():
899
909
if degree != 0 :
900
910
continue
901
911
mscheme = _get_node_info (wk , node )
@@ -920,7 +930,7 @@ def _get_predecessors(workflow, node):
920
930
icxns = {y : x for x , y in cxns .items ()}
921
931
reqp = {x : icxns [y [1 ][0 ]]
922
932
for x , y in cdp_cmd .required_parameters .items ()}
923
- cmds_to_create .append ([cdp_cmd , params , reqp ])
933
+ cmds_to_create .append ([cdp , cdp_cmd , params , reqp ])
924
934
925
935
info = _get_node_info (wk , pnode )
926
936
if info in merging_schemes :
@@ -942,7 +952,7 @@ def _get_predecessors(workflow, node):
942
952
'be applied' )
943
953
reqp [x ] = wkartifact_type
944
954
945
- cmds_to_create .append ([pdp_cmd , params , reqp ])
955
+ cmds_to_create .append ([pdp , pdp_cmd , params , reqp ])
946
956
947
957
if starting_job is not None :
948
958
init_artifacts = {
@@ -953,14 +963,16 @@ def _get_predecessors(workflow, node):
953
963
cmds_to_create .reverse ()
954
964
current_job = None
955
965
loop_starting_job = starting_job
956
- for i , (cmd , params , rp ) in enumerate (cmds_to_create ):
966
+ previous_dps = dict ()
967
+ for i , (dp , cmd , params , rp ) in enumerate (cmds_to_create ):
957
968
if loop_starting_job is not None :
958
969
previous_job = loop_starting_job
959
970
loop_starting_job = None
960
971
else :
961
972
previous_job = current_job
973
+
974
+ req_params = dict ()
962
975
if previous_job is None :
963
- req_params = dict ()
964
976
for iname , dname in rp .items ():
965
977
if dname not in init_artifacts :
966
978
msg = (f'Missing Artifact type: "{ dname } " in '
@@ -970,12 +982,35 @@ def _get_predecessors(workflow, node):
970
982
# raises option c.
971
983
raise ValueError (msg )
972
984
req_params [iname ] = init_artifacts [dname ]
985
+ if len (dp .command .required_parameters ) > 1 :
986
+ for pn in GH .predecessors (node ):
987
+ info = _get_node_info (wk , pn )
988
+ n , cnx , _ = GH .get_edge_data (
989
+ pn , node )['connections' ].connections [0 ]
990
+ if info not in merging_schemes or \
991
+ n not in merging_schemes [info ]:
992
+ msg = ('This workflow contains a step with '
993
+ 'multiple inputs so it cannot be '
994
+ 'completed automatically, please add '
995
+ 'the commands by hand.' )
996
+ raise ValueError (msg )
997
+ req_params [cnx ] = merging_schemes [info ][n ]
973
998
else :
974
- req_params = dict ()
975
- connections = dict ()
976
- for iname , dname in rp .items ():
977
- req_params [iname ] = f'{ previous_job .id } { dname } '
978
- connections [dname ] = iname
999
+ if len (dp .command .required_parameters ) == 1 :
1000
+ cxns = dict ()
1001
+ for iname , dname in rp .items ():
1002
+ req_params [iname ] = f'{ previous_job .id } { dname } '
1003
+ cxns [dname ] = iname
1004
+ connections = {previous_job : cxns }
1005
+ else :
1006
+ connections = dict ()
1007
+ for pn in GH .predecessors (node ):
1008
+ pndp = pn .default_parameter
1009
+ n , cnx , _ = GH .get_edge_data (
1010
+ pn , node )['connections' ].connections [0 ]
1011
+ _job = previous_dps [pndp .id ]
1012
+ req_params [cnx ] = f'{ _job .id } { n } '
1013
+ connections [_job ] = {n : cnx }
979
1014
params .update (req_params )
980
1015
job_params = qdb .software .Parameters .load (
981
1016
cmd , values_dict = params )
@@ -997,8 +1032,9 @@ def _get_predecessors(workflow, node):
997
1032
else :
998
1033
current_job = workflow .add (
999
1034
job_params , req_params = req_params ,
1000
- connections = { previous_job : connections } )
1035
+ connections = connections )
1001
1036
previous_jobs [current_job ] = params
1037
+ previous_dps [dp .id ] = current_job
1002
1038
1003
1039
return workflow
1004
1040
0 commit comments