项目文件夹

文件
Vibhu Jawa 9ae117d3cd [Feature] Add to_cugraph and from_cugraph to DGL (#4166)
* Added to_cugraph and from_cugraph functionality

* fix from_cugraph example

* Addressed Reviews

* Fix linting

* Apply suggestions to docstrings from code review

Co-authored-by: Minjie Wang <minjie.wang@nyu.edu>

* Add API docs and remove `from_cugraph` alias

* move cugraph tests to  tests/cugraph/test_basics.py

* remove ununsed imports from test_basics.py

* remove pytest.importorskip as no longer needed

Co-authored-by: Minjie Wang <minjie.wang@nyu.edu>
Co-authored-by: Minjie Wang <wmjlyjemaine@gmail.com>
2022-07-07 11:52:17 +08:00

65 行
1.8 KiB
Python

import backend as F
import dgl
import numpy as np
from dgl import DGLGraph
import unittest
import pytest
import cugraph
def test_dummy():
cg = cugraph.Graph()
assert cg is not None
def test_to_cugraph_conversion():
g = dgl.graph((F.tensor([0, 1, 2, 3]), F.tensor([1, 0, 3, 2]))).to('cuda')
cugraph_g = g.to_cugraph()
assert cugraph_g.number_of_nodes()==g.number_of_nodes()
assert cugraph_g.number_of_edges()==g.number_of_edges()
assert cugraph_g.has_edge(0, 1)
assert cugraph_g.has_edge(1, 0)
assert cugraph_g.has_edge(3, 2)
def test_from_cugraph_conversion():
# cudf is a dependency of cugraph
import cudf
# directed graph conversion test
cugraph_g = cugraph.Graph(directed=True)
df = cudf.DataFrame({"source":[0, 1, 2, 3],
"destination":[1, 2, 3, 2]})
cugraph_g.from_cudf_edgelist(df)
g = dgl.from_cugraph(cugraph_g)
assert g.device.type == 'cuda'
assert g.number_of_nodes() == cugraph_g.number_of_nodes()
assert g.number_of_edges() == cugraph_g.number_of_edges()
# assert reverse edges are not present
assert g.has_edges_between(0, 1)
assert not g.has_edges_between(1, 0)
assert g.has_edges_between(1, 2)
assert not g.has_edges_between(2, 1)
assert g.has_edges_between(2, 3)
# undirected graph conversion test
cugraph_g = cugraph.Graph(directed=False)
df = cudf.DataFrame({"source":[0, 1, 2, 3],
"destination":[1, 2, 3, 2]})
cugraph_g.from_cudf_edgelist(df)
g = dgl.from_cugraph(cugraph_g)
assert g.device.type == 'cuda'
assert g.number_of_nodes() == cugraph_g.number_of_nodes()
# assert reverse edges are present
assert g.has_edges_between(0, 1)
assert g.has_edges_between(1, 0)
assert g.has_edges_between(1, 2)
assert g.has_edges_between(2, 1)
assert g.has_edges_between(2, 3)