def func_to_benchmark(): for sv in start_vertex: cugraph_df = cugraph.bfs_edges(G, sv, depth_limit=depth_limit) all_cugraph_distances.append(cugraph_df)
def func_to_benchmark(): for sv in start_vertex: cugraph_df = cugraph.bfs_edges( G, sv, return_sp_counter=return_sp_counter) all_cugraph_distances.append(cugraph_df)
def _compare_bfs(G, Gnx, source): df = cugraph.bfs_edges(G, source, return_sp_counter=False) if isinstance(df, pandas.DataFrame): df = cudf.from_pandas(df) # This call should only contain 3 columns: # 'vertex', 'distance', 'predecessor' # It also confirms wether or not 'sp_counter' has been created by the call # 'sp_counter' triggers atomic operations in BFS, thus we want to make # sure that it was not the case # NOTE: 'predecessor' is always returned while the C++ function allows to # pass a nullptr assert len(df.columns) == 3, ("The result of the BFS has an invalid " "number of columns") cu_distances = { vertex: dist for vertex, dist in zip(df["vertex"].to_array(), df["distance"].to_array()) } cu_predecessors = { vertex: dist for vertex, dist in zip(df["vertex"].to_array(), df["predecessor"].to_array()) } nx_distances = nx.single_source_shortest_path_length(Gnx, source) # FIXME: The following only verifies vertices that were reached # by cugraph's BFS. # We assume that the distances are given back as integers in BFS # max_val = np.iinfo(df['distance'].dtype).max # Unreached vertices have a distance of max_val missing_vertex_error = 0 distance_mismatch_error = 0 invalid_predecessor_error = 0 for vertex in nx_distances: if vertex in cu_distances: result = cu_distances[vertex] expected = nx_distances[vertex] if result != expected: print("[ERR] Mismatch on distances: " "vid = {}, cugraph = {}, nx = {}".format( vertex, result, expected)) distance_mismatch_error += 1 if vertex not in cu_predecessors: missing_vertex_error += 1 else: pred = cu_predecessors[vertex] if vertex != source and pred not in nx_distances: invalid_predecessor_error += 1 else: # The graph is unweighted thus, predecessors are 1 away if vertex != source and ( (nx_distances[pred] + 1 != cu_distances[vertex])): print("[ERR] Invalid on predecessors: " "vid = {}, cugraph = {}".format(vertex, pred)) invalid_predecessor_error += 1 else: missing_vertex_error += 1 assert missing_vertex_error == 0, "There are missing vertices" assert distance_mismatch_error == 0, "There are invalid distances" assert invalid_predecessor_error == 0, "There are invalid predecessors"