Skip to content

Commit

Permalink
[Bug Fix] Fix package reliability bug of networkx (dmlc#949)
Browse files Browse the repository at this point in the history
* upd

* fig edgebatch edges

* add test

* trigger

* Update README.md for pytorch PinSage example.

Add noting that the PinSage model example under
example/pytorch/recommendation only work with Python 3.6+
as its dataset loader depends on stanfordnlp package
which work only with Python 3.6+.

* Provid a frame agnostic API to test nn modules on both CPU and CUDA side.

1. make dgl.nn.xxx frame agnostic
2. make test.backend include dgl.nn modules
3. modify test_edge_softmax of test/mxnet/test_nn.py and
    test/pytorch/test_nn.py work on both CPU and GPU

* Fix style

* Delete unused code

* Make agnostic test only related to tests/backend

1. clear all agnostic related code in dgl.nn
2. make test_graph_conv agnostic to cpu/gpu

* Fix code style

* fix

* doc

* Make all test code under tests.mxnet/pytorch.test_nn.py
work on both CPU and GPU.

* Fix syntex

* Remove rand

* Add TAGCN nn.module and example

* Now tagcn can run on CPU.

* Add unitest for TGConv

* Fix style

* For pubmed dataset, using --lr=0.005 can achieve better acc

* Fix style

* Fix some descriptions

* trigger

* Fix doc

* Add nn.TGConv and example

* Fix bug

* Update data in mxnet.tagcn test acc.

* Fix some comments and code

* delete useless code

* Fix namming

* Fix bug

* Fix bug

* Add test for mxnet TAGCov

* Add test code for mxnet TAGCov

* Update some docs

* Fix some code

* Update docs dgl.nn.mxnet

* Update weight init

* Fix

* reproduce the bug

* Fix concurrency bug reported at dmlc#755.
Also make test_shared_mem_store.py more deterministic.

* Update test_shared_mem_store.py

* Update dmlc/core

* networkx >= 2.4 will break our examples

* Update tutorials/requirements

* fix selfloop edges

* upd version
  • Loading branch information
classicsong authored and jermainewang committed Oct 30, 2019
1 parent 98c1448 commit 82499e6
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 15 deletions.
3 changes: 2 additions & 1 deletion examples/mxnet/gat/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import argparse
import networkx as nx
import time
import mxnet as mx
from mxnet import gluon
Expand Down Expand Up @@ -58,7 +59,7 @@ def main(args):
# create graph
g = data.graph
# add self-loop
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
g.add_edges(g.nodes(), g.nodes())
# create model
Expand Down
3 changes: 2 additions & 1 deletion examples/mxnet/gcn/train.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Training GCN model on citation graphs."""
import argparse, time
import numpy as np
import networkx as nx
import mxnet as mx
from mxnet import gluon

Expand Down Expand Up @@ -54,7 +55,7 @@ def main(args):
# create GCN model
g = data.graph
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)
# normalization
Expand Down
3 changes: 2 additions & 1 deletion examples/mxnet/tagcn/train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse, time
import numpy as np
import networkx as nx
import mxnet as mx
from mxnet import gluon

Expand Down Expand Up @@ -52,7 +53,7 @@ def main(args):
g = data.graph
# add self loop
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)

Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/cluster_gcn/cluster_gcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import random

import numpy as np
import networkx as nx
import sklearn.preprocessing
import torch
import torch.nn as nn
Expand Down Expand Up @@ -75,7 +76,7 @@ def main(args):
# create GCN model
g = data.graph
if args.self_loop and not args.dataset.startswith('reddit'):
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
print("adding self-loop edges")
g = DGLGraph(g, readonly=True)
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/dgi/train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse, time
import numpy as np
import networkx as nx
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -49,7 +50,7 @@ def main(args):
g = data.graph
# add self loop
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)
n_edges = g.number_of_edges()
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/gat/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import argparse
import numpy as np
import networkx as nx
import time
import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -76,7 +77,7 @@ def main(args):

g = data.graph
# add self loop
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
g.add_edges(g.nodes(), g.nodes())
n_edges = g.number_of_edges()
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/gcn/gcn_mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
import argparse, time, math
import numpy as np
import networkx as nx
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -153,7 +154,7 @@ def main(args):

# graph preprocess and calculate normalization factor
g = data.graph
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
# add self loop
g.add_edges(g.nodes(), g.nodes())
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/gcn/train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse, time
import numpy as np
import networkx as nx
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -62,7 +63,7 @@ def main(args):
g = data.graph
# add self loop
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)
n_edges = g.number_of_edges()
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/graphsage/graphsage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import abc
import numpy as np
import networkx as nx
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -96,7 +97,7 @@ def main(args):

# graph preprocess and calculate normalization factor
g = data.graph
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
n_edges = g.number_of_edges()

Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/model_zoo/citation_network/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dgl.data import register_data_args, load_data
from models import *
from conf import *
import networkx as nx


def get_model_and_config(name):
Expand Down Expand Up @@ -82,7 +83,7 @@ def main(args):
g = data.graph
# add self loop
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)
n_edges = g.number_of_edges()
Expand Down
5 changes: 3 additions & 2 deletions examples/pytorch/tagcn/train.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse, time
import numpy as np
import networkx as nx
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -60,8 +61,8 @@ def main(args):
g = data.graph
# add self loop
if args.self_loop:
g.remove_edges_from(g.selfloop_edges())
g.add_edges_from(zip(g.nodes(), g.nodes()))
g.remove_edges_from(nx.selfloop_edges(g))
g.add_edges_from(zip(g.nodes(), g.nodes()))
g = DGLGraph(g)
n_edges = g.number_of_edges()

Expand Down
3 changes: 2 additions & 1 deletion tutorials/models/1_gnn/1_gcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ def forward(self, g, features):
# We load the cora dataset using DGL's built-in data module.

from dgl.data import citation_graph as citegrh
import networkx as nx
def load_cora_data():
data = citegrh.load_cora()
features = th.FloatTensor(data.features)
labels = th.LongTensor(data.labels)
mask = th.ByteTensor(data.train_mask)
g = data.graph
# add self loop
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
g.add_edges(g.nodes(), g.nodes())
return g, features, labels, mask
Expand Down
3 changes: 2 additions & 1 deletion tutorials/models/1_gnn/9_gat.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def forward(self, h):

from dgl import DGLGraph
from dgl.data import citation_graph as citegrh
import networkx as nx

def load_cora_data():
data = citegrh.load_cora()
Expand All @@ -282,7 +283,7 @@ def load_cora_data():
mask = torch.ByteTensor(data.train_mask)
g = data.graph
# add self loop
g.remove_edges_from(g.selfloop_edges())
g.remove_edges_from(nx.selfloop_edges(g))
g = DGLGraph(g)
g.add_edges(g.nodes(), g.nodes())
return g, features, labels, mask
Expand Down
2 changes: 1 addition & 1 deletion tutorials/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
networkx
networkx>=2.1
torch
numpy
seaborn
Expand Down

0 comments on commit 82499e6

Please sign in to comment.