當前位置: 首頁>>代碼示例>>Python>>正文


Python toposort.toposort方法代碼示例

本文整理匯總了Python中toposort.toposort方法的典型用法代碼示例。如果您正苦於以下問題:Python toposort.toposort方法的具體用法?Python toposort.toposort怎麽用?Python toposort.toposort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在toposort的用法示例。


在下文中一共展示了toposort.toposort方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: tf_toposort

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def tf_toposort(ts, within_ops=None):
    all_ops = ge.get_forward_walk_ops(
        [x.op for x in ts], within_ops=within_ops)

    deps = {}
    for op in all_ops:
        for o in op.outputs:
            deps[o] = set(op.inputs)
    sorted_ts = toposort(deps)

    # only keep the tensors from our original list
    ts_sorted_lists = []
    for l in sorted_ts:
        keep = list(set(l).intersection(ts))
        if keep:
            ts_sorted_lists.append(keep)

    return ts_sorted_lists 
開發者ID:openai,項目名稱:glow,代碼行數:20,代碼來源:memory_saving_gradients.py

示例2: tf_toposort

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def tf_toposort(ts, within_ops=None):
    all_ops = ge.get_forward_walk_ops([x.op for x in ts], within_ops=within_ops)

    deps = {}
    for op in all_ops:
        for o in op.outputs:
            deps[o] = set(op.inputs)
    sorted_ts = toposort(deps)

    # only keep the tensors from our original list
    ts_sorted_lists = []
    for l in sorted_ts:
        keep = list(set(l).intersection(ts))
        if keep:
            ts_sorted_lists.append(keep)

    return ts_sorted_lists 
開發者ID:cybertronai,項目名稱:gradient-checkpointing,代碼行數:19,代碼來源:memory_saving_gradients.py

示例3: tf_toposort

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def tf_toposort(ts_inp, within_ops=None):
    """ Tensorflow topological sort """
    all_ops = ge.get_forward_walk_ops([x.op for x in ts_inp], within_ops=within_ops)

    deps = {}
    for tf_op in all_ops:
        for outp in tf_op.outputs:
            deps[outp] = set(tf_op.inputs)
    sorted_ts = toposort(deps)

    # only keep the tensors from our original list
    ts_sorted_lists = []
    for lst in sorted_ts:
        keep = list(set(lst).intersection(ts_inp))
        if keep:
            ts_sorted_lists.append(keep)
    return ts_sorted_lists 
開發者ID:deepfakes,項目名稱:faceswap,代碼行數:19,代碼來源:memory_saving_gradients.py

示例4: test_toposort

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def test_toposort():
  tf.reset_default_graph()
  nodes = util.make_caterpillar_graph(length=2)
  graph = linearize_lib.get_graph()
  initial = list(toposort(graph))[0]
  assert len(initial) == 1
  assert list(initial)[0].name == 'merge2' 
開發者ID:cybertronai,項目名稱:gradient-checkpointing,代碼行數:9,代碼來源:linearize_test.py

示例5: toposort

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def toposort(data):
    return [sorted(list(level)) for level in toposort_.toposort(data)] 
開發者ID:dagster-io,項目名稱:dagster,代碼行數:4,代碼來源:utils.py

示例6: toposort_flatten

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def toposort_flatten(data):
    return [item for level in toposort(data) for item in level] 
開發者ID:dagster-io,項目名稱:dagster,代碼行數:4,代碼來源:utils.py

示例7: get_topological_order_by_tables

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def get_topological_order_by_tables(relationships, tables):
    topsort_input =  __prepare_topsort_input(relationships, tables)
    return list(toposort(topsort_input)) 
開發者ID:TonicAI,項目名稱:condenser,代碼行數:5,代碼來源:topo_orderer.py

示例8: __prepare_topsort_input

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def __prepare_topsort_input(relationships, tables):
    dep_breaks = config_reader.get_dependency_breaks()
    deps = dict()
    for r in relationships:
        p =r['fk_table']
        c =r['target_table']

        #break circ dependency
        dep_break_found = False
        for dep_break in dep_breaks:
            if p == dep_break.fk_table and c == dep_break.target_table:
                dep_break_found = True
                break

        if dep_break_found == True:
            continue

        # toposort ignores self circularities for some reason, but we cannot
        if p == c:
            raise ValueError('Circular dependency, {} depends on itself!'.format(p))

        if tables is not None and len(tables) > 0 and (p not in tables or c not in tables):
            continue

        if p in deps:
            deps[p].add(c)
        else:
            deps[p] = set()
            deps[p].add(c)

    return deps 
開發者ID:TonicAI,項目名稱:condenser,代碼行數:33,代碼來源:topo_orderer.py

示例9: ordered_steps

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def ordered_steps(self):
        dependencies = {
            step.name: step.depends() for step in self.steps()
        }
        try:
            result = list(toposort.toposort(dependencies))
        except toposort.CircularDependencyError as de:
            # remove cirular dependencies caused by synthetic steps
            # (custom steps' dependencies should "win")
            for step_name, step_dependencies in de.data.items():
                step = self.step(step_name)
                if not step.is_synthetic:
                    continue # only patch away synthetic steps' dependencies
                for step_dependency_name in step_dependencies:
                    step_dependency = self.step(step_dependency_name)
                    if step_dependency.is_synthetic:
                        continue # leave dependencies between synthetic steps
                    # patch out dependency from synthetic step to custom step
                    dependencies[step_name].remove(step_dependency_name)
            # try again - if there is still a cyclic dependency, this is probably caused
            # by a user error - so let it propagate
            result = toposort.toposort(dependencies)

        # result contains a generator yielding tuples of step name in the correct execution order.
        # each tuple can/should be parallelised
        return result 
開發者ID:gardener,項目名稱:cc-utils,代碼行數:28,代碼來源:job.py

示例10: _init_from_dict

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def _init_from_dict(self, model_dict):
        """
        Initiate self from a model_dict to make sure attributes such as vars, params are available.

        Creates lists of alphabetically sorted independent vars, dependent vars, sigma vars, and parameters.
        Finally it creates a signature for this model so it can be called nicely. This signature only contains
        independent vars and params, as one would expect.

        :param model_dict: dict of (dependent_var, expression) pairs.
        """
        sort_func = lambda symbol: symbol.name
        self.model_dict = OrderedDict(sorted(model_dict.items(),
                                             key=lambda i: sort_func(i[0])))
        # Everything at the bottom of the toposort is independent, at the top
        # dependent, and the rest interdependent.
        ordered = list(toposort(self.connectivity_mapping))
        independent = sorted(ordered.pop(0), key=sort_func)
        self.dependent_vars = sorted(ordered.pop(-1), key=sort_func)
        self.interdependent_vars = sorted(
            [item for items in ordered for item in items],
            key=sort_func
        )
        # `independent` contains both params and vars, needs to be separated
        self.independent_vars = [s for s in independent if
                                 not isinstance(s, Parameter) and not s in self]
        self.params = [s for s in independent if isinstance(s, Parameter)]

        try:
            assert not any(isinstance(var, Parameter)
                           for var in self.dependent_vars)
            assert not any(isinstance(var, Parameter)
                           for var in self.interdependent_vars)
        except AssertionError:
            raise ModelError('`Parameter`\'s can not feature in the role '
                             'of `Variable`')
        # Make Variable object corresponding to each depedent var.
        self.sigmas = {var: Variable(name='sigma_{}'.format(var.name))
                       for var in self.dependent_vars} 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:40,代碼來源:models.py

示例11: ordered_symbols

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def ordered_symbols(self):
        """
        :return: list of all symbols in this model, topologically sorted so they
            can be evaluated in the correct order.

            Within each group of equal priority symbols, we sort by the order of
            the derivative.
        """
        key_func = lambda s: [isinstance(s, sympy.Derivative),
                           isinstance(s, sympy.Derivative) and s.derivative_count]
        symbols = []
        for symbol in toposort(self.connectivity_mapping):
            symbols.extend(sorted(symbol, key=key_func))

        return symbols 
開發者ID:tBuLi,項目名稱:symfit,代碼行數:17,代碼來源:models.py

示例12: make_graph

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def make_graph(self) -> DFGraph:
        """
        Build the DFGraph given the dependency structure described in the problem
        :return: a DFGraph instance corresponding to your problem description
        """
        # step 1 -- toposort graph and allocate node positions as a dict({0, ..., n} -> UUID)
        edge_list = [(source, dest) for dest, sources in self.arguments.items() for source in sources]
        topo_order = list(reversed([x for st in toposort(edge_to_adj_list(edge_list)) for x in st]))
        topo_order = [v for v in set(self.nodes.values()) - set(topo_order)] + topo_order  # add isolated nodes
        uuid2topo = {uuid: topo_idx for topo_idx, uuid in enumerate(topo_order)}

        # step 2 -- map builder data-structures to node position indexed data-structures
        vertex_list = list(uuid2topo.values())
        cost_cpu = dict((uuid2topo[idx], self.costs_cpu[idx]) for idx in self.costs_cpu.keys())
        cost_ram = dict((uuid2topo[idx], self.costs_ram[idx]) for idx in self.costs_ram.keys())
        arg_list = {uuid2topo[key]: [uuid2topo[arg] for arg in args] for key, args in self.arguments.items()}
        names = {uuid2topo[idx]: name for (name, idx) in self.nodes.items()}
        bwd_node_set = set(uuid2topo[v] for v in self.nodes.values() if v in self.backward_nodes)

        # step 3 -- make DFGraph
        return DFGraph(
            v=vertex_list,
            args=arg_list,
            backward_nodes=bwd_node_set,
            node_names=names,
            cost_cpu=cost_cpu,
            cost_ram=cost_ram,
            cost_ram_parameters=self.parameter_cost,
        ) 
開發者ID:parasj,項目名稱:checkmate,代碼行數:31,代碼來源:graph_builder.py

示例13: topological_order

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def topological_order(self):
        adj_set = {k: set(v) for k, v in self.adj_list.items()}
        topo_sets = list(toposort(adj_set))
        return [x for topo_set in topo_sets for x in topo_set] 
開發者ID:parasj,項目名稱:checkmate,代碼行數:6,代碼來源:dfgraph.py

示例14: topological_order_fwd

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def topological_order_fwd(self):
        adj_set = {k: set(v) for k, v in self.adj_list_fwd.items()}
        topo_sets = list(toposort(adj_set))
        return [x for topo_set in topo_sets for x in topo_set] 
開發者ID:parasj,項目名稱:checkmate,代碼行數:6,代碼來源:dfgraph.py

示例15: _init_consideration_queue_from_graph

# 需要導入模塊: import toposort [as 別名]
# 或者: from toposort import toposort [as 別名]
def _init_consideration_queue_from_graph(self, graph):
        self.dependency_dict, self.removed_dependencies, self.structural_dependencies = graph.prune_feedback_edges()
        self.consideration_queue = list(toposort(self.dependency_dict)) 
開發者ID:PrincetonUniversity,項目名稱:PsyNeuLink,代碼行數:5,代碼來源:scheduler.py


注:本文中的toposort.toposort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。