Skip to content

Commit e4b9d9c

Browse files
committed
fix: revert only functional change from last commit
1 parent e0db6bb commit e4b9d9c

File tree

4 files changed

+13
-33
lines changed

4 files changed

+13
-33
lines changed

nx_parallel/algorithms/centrality/tests/test_betweenness_centrality.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,34 @@ def test_edge_betweenness_centrality_get_chunks():
77
def get_chunk(edges):
88
num_chunks = nxp.get_n_jobs()
99

10-
# Convert edges to a list to support slicing
1110
edges = list(edges)
1211

1312
# Split edges into chunks without relying on precomputed centrality
1413
chunk_size = max(1, len(edges) // num_chunks)
1514
chunks = [edges[i : i + chunk_size] for i in range(0, len(edges), chunk_size)]
1615

17-
# Debugging: Print how edges are distributed among chunks
1816
print(f"Chunks distribution: {chunks}")
1917

2018
return chunks
2119

22-
# Create a random graph
2320
G = nx.fast_gnp_random_graph(100, 0.1, directed=False)
24-
H = nxp.ParallelGraph(G) # Wrap the graph in ParallelGraph
21+
H = nxp.ParallelGraph(G)
2522

26-
# Compute edge betweenness centrality using NetworkX
2723
ebc = nx.edge_betweenness_centrality(G, normalized=True)
2824

29-
# Debugging: Print the edge betweenness centrality values from NetworkX
3025
print(f"NetworkX Edge Betweenness Centrality: {ebc}")
3126

32-
# Instantiate the BackendInterface
3327
backend = nxp.BackendInterface()
3428

3529
# Smoke test for edge_betweenness_centrality with custom get_chunks
3630
par_bc_chunk = backend.edge_betweenness_centrality(
37-
H.graph_object, # Pass the underlying NetworkX graph
38-
get_chunks=get_chunk, # Pass the custom get_chunks function
31+
H.graph_object,
32+
get_chunks=get_chunk,
3933
)
4034

41-
# Debugging: Print the results from parallel computation
4235
print(f"Parallel Computed Edge Betweenness Centrality: {par_bc_chunk}")
4336

44-
# Compare with standard NetworkX edge betweenness centrality
37+
# Compare with standard edge betweenness centrality
4538
standard_bc = nx.edge_betweenness_centrality(G, normalized=True)
4639

4740
for edge in standard_bc:

nx_parallel/interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ def __setstate__(self, state):
8181
def assign_algorithms(cls):
8282
"""Class decorator to assign algorithms to the class attributes."""
8383
for attr in ALGORITHMS:
84-
func_name = attr.rsplit(".", 1)[-1]
85-
func = attrgetter(attr)(algorithms)
86-
setattr(cls, func_name, staticmethod(func))
84+
setattr(
85+
cls, attr.rsplit(".", 1)[-1], staticmethod(attrgetter(attr)(algorithms))
86+
)
8787
return cls
8888

8989

nx_parallel/tests/test_get_chunks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,8 @@ def iterator_func(G):
8484
H, process_func, iterator_func, get_chunks=random_chunking
8585
)
8686
if isinstance(c1, types.GeneratorType):
87-
c1, c2 = (
88-
list(c1),
89-
list(c2),
87+
c1, c2 = list(c1), list(
88+
c2
9089
) # Convert generators to lists for comparison
9190
if func in chk_dict_vals:
9291
for i in range(len(G.nodes)):

nx_parallel/utils/tests/test_chunk.py

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_get_n_jobs():
2727
with patch("joblib.parallel.get_active_backend", return_value=("loky", 3)):
2828
assert nxp.get_n_jobs() == 3
2929

30-
# Test with n_jobs set in NetworkX config
30+
# Test with n_jobs set in NX config
3131
nx.config.backends.parallel.active = True
3232
nx.config.backends.parallel.n_jobs = 5
3333
assert nxp.get_n_jobs() == 5
@@ -59,13 +59,11 @@ def test_execute_parallel_basic():
5959
G = nx.path_graph(10)
6060
H = nxp.ParallelGraph(G)
6161

62-
# Define a simple process_func that calculates the degree of each node in the chunk
6362
def process_func(G, chunk, **kwargs):
6463
return {node: G.degree(node) for node in chunk}
6564

66-
# Define an iterator_func that returns all nodes
6765
def iterator_func(G):
68-
return list(G.nodes()) # Convert NodeView to list
66+
return list(G.nodes())
6967

7068
# Execute in parallel without overrides
7169
results = nxp.execute_parallel(
@@ -85,17 +83,14 @@ def iterator_func(G):
8583
def test_execute_parallel_with_overrides():
8684
"""Test `execute_parallel` with overridden parallel configuration."""
8785

88-
# Create a simple graph
8986
G = nx.complete_graph(5)
9087
H = nxp.ParallelGraph(G)
9188

92-
# Define a simple process_func that returns the list of nodes in the chunk
9389
def process_func(G, chunk, **kwargs):
9490
return list(chunk)
9591

96-
# Define an iterator_func that returns all nodes
9792
def iterator_func(G):
98-
return list(G.nodes()) # Convert NodeView to list
93+
return list(G.nodes())
9994

10095
# Mock joblib.Parallel in the correct module
10196
with patch("nx_parallel.utils.chunk.Parallel") as mock_parallel:
@@ -123,11 +118,9 @@ def test_execute_parallel_callable_chunks():
123118
G = nx.cycle_graph(6)
124119
H = nxp.ParallelGraph(G)
125120

126-
# Define a process_func that sums node numbers in the chunk
127121
def process_func(G, chunk, **kwargs):
128122
return sum(chunk)
129123

130-
# Define an iterator_func that returns all nodes as a list
131124
def iterator_func(G):
132125
return list(G.nodes()) # Convert NodeView to list
133126

@@ -151,17 +144,14 @@ def custom_chunking(data):
151144
def test_parallel_config_override():
152145
"""Test that `parallel_config` correctly overrides config within its context."""
153146

154-
# Define a simple graph
155147
G = nx.complete_graph(5)
156148
H = nxp.ParallelGraph(G)
157149

158-
# Define a simple process_func that returns the list of nodes in the chunk
159150
def process_func(G, chunk, **kwargs):
160151
return list(chunk)
161152

162-
# Define an iterator_func that returns all nodes
163153
def iterator_func(G):
164-
return list(G.nodes()) # Convert NodeView to list
154+
return list(G.nodes())
165155

166156
# Mock joblib.Parallel to capture the parameters it's called with
167157
with patch("nx_parallel.utils.chunk.Parallel") as mock_parallel:
@@ -189,11 +179,9 @@ def test_parallel_config_nested_overrides():
189179
G = nx.complete_graph(5)
190180
H = nxp.ParallelGraph(G)
191181

192-
# Define a simple process_func
193182
def process_func(G, chunk, **kwargs):
194183
return list(chunk)
195184

196-
# Define an iterator_func
197185
def iterator_func(G):
198186
return list(G.nodes())
199187

0 commit comments

Comments
 (0)