def from_agraph(A,create_using=None):
    if create_using is None:
        if A.is_directed():
            if A.is_strict():
                create_using=nx.DiGraph()
            else:
                create_using=nx.MultiDiGraph()
        else:
            if A.is_strict():
                create_using=nx.Graph()
            else:
                create_using=nx.MultiGraph()

    # assign defaults
    N=nx.empty_graph(0,create_using)
    N.name=''
    if A.name is not None:
        N.name=A.name

    # add nodes, attributes to N.node_attr
    for n in A.nodes():
        str_attr=dict((str(k),v) for k,v in n.attr.items())
        N.add_node(str(n),**str_attr)

    # add edges, assign edge data as dictionary of attributes
    for e in A.edges():
        u,v=str(e[0]),str(e[1])
        attr=dict(e.attr)
        str_attr=dict((str(k),v) for k,v in attr.items())
        if not N.is_multigraph():
            if e.name is not None:
                str_attr['key']=e.name
            N.add_edge(u,v,**str_attr)
        else:
            N.add_edge(u,v,key=e.name,**str_attr)

    # add default attributes for graph, nodes, and edges
    # hang them on N.graph_attr
    N.graph['graph']=dict(A.graph_attr)
    N.graph['node']=dict(A.node_attr)
    N.graph['edge']=dict(A.edge_attr)
    return N
Return a NetworkX Graph or DiGraph from a PyGraphviz graph.
dataset/ETHPy150Open gkno/gkno_launcher/src/networkx/drawing/nx_agraph.py/from_agraph