rapidsai / cugraph

cuGraph - RAPIDS Graph Analytics Library
https://docs.rapids.ai/api/cugraph/stable/
Apache License 2.0
1.76k stars 304 forks source link

[BUG]: Multiple edges error warning for graphs created with nx.Graph() #4413

Open tamakoyuki opened 6 months ago

tamakoyuki commented 6 months ago

Version

cugraph-cu11 24.4.0

Which installation method(s) does this occur on?

Pip

Describe the bug.

I did not create multiple edges in my code, but the minimum spanning tree algorithm issued an exception warning. That's why I hope to eliminate this warning and speed up tree generation.

Minimum reproducible example

import networkx as nx
import random
from cugraph.tree.minimum_spanning_tree import minimum_spanning_tree

# Create an empty graph
G = nx.Graph()

# Add 100 nodes to the graph
for i in range(100):
    G.add_node(i)

# Create a list to store random nodes
random_nodes_list = []

# Add random edges to the graph
for i in range(100):
    # Choose 30 random nodes from all nodes except the current node
    other_nodes = [node for node in range(100) if node != i]
    random_nodes = random.sample(other_nodes, 30)
    for j in random_nodes:
        # Add an edge if it doesn't exist already
        if not G.has_edge(i, j):
            weight = random.uniform(1, 2)  # Assign a random weight to the edge
            G.add_edge(i, j, weight=weight)
    # Store the random nodes if i equals 5
    if i == 5:
        random_nodes_list = random_nodes

# Define subgraph nodes as the list of random nodes
subgraph_nodes = random_nodes_list

# Create a subgraph with the selected nodes
subgraph = G.subgraph(subgraph_nodes)

# Find the minimum spanning tree of the subgraph
min_spanning_tree = minimum_spanning_tree(subgraph)

# Calculate the total distance of the minimum spanning tree
total_distance = sum([min_spanning_tree[i][j]['weight'] for i, j in min_spanning_tree.edges()])

print("The total distance:", total_distance)

Relevant log output

(py10) lw@user-virtual-machine:~$ python /home/lw/newpro/tes.py
/home/share/lw/miniconda3/envs/py10/lib/python3.10/site-packages/cugraph/structure/symmetrize.py:93: FutureWarning: Multi is deprecated and the removal of multi edges will no longer be supported from 'symmetrize'. Multi edges will be removed upon creation of graph instance.
  warnings.warn(
/home/share/lw/miniconda3/envs/py10/lib/python3.10/site-packages/cugraph/structure/symmetrize.py:93: FutureWarning: Multi is deprecated and the removal of multi edges will no longer be supported from 'symmetrize'. Multi edges will be removed upon creation of graph instance.
  warnings.warn(
The totol: 30.71378326416015

Environment details

No response

Other/Misc.

No response

Code of Conduct

BradReesWork commented 6 months ago

@tamakoyuki thanks for entering this issue.

ChuckHastings commented 3 months ago

This warning occurs in the conversion from a networkx graph to the cugraph structure for representing the graph.

This is a code path that we are phasing out. @rlratzel - does nx-cugraph support minimum spanning tree? If not, any idea when it will?

@tamakoyuki - it should be safe to ignore this warning. The symmetrization function should be working correctly, the warning is indicating that we plan on dropping support for that feature. In reality (new since that warning was put in place), we plan on dropping support for calling cugraph algorithms in this manner in favor of using nx-cugraph. I don't believe we will change anything in the existing code path at this point, we're going to continue to migrate users to the nx-cugraph path.

Note that the warning isn't actually identifying that you are sending in multi edges... rather it is indicating that the code is passing a parameter that you might be sending in multi edges. This is hardcoded into the current code path as a precaution.