MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / draw

Method draw

python/paddle/base/framework.py:5917–5966  ·  view source on GitHub ↗

Draw the graph. If `dot` command is installed, the drawn graph will be saved as pdf file type, otherwise dot file type is used. Args: save_path(str): the save path of drawn graph. name(str): the name of drawn graph. marked_nodes(set(IrNod

(self, save_path, name, marked_nodes=None, remove_ctr_var=True)

Source from the content-addressed store, hash-verified

5915 return wrapped_adj_list
5916
5917 def draw(self, save_path, name, marked_nodes=None, remove_ctr_var=True):
5918 """
5919 Draw the graph. If `dot` command is installed, the drawn graph
5920 will be saved as pdf file type, otherwise dot file type is used.
5921
5922 Args:
5923 save_path(str): the save path of drawn graph.
5924 name(str): the name of drawn graph.
5925 marked_nodes(set(IrNode)): nodes that are needed to be marked.
5926 Default value is None.
5927 remove_ctr_var(bool): If it is set True, all control variable nodes
5928 in the graph will be removed. Default value is True.
5929 """
5930
5931 def _convert_to_pdf(dot_file_path):
5932 pdf_save_path = os.path.splitext(dot_file_path)[0] + ".pdf"
5933 exited_code = subprocess.call(
5934 ["dot", "-Tpdf", dot_file_path, "-o", pdf_save_path]
5935 )
5936 if exited_code != 0:
5937 print("The dot command is needed for creating pdf files.")
5938 print(f"The {dot_file_path} is saved as the dot filetype.")
5939
5940 remove_ctr_vars = set()
5941 if remove_ctr_var:
5942 for node in self.all_var_nodes():
5943 if node.is_ctrl_var():
5944 remove_ctr_vars.add(node)
5945 self.safe_remove_nodes(remove_ctr_vars)
5946 print(f"Total ops num = {len(self.all_op_nodes())}.")
5947
5948 if marked_nodes is not None:
5949 if not isinstance(marked_nodes, set):
5950 if isinstance(marked_nodes, Iterable):
5951 marked_nodes = set(marked_nodes)
5952 else:
5953 marked_nodes = {marked_nodes}
5954 marked_nodes = {n.node for n in marked_nodes}
5955 remove_ctr_vars = {n.node for n in remove_ctr_vars}
5956 marked_nodes = marked_nodes - remove_ctr_vars
5957 if self.graph.has("__graphviz__marked_node__"):
5958 self.graph.erase("__graphviz__marked_node__")
5959 self.graph.set("__graphviz__marked_node__", marked_nodes)
5960 if not os.path.exists(save_path):
5961 os.makedirs(save_path)
5962 viz_dot_path = os.path.join(save_path, name) + ".dot"
5963 viz_pass = core.get_pass("graph_viz_pass")
5964 viz_pass.set("graph_viz_path", viz_dot_path)
5965 viz_pass.apply(self.graph)
5966 _convert_to_pdf(viz_dot_path)
5967
5968 def to_program(self):
5969 """

Callers 6

quant_awareFunction · 0.95
_predictMethod · 0.95
_predictMethod · 0.95
generate_dot_for_modelFunction · 0.95
_apply_passMethod · 0.80
_apply_passFunction · 0.80

Calls 13

all_var_nodesMethod · 0.95
safe_remove_nodesMethod · 0.95
all_op_nodesMethod · 0.95
setClass · 0.85
is_ctrl_varMethod · 0.80
existsMethod · 0.80
printFunction · 0.50
addMethod · 0.45
hasMethod · 0.45
eraseMethod · 0.45
setMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected