def test_sort_keep_orig_order2(self): top = set_as_top(Assembly()) for i in range(11): top.add('c%d'%i, Simple()) # connect two independent strings of comps to test sorting top.connect('c1.c', 'c2.a') top.connect('c2.c', 'c3.a') top.connect('c3.c', 'c4.a') top.connect('c4.c', 'c5.a') top.connect('c6.c', 'c7.a') top.connect('c7.c', 'c8.a') top.connect('c8.c', 'c9.a') top.connect('c9.c', 'c10.a') wfnames = ['c6', 'c7', 'c8', 'c9', 'c10', 'c1', 'c2', 'c3', 'c4', 'c5'] top.driver.workflow.add(wfnames) top._setup() names = gsort(top.driver.workflow._reduced_graph.component_graph(), wfnames) self.assertEqual(names, wfnames) top.driver.workflow.clear() wfnames = ['c6', 'c1', 'c7', 'c2', 'c8', 'c3', 'c9', 'c4', 'c10', 'c5'] top.driver.workflow.add(wfnames) top._setup() names = gsort(top.driver.workflow._reduced_graph.component_graph(), wfnames) self.assertEqual(names, wfnames)
def compute_ordering(self, cgraph): """Given a component graph, each driver can determine its iteration set and the ordering of its workflow. """ cgraph = cgraph.subgraph(self._full_iter_set) # call compute_ordering on all subdrivers for name in self._iter_set: obj = getattr(self.parent, name) if has_interface(obj, IDriver): obj.compute_ordering(cgraph) self._collapse_subdrivers(cgraph) # now figure out the order of our iter_set self._ordering = self.workflow._explicit_names + \ [n for n in self._iter_set if n not in self.workflow._explicit_names] # remove any nodes that got collapsed into subdrivers self._ordering = [n for n in self._ordering if n in cgraph] self._ordering = gsort(cgraph, self._ordering) self.workflow._ordering = self._ordering
def _get_collapsed_graph(self): """Get a dependency graph with only our workflow components in it, with additional edges added to it from sub-workflows of any Driver components in our workflow, and from any ExprEvaluators in any components in our workflow. """ if self._collapsed_graph: return self._collapsed_graph scope = self.scope graph = scope._depgraph # find all of the incoming and outgoing edges to/from all of the # components in each driver's iteration set so we can add edges to/from # the driver in our collapsed graph comps = self.get_components(full=True) cnames = set([c.name for c in comps]) graph_with_subs = graph.component_graph() collapsed_graph = graph_with_subs.subgraph(cnames) for comp in comps: if has_interface(comp, IDriver): comp._collapse_subdrivers(collapsed_graph) fnames = [n for n in self._fullnames if n in collapsed_graph] self._fullnames = gsort(collapsed_graph, fnames) self._collapsed_graph = collapsed_graph return self._collapsed_graph
def test_sorting(self): cgraph = self.dep.component_graph() order = ['C', 'D', 'B', 'A'] neworder = gsort(cgraph, order) self.assertEqual(neworder, ['A', 'B', 'C', 'D'])
def test_sorting(self): cgraph = self.dep.component_graph() order = ['C','D','B','A'] neworder = gsort(cgraph, order) self.assertEqual(neworder, ['A','B','C','D'])