dmlc / dmlc/dgl

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

Open
#4,778 3 comments 0 reactions 1 assignee Claimed by @BarclayII View on GitHub
stale-issue
Dominant language
Python
Stars
14.3k
Forks
3.1k
PR merge metrics
No merged PRs in 30d

Description

## 🐛 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

- DGL Version (e.g., 1.0): 0.9.1
- Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): PyTorch 1.12.1
- OS (e.g., Linux): Windows
- How you installed DGL (`conda`, `pip`, source): pip
- Python version: 3.8
- CUDA/cuDNN version (if applicable): cuda11.6
- GPU models and configuration (e.g. V100): Nvidia RTX 2060

## Additional context

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.