当前位置: 首页>>代码示例>>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;未经允许,请勿转载。