def diff(network_config_1, network_config_2, render_to=None, dpi=800, lazy=False, merge_blocks=[]): if not isinstance(network_config_1, list): graph_list1 = dsl_parser.parse(network_config_1, lazy=lazy) else: graph_list1 = network_config_1 if not isinstance(network_config_2, list): graph_list2 = dsl_parser.parse(network_config_2, lazy=lazy) else: graph_list2 = network_config_2 tree_full1 = param_count.ParamCount(graph_list1).annotate_tree() tree_full2 = param_count.ParamCount(graph_list2).annotate_tree() operations = [] cost = 0 graph_list1_block = [] graph_list2_block = [] for block in merge_blocks: graph_list1_block += list(filter(lambda x: x["meta"]["block"]==block, graph_list1)) graph_list2_block += list(filter(lambda x: x["meta"]["block"]==block, graph_list2)) _cost, _operations = _diff_graph_list(graph_list1_block, graph_list2_block, tree_full1, tree_full2) cost += _cost operations += _operations for block in registry.BLOCKS: if block in merge_blocks: continue graph_list1_block = list(filter(lambda x: x["meta"]["block"]==block, graph_list1)) graph_list2_block = list(filter(lambda x: x["meta"]["block"]==block, graph_list2)) _cost, _operations = _diff_graph_list(graph_list1_block, graph_list2_block, tree_full1, tree_full2) cost += _cost operations += _operations if render_to is not None: print("Done computing diff. Rendering image") annotation = annotate_ops(operations) img1 = core.draw(tree_full1, None, annotation[1], dpi=dpi) img2 = core.draw(tree_full2, None, annotation[2], dpi=dpi) fig, axs = plt.subplots(1, 2, dpi=dpi) axs[0].imshow(img1) axs[0].axis("off") axs[1].imshow(img2) axs[1].axis("off") fig.tight_layout() if render_to != "": fig.savefig(render_to, dpi="figure") print("Diff images written to: %s" % render_to) else: print("Diff images rendered to screen") plt.show() return cost, operations
def __init__(self, recipe_name): self.name = recipe_name if self.name != "root" and self.name not in registry.BLOCKS: self.config_path = os.path.join(const.COMPONENT_BASE_PATH, self.name + ".yml") self.recipe = dsl_parser.parse(self.config_path, return_dict=False, lazy=True) else: self.recipe = None
def dist(network_config_1, network_config_2, render_to=None, exclude_types=[], dpi=800, lazy=False): graph_list1 = dsl_parser.parse(network_config_1, lazy=lazy) graph_list2 = dsl_parser.parse(network_config_2, lazy=lazy) # Do not include dimensionality in dist # graph1 = dsl_parser.list_to_graph(graph_list1) # graph2 = dsl_parser.list_to_graph(graph_list2) # tree1 = core.alex_graph_to_tree(graph1, exclude_types=exclude_types) # tree2 = core.alex_graph_to_tree(graph2, exclude_types=exclude_types) # Include dimensionality in dist tree1 = param_count.ParamCount(graph_list1).annotate_tree() tree2 = param_count.ParamCount(graph_list2).annotate_tree() cost, operations = _dist_graph_list(tree1, tree2, exclude_types=exclude_types, render_to=render_to, dpi=dpi) return cost, operations
def __init__(self, config_path, exclude_types=[], naive=True, lazy=False): if isinstance(config_path, (str, dict)): self.config_path = config_path self.components_list = dsl_parser.parse(self.config_path, lazy=lazy) elif isinstance(config_path, list): self.components_list = deepcopy(config_path) graph = dsl_parser.list_to_graph(self.components_list) self.tree = core.alex_graph_to_tree(graph, exclude_types=exclude_types, naive=naive) self.components = dsl_parser.list_to_dict(self.components_list) self.passes = [None] self.anno_name = "unnamed annotation"
def test_list_to_graph(self): glist = dsl_parser.parse(self.config, return_dict=False) graph = dsl_parser.list_to_graph(glist)