Skip to content

Commit fa096f0

Browse files
authored
Refactor MG Centrality Tests (#4197)
Addresses #4187 This PR makes improvements to old testing conventions used in `cugraph.centrality` MG tests Instead of using nested fixtures. eg. `input_expected_output -> input_combo -> fixture_params` which can be confusing, the `@pytest.mark.parametrize` marker is used to iterate through combinations of parameters used for testing. The fixtures are also replaced by functions used to create SG and MG graphs. Authors: - Ralph Liu (https://github.com/nv-rliu) Approvers: - Don Acosta (https://github.com/acostadon) - Rick Ratzel (https://github.com/rlratzel) - Joseph Nke (https://github.com/jnke2016) URL: #4197
1 parent a410b3f commit fa096f0

7 files changed

Lines changed: 328 additions & 400 deletions

python/cugraph/cugraph/tests/centrality/test_batch_betweenness_centrality_mg.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2021-2023, NVIDIA CORPORATION.
1+
# Copyright (c) 2021-2024, NVIDIA CORPORATION.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -24,46 +24,49 @@
2424
compare_scores,
2525
)
2626

27-
DIRECTED_GRAPH_OPTIONS = [False, True]
28-
WEIGHTED_GRAPH_OPTIONS = [False, True]
29-
ENDPOINTS_OPTIONS = [False, True]
30-
NORMALIZED_OPTIONS = [False, True]
31-
DEFAULT_EPSILON = 0.0001
32-
SUBSET_SIZE_OPTIONS = [4, None]
33-
SUBSET_SEED_OPTIONS = [42]
34-
3527

3628
# =============================================================================
3729
# Parameters
3830
# =============================================================================
39-
DATASETS = [karate]
40-
# FIXME: The "preset_gpu_count" from 21.08 and below are currently not
41-
# supported and have been removed
4231

43-
RESULT_DTYPE_OPTIONS = [np.float64]
32+
33+
DATASETS = [karate]
34+
DEFAULT_EPSILON = 0.0001
35+
IS_DIRECTED = [False, True]
36+
ENDPOINTS = [False, True]
37+
IS_NORMALIZED = [False, True]
38+
RESULT_DTYPES = [np.float64]
39+
SUBSET_SIZES = [4, None]
40+
SUBSET_SEEDS = [42]
41+
IS_WEIGHTED = [False, True]
4442

4543

4644
# =============================================================================
4745
# Pytest Setup / Teardown - called for each test function
4846
# =============================================================================
47+
48+
4949
def setup_function():
5050
gc.collect()
5151

5252

53+
# =============================================================================
54+
# Tests
55+
# =============================================================================
56+
57+
5358
@pytest.mark.mg
5459
@pytest.mark.skipif(is_single_gpu(), reason="skipping MG testing on Single GPU system")
55-
@pytest.mark.parametrize(
56-
"graph_file", DATASETS, ids=[f"dataset={d.get_path().stem}" for d in DATASETS]
57-
)
58-
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
59-
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
60-
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
60+
@pytest.mark.parametrize("dataset", DATASETS)
61+
@pytest.mark.parametrize("directed", IS_DIRECTED)
62+
@pytest.mark.parametrize("subset_size", SUBSET_SIZES)
63+
@pytest.mark.parametrize("normalized", IS_NORMALIZED)
6164
@pytest.mark.parametrize("weight", [None])
62-
@pytest.mark.parametrize("endpoints", ENDPOINTS_OPTIONS)
63-
@pytest.mark.parametrize("subset_seed", SUBSET_SEED_OPTIONS)
64-
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
65+
@pytest.mark.parametrize("endpoints", ENDPOINTS)
66+
@pytest.mark.parametrize("subset_seed", SUBSET_SEEDS)
67+
@pytest.mark.parametrize("result_dtype", RESULT_DTYPES)
6568
def test_mg_betweenness_centrality(
66-
graph_file,
69+
dataset,
6770
directed,
6871
subset_size,
6972
normalized,
@@ -74,7 +77,7 @@ def test_mg_betweenness_centrality(
7477
dask_client,
7578
):
7679
sorted_df = calc_betweenness_centrality(
77-
graph_file,
80+
dataset,
7881
directed=directed,
7982
normalized=normalized,
8083
k=subset_size,
@@ -90,3 +93,6 @@ def test_mg_betweenness_centrality(
9093
second_key="ref_bc",
9194
epsilon=DEFAULT_EPSILON,
9295
)
96+
97+
# Clean-up stored dataset edge-lists
98+
dataset.unload()
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2023, NVIDIA CORPORATION.
1+
# Copyright (c) 2019-2024, NVIDIA CORPORATION.
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
@@ -19,59 +19,57 @@
1919
from cugraph.dask.common.mg_utils import is_single_gpu
2020
from cugraph.datasets import karate, netscience
2121

22-
# Get parameters from standard betwenness_centrality_test
23-
# As tests directory is not a module, we need to add it to the path
24-
# FIXME: Test must be reworked to import from 'cugraph.testing' instead of
25-
# importing from other tests
26-
from test_edge_betweenness_centrality import (
27-
DIRECTED_GRAPH_OPTIONS,
28-
NORMALIZED_OPTIONS,
29-
DEFAULT_EPSILON,
30-
SUBSET_SIZE_OPTIONS,
31-
)
32-
3322
from test_edge_betweenness_centrality import (
3423
calc_edge_betweenness_centrality,
3524
compare_scores,
3625
)
3726

27+
3828
# =============================================================================
3929
# Parameters
4030
# =============================================================================
41-
DATASETS = [karate, netscience]
4231

43-
# FIXME: The "preset_gpu_count" from 21.08 and below are not supported and have
44-
# been removed
45-
RESULT_DTYPE_OPTIONS = [np.float32, np.float64]
32+
33+
DATASETS = [karate, netscience]
34+
IS_DIRECTED = [True, False]
35+
IS_NORMALIZED = [True, False]
36+
DEFAULT_EPSILON = 0.0001
37+
SUBSET_SIZES = [4, None]
38+
RESULT_DTYPES = [np.float32, np.float64]
4639

4740

4841
# =============================================================================
4942
# Pytest Setup / Teardown - called for each test function
5043
# =============================================================================
44+
45+
5146
def setup_function():
5247
gc.collect()
5348

5449

50+
# =============================================================================
51+
# Tests
52+
# =============================================================================
53+
54+
5555
# FIXME: Fails for directed = False(bc score twice as much) and normalized = True.
5656
@pytest.mark.mg
5757
@pytest.mark.skipif(is_single_gpu(), reason="skipping MG testing on Single GPU system")
58-
@pytest.mark.parametrize(
59-
"graph_file", DATASETS, ids=[f"dataset={d.get_path().stem}" for d in DATASETS]
60-
)
61-
@pytest.mark.parametrize("directed", DIRECTED_GRAPH_OPTIONS)
62-
@pytest.mark.parametrize("subset_size", SUBSET_SIZE_OPTIONS)
63-
@pytest.mark.parametrize("normalized", NORMALIZED_OPTIONS)
64-
@pytest.mark.parametrize("result_dtype", RESULT_DTYPE_OPTIONS)
58+
@pytest.mark.parametrize("dataset", DATASETS)
59+
@pytest.mark.parametrize("directed", IS_DIRECTED)
60+
@pytest.mark.parametrize("subset_size", SUBSET_SIZES)
61+
@pytest.mark.parametrize("normalized", IS_NORMALIZED)
62+
@pytest.mark.parametrize("result_dtype", RESULT_DTYPES)
6563
def test_mg_edge_betweenness_centrality(
66-
graph_file,
64+
dataset,
6765
directed,
6866
subset_size,
6967
normalized,
7068
result_dtype,
7169
dask_client,
7270
):
7371
sorted_df = calc_edge_betweenness_centrality(
74-
graph_file,
72+
dataset,
7573
directed=directed,
7674
normalized=normalized,
7775
k=subset_size,
@@ -86,3 +84,5 @@ def test_mg_edge_betweenness_centrality(
8684
second_key="ref_bc",
8785
epsilon=DEFAULT_EPSILON,
8886
)
87+
# Clean-up stored dataset edge-lists
88+
dataset.unload()

0 commit comments

Comments
 (0)