cugraph icon indicating copy to clipboard operation
cugraph copied to clipboard

isolated vertices are not being captured properly when initializing a Graph with an adjacency matrix

Open rlratzel opened this issue 4 years ago • 4 comments

Isolated vertices are lost when we initialize a Graph using an adj list:

>>> nxG = nx.from_numpy_array     (np.array([[1,1,0], [1,0,0], [0,0,0]]), create_using=nx.DiGraph)
>>> G   = cugraph.from_numpy_array(np.array([[1,1,0], [1,0,0], [0,0,0]]), create_using=cugraph.DiGraph)
>>>
>>> nxG.number_of_nodes()
3
>>> G.number_of_vertices()
2
>>> G = cugraph.from_numpy_array(np.array([[0]]), create_using=cugraph.DiGraph)
/opt/conda/envs/rapids/lib/python3.8/site-packages/cudf/core/join/casting_logic.py:132: UserWarning: can't safely cast column from right with type float64 to int64, upcasting to float64
  warnings.warn(
>>> G.number_of_vertices()
nan
>>> nxG = nx.from_numpy_array(np.array([[0]]), create_using=nx.DiGraph)
>>> nxG.number_of_nodes()
1

This is likely due to internally converting the numpy array to an edgelist, which is then used to initialize the Graph. We may be able to at least capture the correct number of vertices by looking at the incoming array's shape (which would also allow us to assert it's square).

rlratzel avatar Mar 23 '21 03:03 rlratzel

The new graph object construction code can handle this properly as long as the python code calls the construction properly.

The legacy graph object construction code in C++ should handle this properly except in the case where there are isolated vertices at the end of the vertex list.

We need to prioritize/schedule this accordingly. If we can wait until we migrate to the new graph objects (C++) then this problem will be corrected at that point. If we need to fix it sooner then we will need to update the legacy implementation to properly handle isolated vertices at the end of the vertex list.

ChuckHastings avatar Jun 03 '21 16:06 ChuckHastings

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Feb 25 '22 20:02 github-actions[bot]

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar May 11 '22 18:05 github-actions[bot]

This issue has been labeled inactive-30d due to no recent activity in the past 30 days. Please close this issue if no further response or action is needed. Otherwise, please respond with a comment indicating any updates or changes to the original issue and/or confirm this issue still needs to be addressed. This issue will be labeled inactive-90d if there is no activity in the next 60 days.

github-actions[bot] avatar Jul 01 '22 15:07 github-actions[bot]

Note that #3982 adds parameters to the C API that can address this. The python layer would need to be updated to pick up these changes in the case of an adjacency matrix.

ChuckHastings avatar Nov 14 '23 23:11 ChuckHastings