-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathexample.py
More file actions
73 lines (58 loc) · 1.99 KB
/
example.py
File metadata and controls
73 lines (58 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pickle
"""
NOTE: VERY IMPORTANT
--------------------
Do not use "import torch"
Instead, use "from dgll import backend as F"
In your code, use "F.tensor" or any PyTorch functions using "F."
PyTorch is already included as a backend in the dgll library to ensure consistency and the possibily of multiple backends.
"""
from dgll import backend as F
# Load the graph
# You can download cora.graph and products.graph from the server
# Cora
g = pickle.load(open("dgll/dataset/cora.graph", "rb"))
# ogbn-products
# g = pickle.load(open("products.graph", "rb"))
# A set of node IDs
nodes = F.tensor([0, 2, 5, 6, 9, 23])
# Get the neighbors of the nodes
neighbors = g.get_neighbors(nodes)
# Get Induced Subgraph
induced_subgraph = g.get_induced_subgraph(nodes)
# Get the labels of the nodes
labels = g.get_labels(nodes)
# Get the features of the nodes
features = g.get_features(nodes)
# Get the nodes that are in the training subset
train_nodes = g.get_train_nodes()
# Get the nodes that are in the validation subset
validation_nodes = g.get_validation_nodes()
# Get the nodes that are in the test subset
test_nodes = g.get_test_nodes()
# Print the results
print(neighbors)
print(induced_subgraph)
print(labels)
print(features)
print(train_nodes)
print(validation_nodes)
print(test_nodes)
# Output
# [[809, 1217, 1218], [], [2, 114, 516, 541], [88, 91, 200, 226, 728], [2, 89, 121, 182, 208], [505, 582]]
# tensor([[0, 0, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0],
# [0, 1, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0],
# [0, 1, 0, 0, 0, 0],
# [0, 0, 0, 0, 0, 0]], dtype=torch.int32)
# tensor([1, 4, 4, 6, 4, 4])
# tensor([[0, 0, 0, ..., 0, 0, 0],
# [0, 0, 0, ..., 0, 0, 0],
# [0, 0, 0, ..., 0, 0, 0],
# [0, 0, 0, ..., 0, 0, 0],
# [0, 0, 0, ..., 0, 0, 0],
# [0, 0, 0, ..., 0, 0, 0]], dtype=torch.int32)
# tensor([ 0, 9, 10, ..., 2701, 2704, 2706])
# tensor([ 2, 7, 8, ..., 2697, 2702, 2707])
# tensor([ 1, 3, 4, ..., 2700, 2703, 2705])