MCPcopy
hub / github.com/dmlc/dgl / _read_graph

Function _read_graph

tools/verify_partitions.py:37–134  ·  view source on GitHub ↗

Read a DGL Graph object from storage using metadata schema, which is a json object describing the DGL graph on disk. Parameters: ----------- schema : json object json object describing the input graph to read from the disk Returns: -------- DGL Graph Object :

(schema)

Source from the content-addressed store, hash-verified

35
36
37def _read_graph(schema):
38 """Read a DGL Graph object from storage using metadata schema, which is
39 a json object describing the DGL graph on disk.
40
41 Parameters:
42 -----------
43 schema : json object
44 json object describing the input graph to read from the disk
45
46 Returns:
47 --------
48 DGL Graph Object :
49 DGL Graph object is created which is read from the disk storage.
50 """
51 edges = {}
52 edge_types = schema[constants.STR_EDGE_TYPE]
53 for etype in edge_types:
54 efiles = schema[constants.STR_EDGES][etype][constants.STR_DATA]
55 src = []
56 dst = []
57 for fname in efiles:
58 if (
59 schema[constants.STR_EDGES][etype][constants.STR_FORMAT][
60 constants.STR_NAME
61 ]
62 == constants.STR_CSV
63 ):
64 data = read_file(fname, constants.STR_CSV)
65 elif (
66 schema[constants.STR_EDGES][etype][constants.STR_FORMAT][
67 constants.STR_NAME
68 ]
69 == constants.STR_PARQUET
70 ):
71 data = read_file(fname)
72 else:
73 raise ValueError(
74 f"Unknown edge format for {etype} - {schema[constants.STR_EDGES][etype][constants.STR_FORMAT]}"
75 )
76
77 src.append(data[:, 0])
78 dst.append(data[:, 1])
79 src = np.concatenate(src)
80 dst = np.concatenate(dst)
81 edges[_etype_str_to_tuple(etype)] = (src, dst)
82
83 g = dgl.heterograph(edges)
84 # g = dgl.to_homogeneous(g)
85
86 g.ndata["orig_id"] = g.ndata[dgl.NID]
87 g.edata["orig_id"] = g.edata[dgl.EID]
88
89 # read features here.
90 for ntype in schema[constants.STR_NODE_TYPE]:
91 if ntype in schema[constants.STR_NODE_DATA]:
92 for featname, featdata in schema[constants.STR_NODE_DATA][
93 ntype
94 ].items():

Callers 1

_validate_resultsFunction · 0.85

Calls 8

read_fileFunction · 0.90
_etype_str_to_tupleFunction · 0.90
appendMethod · 0.80
infoMethod · 0.80
itemsMethod · 0.45
num_nodesMethod · 0.45
num_edgesMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected