Different from GetPydotGraph, hide all blob nodes and only show op nodes. If minimal_dependency is set as well, for each op, we will only draw the edges to the minimal necessary ancestors. For example, if op c depends on op a and b, and op b depends on a, then only the edge b->c will be
(
operators_or_net,
name=None,
rankdir='LR',
minimal_dependency=False,
op_node_producer=None,
)
| 132 | |
| 133 | |
| 134 | def GetPydotGraphMinimal( |
| 135 | operators_or_net, |
| 136 | name=None, |
| 137 | rankdir='LR', |
| 138 | minimal_dependency=False, |
| 139 | op_node_producer=None, |
| 140 | ): |
| 141 | """Different from GetPydotGraph, hide all blob nodes and only show op nodes. |
| 142 | |
| 143 | If minimal_dependency is set as well, for each op, we will only draw the |
| 144 | edges to the minimal necessary ancestors. For example, if op c depends on |
| 145 | op a and b, and op b depends on a, then only the edge b->c will be drawn |
| 146 | because a->c will be implied. |
| 147 | """ |
| 148 | if op_node_producer is None: |
| 149 | op_node_producer = GetOpNodeProducer(False, **OP_STYLE) |
| 150 | operators, name = _rectify_operator_and_name(operators_or_net, name) |
| 151 | graph = pydot.Dot(name, rankdir=rankdir) |
| 152 | # blob_parents maps each blob name to its generating op. |
| 153 | blob_parents = {} |
| 154 | # op_ancestry records the ancestors of each op. |
| 155 | op_ancestry = defaultdict(set) |
| 156 | for op_id, op in enumerate(operators): |
| 157 | op_node = op_node_producer(op, op_id) |
| 158 | graph.add_node(op_node) |
| 159 | # Get parents, and set up op ancestry. |
| 160 | parents = [ |
| 161 | blob_parents[input_name] for input_name in op.input |
| 162 | if input_name in blob_parents |
| 163 | ] |
| 164 | op_ancestry[op_node].update(parents) |
| 165 | for node in parents: |
| 166 | op_ancestry[op_node].update(op_ancestry[node]) |
| 167 | if minimal_dependency: |
| 168 | # only add nodes that do not have transitive ancestry |
| 169 | for node in parents: |
| 170 | if all( |
| 171 | [node not in op_ancestry[other_node] |
| 172 | for other_node in parents] |
| 173 | ): |
| 174 | graph.add_edge(pydot.Edge(node, op_node)) |
| 175 | else: |
| 176 | # Add all parents to the graph. |
| 177 | for node in parents: |
| 178 | graph.add_edge(pydot.Edge(node, op_node)) |
| 179 | # Update blob_parents to reflect that this op created the blobs. |
| 180 | for output_name in op.output: |
| 181 | blob_parents[output_name] = op_node |
| 182 | return graph |
| 183 | |
| 184 | |
| 185 | def GetOperatorMapForPlan(plan_def): |
no test coverage detected
searching dependent graphs…