def output_graph( self, file_name: Union[str, Path], base_only: bool = False, dpi: Optional[int] = None, ) -> None: """Write the type graph to a file. Args: file_name: the file to save the output to base_only: if True, plot the graph without relation mapping edges dpi: set the dpi of the output image """ from visions.utils.graph import output_graph if base_only: graph = self.base_graph.copy() else: graph = self.relation_graph.copy() graph.graph["node"] = {"shape": "box", "color": "red"} if dpi is not None: graph.graph["graph"] = {"dpi": dpi} output_graph(graph, file_name)
def plot(self, file_name, type_specific=None): """ Args: file_name: type_specific: Returns: """ G = self.typeset.base_graph.copy() G.graph["node"] = {"shape": "box", "color": "red"} included_nodes = G.nodes if type_specific is not None: included_nodes = nx.ancestors(G, type_specific) included_nodes.add(type_specific) G.remove_nodes_from(G.nodes - included_nodes) G.add_node("summary", shape="note") for base_type, summary_ops in self.summary_ops.items(): if len(summary_ops) > 0 and base_type in included_nodes: G.add_edge( str(base_type), "summary", label="\n".join([str(op.__name__) for op in summary_ops]), ) output_graph(G, file_name)
def output_graph(self, file_name: str, base_only: bool = False) -> None: """Write the type graph to a file. Args: file_name: the file to save the output to base_only: if True, plot the graph without relation mapping edges """ if base_only: graph = self.base_graph.copy() else: graph = self.relation_graph.copy() graph.graph["node"] = {"shape": "box", "color": "red"} output_graph(graph, file_name)