mirror of
https://github.com/wassname/ray.git
synced 2026-06-28 22:03:57 +08:00
ba56b08474
* Reintroduce passing arguments by value to remote functions. * Check size of arguments passed by value. * Fix computation graph visualization.
35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
# Utilities to deal with computation graphs
|
|
|
|
import graphviz
|
|
|
|
def graph_to_graphviz(computation_graph):
|
|
"""
|
|
Convert the computation graph to graphviz format.
|
|
|
|
Args:
|
|
computation_graph [graph_pb2.CompGraph]: protocol buffer description of
|
|
the computation graph
|
|
|
|
Returns:
|
|
Graphviz description of the computation graph
|
|
"""
|
|
dot = graphviz.Digraph(format="pdf")
|
|
dot.node("op-root", shape="box")
|
|
for (i, op) in enumerate(computation_graph.operation):
|
|
if op.HasField("task"):
|
|
dot.node("op" + str(i), shape="box", label=str(i) + "\n" + op.task.name.split(".")[-1])
|
|
for res in op.task.result:
|
|
dot.edge("op" + str(i), str(res))
|
|
elif op.HasField("put"):
|
|
dot.node("op" + str(i), shape="box", label=str(i) + "\n" + "put")
|
|
dot.edge("op" + str(i), str(op.put.objectid))
|
|
elif op.HasField("get"):
|
|
dot.node("op" + str(i), shape="box", label=str(i) + "\n" + "get")
|
|
creator_operationid = op.creator_operationid if op.creator_operationid != 2 ** 64 - 1 else "-root"
|
|
dot.edge("op" + str(creator_operationid), "op" + str(i), style="dotted", constraint="false")
|
|
for arg in op.task.arg:
|
|
if len(arg.serialized_arg) == 0:
|
|
dot.node(str(arg.objectid))
|
|
dot.edge(str(arg.objectid), "op" + str(i))
|
|
return dot
|