usergraphtheory's picture
Sync from erdostack/bench at a7805c45d77258d316383c92bdc9f472498d255f (part 48)
187416f verified
Raw History Blame Contribute Delete
474 Bytes
"""Read data/programme.json back into a graph."""
import json
from pathlib import Path
import networkx as nx
from .build import OUT
def load(path=OUT):
raw = json.loads(Path(path).read_text(encoding="utf-8"))
G = nx.DiGraph()
for node in raw["nodes"]:
attrs = dict(node)
G.add_node(attrs.pop("id"), **attrs)
for edge in raw["edges"]:
attrs = dict(edge)
G.add_edge(attrs.pop("from"), attrs.pop("to"), **attrs)
return G