Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2020-2025, NVIDIA CORPORATION.:
# SPDX-FileCopyrightText: Copyright (c) 2020-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import gc
Expand All @@ -10,12 +10,14 @@

import cudf
import cugraph
from cugraph.datasets import karate_disjoint
from cugraph.testing import SMALL_DATASETS
from cugraph.datasets import karate_disjoint, netscience, polbooks, karate

# =============================================================================
# Parameters
# =============================================================================
TEST_DATASETS = [netscience, polbooks]


DIRECTED_GRAPH_OPTIONS = [False, True]
WEIGHTED_GRAPH_OPTIONS = [False, True]
ENDPOINTS_OPTIONS = [False, True]
Expand All @@ -25,9 +27,7 @@
SUBSET_SIZE_OPTIONS = [4, None]
SUBSET_SEED_OPTIONS = [42]

# NOTE: The following is not really being exploited in the tests as the
# datasets that are used are too small to compare, but it ensures that both
# path are actually sane
# NOTE: The output conversion is done after the centrality is computed.
RESULT_DTYPE_OPTIONS = [np.float32, np.float64]


Expand Down Expand Up @@ -301,16 +301,49 @@ def compare_scores(sorted_df, first_key, second_key, epsilon=DEFAULT_EPSILON):
# =============================================================================
@pytest.mark.sg
@pytest.mark.requires_nx(min_ver="3.5")
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", [False, True])
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
def test_betweenness_centrality(
graph_file,
directed,
subset_size,
normalized,
weight,
endpoints,
subset_seed,
edgevals,
):
sorted_df = calc_betweenness_centrality(
graph_file,
directed=directed,
normalized=normalized,
k=subset_size,
weight=weight,
endpoints=endpoints,
seed=subset_seed,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.requires_nx(min_ver="3.5")
@pytest.mark.parametrize("graph_file", [karate])
@pytest.mark.parametrize("directed", [False])
@pytest.mark.parametrize("subset_size", [4])
@pytest.mark.parametrize("normalized", [False])
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("endpoints", [False])
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", [False])
def test_betweenness_centrality_return_dtypes(
graph_file,
directed,
subset_size,
Expand All @@ -336,14 +369,13 @@ def test_betweenness_centrality(


@pytest.mark.sg
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", [netscience])
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("subset_size", [None])
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("normalized", [False])
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
@pytest.mark.parametrize("endpoints", [False])
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("use_k_full", [True])
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
@pytest.mark.skip(reason="Skipping large tests")
Expand All @@ -355,7 +387,6 @@ def test_betweenness_centrality_k_full(
weight,
endpoints,
subset_seed,
result_dtype,
use_k_full,
edgevals,
):
Expand All @@ -369,7 +400,6 @@ def test_betweenness_centrality_k_full(
weight=weight,
endpoints=endpoints,
seed=subset_seed,
result_dtype=result_dtype,
use_k_full=use_k_full,
edgevals=edgevals,
)
Expand All @@ -388,7 +418,6 @@ def test_betweenness_centrality_k_full(
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
@pytest.mark.parametrize("subset_seed", [None])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
@pytest.mark.skip(reason="Skipping large tests")
def test_betweenness_centrality_fixed_sample(
Expand All @@ -399,7 +428,6 @@ def test_betweenness_centrality_fixed_sample(
weight,
endpoints,
subset_seed,
result_dtype,
edgevals,
):
"""Test Betweenness Centrality using a subset
Expand All @@ -413,21 +441,19 @@ def test_betweenness_centrality_fixed_sample(
weight=weight,
endpoints=endpoints,
seed=subset_seed,
result_dtype=result_dtype,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [[]])
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
@pytest.mark.skip(reason="Skipping large tests")
def test_betweenness_centrality_weight_except(
Expand All @@ -438,7 +464,6 @@ def test_betweenness_centrality_weight_except(
weight,
endpoints,
subset_seed,
result_dtype,
edgevals,
):
"""Calls betwenness_centrality with weight
Expand All @@ -454,22 +479,21 @@ def test_betweenness_centrality_weight_except(
weight=weight,
endpoints=endpoints,
seed=subset_seed,
result_dtype=result_dtype,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("graph_file", [karate])
@pytest.mark.parametrize("directed", [False])
@pytest.mark.parametrize("normalized", [False])
@pytest.mark.parametrize("subset_size", [None])
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
@pytest.mark.parametrize("endpoints", [False])
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
@pytest.mark.parametrize("result_dtype", [str])
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("edgevals", [False])
def test_betweenness_invalid_dtype(
graph_file,
directed,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2019-2025, NVIDIA CORPORATION.:
# SPDX-FileCopyrightText: Copyright (c) 2019-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import gc
Expand All @@ -11,24 +11,23 @@
import cupy
import cudf
import cugraph
from cugraph.datasets import karate_disjoint
from cugraph.testing import utils, SMALL_DATASETS
from cugraph.datasets import karate_disjoint, polbooks, karate
from cugraph.testing import utils

# NOTE: Endpoint parameter is not currently being tested, there could be a test
# to verify that python raise an error if it is used
# =============================================================================
# Parameters
# =============================================================================
TEST_DATASETS = [karate, polbooks]

DIRECTED_GRAPH_OPTIONS = [False, True]
WEIGHTED_GRAPH_OPTIONS = [False, True]
NORMALIZED_OPTIONS = [False, True]
DEFAULT_EPSILON = 0.0001

SUBSET_SIZE_OPTIONS = [4, None]

# NOTE: The following is not really being exploited in the tests as the
# datasets that are used are too small to compare, but it ensures that both
# path are actually sane
# NOTE: The output conversion is done after the centrality is computed.
RESULT_DTYPE_OPTIONS = [np.float32, np.float64]


Expand Down Expand Up @@ -302,21 +301,49 @@ def generate_upper_triangle(dataframe):

@pytest.mark.sg
@pytest.mark.requires_nx(min_ver="3.5", max_ver="3.5")
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
def test_edge_betweenness_centrality(
graph_file,
directed,
subset_size,
normalized,
weight,
result_dtype,
edgevals,
):
sorted_df = calc_edge_betweenness_centrality(
graph_file,
directed=directed,
normalized=normalized,
k=subset_size,
weight=weight,
seed=42,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.requires_nx(min_ver="3.5", max_ver="3.5")
@pytest.mark.parametrize("graph_file", [karate])
@pytest.mark.parametrize("directed", [False])
@pytest.mark.parametrize("subset_size", [None])
@pytest.mark.parametrize("normalized", [False])
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("edgevals", [False])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
def test_edge_betweenness_centrality_return_dtypes(
graph_file,
directed,
subset_size,
normalized,
weight,
edgevals,
result_dtype,
):
sorted_df = calc_edge_betweenness_centrality(
graph_file,
Expand All @@ -333,12 +360,11 @@ def test_edge_betweenness_centrality(

@pytest.mark.sg
@pytest.mark.requires_nx(min_ver="3.5")
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("subset_size", [None])
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("use_k_full", [True])
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
def test_edge_betweenness_centrality_k_full(
Expand All @@ -347,7 +373,6 @@ def test_edge_betweenness_centrality_k_full(
subset_size,
normalized,
weight,
result_dtype,
use_k_full,
edgevals,
):
Expand All @@ -360,7 +385,6 @@ def test_edge_betweenness_centrality_k_full(
k=subset_size,
weight=weight,
seed=42,
result_dtype=result_dtype,
use_k_full=use_k_full,
edgevals=edgevals,
)
Expand All @@ -378,15 +402,13 @@ def test_edge_betweenness_centrality_k_full(
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [None])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
def test_edge_betweenness_centrality_fixed_sample(
graph_file,
directed,
subset_size,
normalized,
weight,
result_dtype,
edgevals,
):
"""Test Edge Betweenness Centrality using a subset
Expand All @@ -400,27 +422,24 @@ def test_edge_betweenness_centrality_fixed_sample(
normalized=normalized,
weight=weight,
seed=None,
result_dtype=result_dtype,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("weight", [[]])
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
@pytest.mark.parametrize("edgevals", WEIGHTED_GRAPH_OPTIONS)
def test_edge_betweenness_centrality_weight_except(
graph_file,
directed,
subset_size,
normalized,
weight,
result_dtype,
edgevals,
):
"""Test calls edge_betweeness_centrality with weight parameter
Expand All @@ -436,14 +455,13 @@ def test_edge_betweenness_centrality_weight_except(
normalized=normalized,
weight=weight,
seed=42,
result_dtype=result_dtype,
edgevals=edgevals,
)
compare_scores(sorted_df, first_key="cu_bc", second_key="ref_bc")


@pytest.mark.sg
@pytest.mark.parametrize("graph_file", SMALL_DATASETS)
@pytest.mark.parametrize("graph_file", TEST_DATASETS)
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
Expand Down
Loading
Loading