Skip to content

Commit 4bb0f08

Browse files
authored
fix(core): fix workflow graph generation and CompositePlan view (#2436)
1 parent 3a40e83 commit 4bb0f08

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

renku/core/commands/view_model/composite_plan.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from renku.core.models.workflow.composite_plan import CompositePlan
2323
from renku.core.models.workflow.parameter import ParameterLink, ParameterMapping
24+
from renku.core.models.workflow.plan import AbstractPlan
2425

2526

2627
class ParameterMappingViewModel:
@@ -51,9 +52,20 @@ def __init__(self, source: str, sinks: List[str]):
5152
self.sinks = sinks
5253

5354
@classmethod
54-
def from_link(cls, link: ParameterLink):
55+
def from_link(cls, link: ParameterLink, plan: AbstractPlan):
5556
"""Create view model from ``ParameterLink``."""
56-
return cls(source=link.source.name, sinks=[s.name for s in link.sinks])
57+
source_path = plan.get_parameter_path(link.source)
58+
source_path.append(link.source)
59+
source_path = ".".join(p.name for p in source_path[1:])
60+
61+
sinks = []
62+
63+
for sink in link.sinks:
64+
sink_path = plan.get_parameter_path(sink)
65+
sink_path.append(sink)
66+
sink_path = ".".join(p.name for p in sink_path[1:])
67+
sinks.append(sink_path)
68+
return cls(source=source_path, sinks=sinks)
5769

5870

5971
class StepViewModel:
@@ -92,6 +104,6 @@ def from_composite_plan(cls, plan: CompositePlan):
92104
name=plan.name,
93105
description=plan.description,
94106
mappings=[ParameterMappingViewModel.from_mapping(mapping) for mapping in plan.mappings],
95-
links=[ParameterLinkViewModel.from_link(link) for link in plan.links],
107+
links=[ParameterLinkViewModel.from_link(link, plan) for link in plan.links],
96108
steps=[StepViewModel(id=s.id, name=s.name) for s in plan.plans],
97109
)

renku/core/management/workflow/activity.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,21 @@ def connect_nodes_by_execution_order():
155155

156156
def create_order_among_activities(activities: Set[Activity], path):
157157
for a, b in itertools.combinations(activities, 2):
158-
if networkx.has_path(graph, a, b) or networkx.has_path(graph, b, a):
158+
if (networkx.has_path(graph, a, b) and path in overridden_activities[a]) or (
159+
networkx.has_path(graph, b, a) and path in overridden_activities[b]
160+
):
159161
continue
160162

161163
# NOTE: More recent activity should be executed after the other one
162164
# NOTE: This won't introduce a cycle in the graph because there is no other path between the two nodes
163165
comparison = a.compare_to(b)
164166
if comparison < 0:
165-
graph.add_edge(a, b)
167+
if not networkx.has_path(graph, a, b):
168+
graph.add_edge(a, b)
166169
overridden_activities[a].add(path)
167170
elif comparison > 0:
168-
graph.add_edge(b, a)
171+
if not networkx.has_path(graph, b, a):
172+
graph.add_edge(b, a)
169173
overridden_activities[b].add(path)
170174
else:
171175
raise ValueError(f"Cannot create an order between activities {a.id} and {b.id}")

renku/core/models/workflow/composite_plan.py

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ def find_parameter(self, parameter: CommandParameterBase):
211211

212212
return False
213213

214+
def get_parameter_path(self, parameter: CommandParameterBase):
215+
"""Get the path to a parameter inside this plan."""
216+
if parameter in self.mappings:
217+
return [self]
218+
219+
for plan in self.plans:
220+
path = plan.get_parameter_path(parameter)
221+
if path:
222+
return [self] + path
223+
224+
return None
225+
214226
def get_parameter_by_id(self, parameter_id: str) -> CommandParameterBase:
215227
"""Get a parameter on this plan by id."""
216228
mapping = next((p for p in self.mappings if parameter_id == p.id), None)

renku/core/models/workflow/plan.py

+7
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ def find_parameter(self, parameter: CommandParameterBase) -> bool:
213213
"""Find if a parameter exists on this plan."""
214214
return any(parameter.id == p.id for p in self.inputs + self.outputs + self.parameters)
215215

216+
def get_parameter_path(self, parameter: CommandParameterBase):
217+
"""Get the path to a parameter inside this plan."""
218+
if self.find_parameter(parameter):
219+
return [self]
220+
221+
return None
222+
216223
def get_parameter_by_id(self, parameter_id: str) -> CommandParameterBase:
217224
"""Get a parameter on this plan by id."""
218225
return next((p for p in self.inputs + self.outputs + self.parameters if parameter_id == p.id), None)

0 commit comments

Comments
 (0)