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
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,33 @@ nx-parallel is a NetworkX backend that uses joblib for parallelization. This pro
- [all_pairs_shortest_path](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/shortest_paths/unweighted.py#L62)
- [all_pairs_shortest_path_length](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/shortest_paths/unweighted.py#L19)
- [approximate_all_pairs_node_connectivity](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/approximation/connectivity.py#L14)
- [average_clustering](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L213)
- [average_neighbor_degree](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/assortativity/neighbor_degree.py#L10)
- [betweenness_centrality](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/centrality/betweenness.py#L20)
- [closeness_vitality](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/vitality.py#L10)
- [clustering](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L146)
- [cn_soundarajan_hopcroft](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L200)
- [colliders](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/dag.py#L37)
- [common_neighbor_centrality](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L158)
- [edge_betweenness_centrality](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/centrality/betweenness.py#L103)
- [is_reachable](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/tournament.py#L13)
- [harmonic_centrality](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/centrality/harmonic.py#L10)
- [is_reachable](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/tournament.py#L15)
- [jaccard_coefficient](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L80)
- [johnson](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/shortest_paths/weighted.py#L251)
- [local_efficiency](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/efficiency_measures.py#L11)
- [node_redundancy](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/bipartite/redundancy.py#L12)
- [number_attracting_components](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/components/attracting.py#L9)
- [number_connected_components](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/components/connected.py#L9)
- [number_of_isolates](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/isolate.py#L9)
- [number_strongly_connected_components](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/components/strongly_connected.py#L9)
- [number_weakly_connected_components](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/components/weakly_connected.py#L9)
- [preferential_attachment](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L133)
- [ra_index_soundarajan_hopcroft](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L232)
- [resource_allocation_index](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L55)
- [square_clustering](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L14)
- [tournament_is_strongly_connected](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/tournament.py#L58)
- [triangles](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L76)
- [square_clustering](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L22)
- [tournament_is_strongly_connected](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/tournament.py#L76)
- [triangles](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/cluster.py#L84)
- [v_structures](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/dag.py#L13)
- [within_inter_cluster](https://github.com/networkx/nx-parallel/blob/main/nx_parallel/algorithms/link_prediction.py#L264)

<details>
Expand Down
2 changes: 1 addition & 1 deletion nx_parallel/algorithms/centrality/harmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
__all__ = ["harmonic_centrality"]


@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse)
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse(threshold=0.3))
def harmonic_centrality(
G, nbunch=None, distance=None, sources=None, get_chunks="chunks"
):
Expand Down
8 changes: 2 additions & 6 deletions nx_parallel/tests/test_should_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def dummy_if_large(G):


def test_should_run_if_sparse():
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse)
@nxp._configure_if_nx_active(should_run=nxp.should_run_if_sparse(threshold=0.4))
def dummy_if_sparse(G):
pass

Expand All @@ -63,12 +63,8 @@ def dummy_if_sparse(G):
== "Graph too dense to benefit from parallel execution"
)

G_sparse = nx.fast_gnp_random_graph(20, 0.3, seed=42)
G_sparse = nx.fast_gnp_random_graph(20, 0.2, seed=42)
assert dummy_if_sparse.should_run(G_sparse)
assert (
dummy_if_sparse.should_run(G_sparse, threshold=0.2)
== "Graph too dense to benefit from parallel execution"
)


@pytest.mark.parametrize("func_name", get_functions_with_should_run())
Expand Down
34 changes: 20 additions & 14 deletions nx_parallel/utils/should_run_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def should_skip_parallel(*_):


def should_run_if_large(G, *_):
if hasattr(G, "graph_object"):
G = G.graph_object

if len(G) <= 200:
return "Graph too small for parallel execution"
return True
Expand All @@ -27,18 +30,21 @@ def default_should_run(*_):
return True


def should_run_if_sparse(G, *args, threshold=0.3, **kwargs):
if hasattr(G, "graph_object"):
G = G.graph_object
def should_run_if_sparse(threshold=0.3):
def wrapper(G, *_):
if hasattr(G, "graph_object"):
G = G.graph_object

nodes = len(G)
# Handle trivial graphs separately to avoid division by zero
if nodes <= 1:
return "Empty graph" if nodes == 0 else "Single-node graph"

density = 2 * G.number_of_edges() / (nodes * (nodes - 1))
return (
True
if density <= threshold
else "Graph too dense to benefit from parallel execution"
)

nodes = len(G)
# Handle trivial graphs separately to avoid division by zero
if nodes <= 1:
return "Empty graph" if nodes == 0 else "Single-node graph"

density = 2 * G.number_of_edges() / (nodes * (nodes - 1))
return (
True
if density <= threshold
else "Graph too dense to benefit from parallel execution"
)
return wrapper
60 changes: 0 additions & 60 deletions timing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,3 @@ CPU: 2 GHz Quad-Core Intel Core i5

RAM: 16 GB LPDDR4X at 3733 MHz

## Heatmaps

### New Heatmaps (`new_heatmaps/`)

betweeness_centrality
![alt text](new_heatmaps/heatmap_betweenness_centrality_timing.png)

edge_betweeness_centrality
![alt text](new_heatmaps/heatmap_edge_betweenness_centrality_timing.png)

number_of_isolates
![alt text](new_heatmaps/heatmap_number_of_isolates_timing.png)

tournament.is_reachable
![alt text](new_heatmaps/heatmap_is_reachable_timing.png)

node_redundancy
![alt text](new_heatmaps/heatmap_node_redundancy_timing.png)

## Old heatmaps (`old_heatmaps/`):

all_pairs_all_shortest_paths
![alt text](old_heatmaps/heatmap_all_pairs_all_shortest_paths_timing.png)

all_pairs_bellman_ford_path
![alt text](old_heatmaps/heatmap_all_pairs_bellman_ford_path_timing.png)

all_pairs_bellman_ford_path_length
![alt text](old_heatmaps/heatmap_all_pairs_bellman_ford_path_length_timing.png)

all_pairs_dijkstra_path
![alt text](old_heatmaps/heatmap_all_pairs_dijkstra_path_timing.png)

all_pairs_dijkstra_path_length
![alt text](old_heatmaps/heatmap_all_pairs_dijkstra_path_length_timing.png)

all_pairs_node_connectivity
![alt text](old_heatmaps/heatmap_all_pairs_node_connectivity_timing.png)

all_pairs_shortest_path
![alt text](old_heatmaps/heatmap_all_pairs_shortest_path_timing.png)

all_pairs_shortest_path_length
![alt text](old_heatmaps/heatmap_all_pairs_shortest_path_length_timing.png)

closeness_vitality
![alt text](old_heatmaps/heatmap_closeness_vitality_timing.png)

is_strongly_connected
![alt text](old_heatmaps/heatmap_is_strongly_connected_timing.png)

johnson
![alt text](old_heatmaps/heatmap_johnson_timing.png)

local_efficiency
![alt text](old_heatmaps/heatmap_local_efficiency_timing.png)

square_clustering
![alt text](old_heatmaps/heatmap_square_clustering_timing.png)

8 changes: 6 additions & 2 deletions timing/new_heatmaps/timing_individual_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@
import types

seed = random.Random(42)
tournament_funcs = ["is_reachable", "tournament_is_strongly_connected"]
tournament_funcs = ["is_reachable", "is_strongly_connected"]
bipartite_funcs = ["node_redundancy"]
community_funcs = [
"ra_index_soundarajan_hopcroft",
"cn_soundarajan_hopcroft",
"within_inter_cluster",
]
not_implemented_undirected = []
not_implemented_undirected = [
"number_attracting_components",
"number_strongly_connected_components",
"number_weakly_connected_components",
]


def time_individual_function(
Expand Down
Binary file not shown.
Binary file removed timing/old_heatmaps/heatmap_clustering_timing.png
Binary file not shown.
Binary file removed timing/old_heatmaps/heatmap_is_reachable_timing.png
Binary file not shown.
Loading