dmlc / dgl

Python package built to ease deep learning on graph, on top of existing DL frameworks.
http://dgl.ai
Apache License 2.0
13.55k stars 3.01k forks source link

dgl.sampling.sample_neighbors return zero or less edges when setting excluded_edges #4778

Open xansar opened 2 years ago

xansar commented 2 years ago

🐛 Bug

when setting excluded_edges, this function will return a graph with edges less than fanout.

To Reproduce

Steps to reproduce the behavior:

  1. create a graph u1 = torch.tensor([0, 0, 1, 1, 2, 3]) u2 = torch.tensor([1, 2, 3, 4, 5, 4]) g = dgl.graph((u1, u2), num_nodes=6) g.all_edges(form='all')
  2. sample with out excluded_edges sg = dgl.sampling.sample_neighbors(g, nodes=[1], fanout=2, replace=True, edge_dir='out') sg.edges(order='eid'), sg.edata[dgl.EID], sg.num_edges() ((tensor([1, 1]), tensor([4, 4])), tensor([3, 3]), 2)
  3. sample with excluded_edges A bug will occur, and sometimes this function will return a graph without edges: sg = dgl.sampling.sample_neighbors(g, nodes=[1], fanout=2, replace=True, edge_dir='out', exclude_edges=[3]) sg.edges(order='eid'), sg.edata[dgl.EID], sg.num_edges() ((tensor([], dtype=torch.int64), tensor([], dtype=torch.int64)), sometimes with one edge: ((tensor([1]), tensor([3])), tensor([2]), 1)

Expected behavior

fix this bug

Environment

Additional context

mufeili commented 2 years ago

Could you take a look? @BarclayII

BarclayII commented 2 years ago

I should have fixed the bug in #4732 . Could you try the nightly version?

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale due to lack of activity. It will be closed if no further activity occurs. Thank you