'Convert the graph to DOT format.
Arguments:
fh (IO): A file, or a file-like object to write the graph to.
formatter (celery.utils.graph.GraphFormatter): Custom graph
formatter to use.'

def to_dot(self, fh, formatter=None):

    seen = set()
    draw = (formatter or self.formatter)
    def P(s):
        print(bytes_to_str(s), file=fh)
    def if_not_seen(fun, obj):
        if (draw.label(obj) not in seen):
            P(fun(obj))
            seen.add(draw.label(obj))
    P(draw.head())
    for (obj, adjacent) in items(self):
        if (not adjacent):
            if_not_seen(draw.terminal_node, obj)
        for req in adjacent:
            if_not_seen(draw.node, obj)
            P(draw.edge(obj, req))
    P(draw.tail())
