def test_Graph_from_MultiGraph(graph_file): # FIXME: Migrate to new test fixtures for Graph setup once available cuM = utils.read_csv_file(graph_file) GM = cugraph.MultiGraph() GM.from_cudf_edgelist(cuM, source="0", destination="1", edge_attr="2") nxM = utils.read_csv_for_nx(graph_file, read_weights_in_sp=True) GnxM = nx.from_pandas_edgelist( nxM, source="0", target="1", edge_attr="weight", create_using=nx.MultiGraph(), ) G = cugraph.Graph(GM) Gnx = nx.Graph(GnxM) assert Gnx.number_of_edges() == G.number_of_edges() GdM = cugraph.MultiDiGraph() GdM.from_cudf_edgelist(cuM, source="0", destination="1", edge_attr="2") GnxdM = nx.from_pandas_edgelist( nxM, source="0", target="1", edge_attr="weight", create_using=nx.MultiGraph(), ) Gd = cugraph.DiGraph(GdM) Gnxd = nx.DiGraph(GnxdM) assert Gnxd.number_of_edges() == Gd.number_of_edges()
def test_Graph_from_MultiGraph(managed, pool, graph_file): gc.collect() rmm.reinitialize(managed_memory=managed, pool_allocator=pool, initial_pool_size=2 << 27) assert (rmm.is_initialized()) cu_M = utils.read_csv_file(graph_file) # create dataframe for MultiGraph cu_M['3'] = cudf.Series([2.0] * len(cu_M), dtype=np.float32) cu_M['4'] = cudf.Series([3.0] * len(cu_M), dtype=np.float32) # initialize MultiGraph G_multi = cugraph.MultiGraph() G_multi.from_cudf_edgelist(cu_M, source='0', destination='1', edge_attr=['2', '3', '4']) # initialize Graph G = cugraph.Graph() G.from_cudf_edgelist(cu_M, source='0', destination='1', edge_attr='2') # create Graph from MultiGraph G_from_multi = cugraph.Graph(G_multi, edge_attr='2') assert G.edgelist.edgelist_df == G_from_multi.edgelist.edgelist_df
def test_multi_directed_graph_renumber_false(renumber, dask_client): input_data_path = (RAPIDS_DATASET_ROOT_DIR_PATH / "karate_multi_edge.csv").as_posix() chunksize = dcg.get_chunksize(input_data_path) ddf = dask_cudf.read_csv( input_data_path, chunksize=chunksize, delimiter=" ", names=["src", "dst", "value"], dtype=["int32", "int32", "float32"], ) dg = cugraph.MultiGraph(directed=True) with pytest.raises(ValueError): dg.from_dask_cudf_edgelist(ddf, "src", "dst", renumber=renumber)
def test_graph_init_with_multigraph(): """ Ensures only a valid MultiGraph instance can be used to initialize a Graph by checking if either the correct exception is raised or no exception at all. """ nxMG = nx.MultiGraph() with pytest.raises(TypeError): cugraph.Graph(m_graph=nxMG) gdf = cudf.DataFrame({"src": [0, 1, 2], "dst": [1, 2, 3]}) cMG = cugraph.MultiGraph() cMG.from_cudf_edgelist(gdf, source="src", destination="dst") cugraph.Graph(m_graph=cMG) cDiMG = cugraph.MultiDiGraph() # deprecated, but should still work cDiMG.from_cudf_edgelist(gdf, source="src", destination="dst") cugraph.Graph(m_graph=cDiMG)