-
-
Notifications
You must be signed in to change notification settings - Fork 35
ENH : adding parallel implementations of all_pairs_ algos
#33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f9f1ff4
initial commit
Schefflera-Arboricola d7fcf95
rm extra docs
Schefflera-Arboricola fcf6612
added unweighted.py rm johnson and all non all_pairs_ algos from weig…
Schefflera-Arboricola 1f68d7d
added all_pairs_node_connectivity
Schefflera-Arboricola 94de91f
Update weighted.py
Schefflera-Arboricola 485270d
modifying G
Schefflera-Arboricola a6a8f0a
fixed all_pairs_node_connectivity
Schefflera-Arboricola 0cba23e
un-updated ParallelGraph class
Schefflera-Arboricola e9c6c06
style fixes
Schefflera-Arboricola 5bc797e
changed all_pairs def
Schefflera-Arboricola 414f2c8
adding directed to _calculate_all_pairs_node_connectivity_subset
Schefflera-Arboricola 4f8a751
updated docs of all funcs
Schefflera-Arboricola 00b310b
style fix
Schefflera-Arboricola 20ec806
added benchmarks
Schefflera-Arboricola 01e42ac
style fix
Schefflera-Arboricola bbbc5f2
added 6 heatmaps(no speedups in 3)
Schefflera-Arboricola cbda3e8
used loky backend in approximation.connectivity.all_pairs_node_connec…
Schefflera-Arboricola c7a341b
added get_chunks to shortest paths algos
Schefflera-Arboricola 95b9217
added chunking in all_pairs_node_connectivity, added benchmarks, fixe…
Schefflera-Arboricola a96dbff
updated docstrings of all 9 funcs
Schefflera-Arboricola 34ef348
Merge branch 'main' into shortest_paths
dschult 07db6dc
Merge branch 'main' into shortest_paths
dschult 5c28ad1
typo fix
Schefflera-Arboricola e0c000b
Merge branch 'main' into shortest_paths
Schefflera-Arboricola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .connectivity import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Parallel implementations of fast approximation for node connectivity""" | ||
| import itertools | ||
| from joblib import Parallel, delayed | ||
| import nx_parallel as nxp | ||
| from networkx.algorithms.approximation.connectivity import local_node_connectivity | ||
|
|
||
| __all__ = [ | ||
| "all_pairs_node_connectivity", | ||
| ] | ||
|
|
||
|
|
||
| def all_pairs_node_connectivity(G, nbunch=None, cutoff=None): | ||
| def _calculate_all_pairs_node_connectivity_subset(chunk): | ||
| for u, v in chunk: | ||
| k = local_node_connectivity(G, u, v, cutoff=cutoff) | ||
| all_pairs[u][v] = k | ||
| if not directed: | ||
| all_pairs[v][u] = k | ||
|
|
||
| if hasattr(G, "graph_object"): | ||
| G = G.graph_object | ||
|
|
||
| if nbunch is None: | ||
| nbunch = G | ||
| else: | ||
| nbunch = set(nbunch) | ||
|
|
||
| directed = G.is_directed() | ||
| if directed: | ||
| iter_func = itertools.permutations | ||
| else: | ||
| iter_func = itertools.combinations | ||
|
|
||
| pairs = list(iter_func(nbunch, 2)) | ||
|
|
||
| all_pairs = {} | ||
| for u, v in pairs: | ||
| all_pairs.setdefault(u, {})[v] = None | ||
| if not directed: | ||
| all_pairs.setdefault(v, {})[u] = None | ||
dschult marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| total_cores = nxp.cpu_count() | ||
| num_in_chunk = max(len(pairs) // total_cores, 1) | ||
| pair_chunks = nxp.chunks(pairs, num_in_chunk) | ||
|
|
||
| Parallel(n_jobs=total_cores, backend="threading")( | ||
| delayed(_calculate_all_pairs_node_connectivity_subset)(chunk) | ||
| for chunk in pair_chunks | ||
| ) | ||
|
|
||
| return all_pairs | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| from .weighted import * | ||
| from .unweighted import * |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| # TODO : update docstrings | ||
|
|
||
| """ | ||
| Shortest path parallel algorithms for unweighted graphs. | ||
| """ | ||
|
|
||
| from joblib import Parallel, delayed | ||
| import nx_parallel as nxp | ||
| from networkx.algorithms.shortest_paths.unweighted import ( | ||
| single_source_shortest_path_length, | ||
| single_source_shortest_path, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "all_pairs_shortest_path", | ||
| "all_pairs_shortest_path_length", | ||
| ] | ||
|
|
||
|
|
||
| def all_pairs_shortest_path_length(G, cutoff=None): | ||
| """Computes the shortest path lengths between all nodes in `G`.""" | ||
| if hasattr(G, "graph_object"): | ||
| G = G.graph_object | ||
|
|
||
| length = single_source_shortest_path_length | ||
dschult marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def _calculate_all_pairs_shortest_path_length_subset(n): | ||
| return (n, (length(G, n, cutoff=cutoff))) | ||
|
|
||
| total_cores = nxp.cpu_count() | ||
|
|
||
| return Parallel(n_jobs=total_cores, return_as="generator")( | ||
| delayed(_calculate_all_pairs_shortest_path_length_subset)(n) for n in G | ||
| ) | ||
|
|
||
|
|
||
| def all_pairs_shortest_path(G, cutoff=None): | ||
| """Compute shortest paths between all nodes.""" | ||
| if hasattr(G, "graph_object"): | ||
| G = G.graph_object | ||
|
|
||
| def _calculate_all_pairs_shortest_path_subset(n): | ||
| return (n, (single_source_shortest_path(G, n, cutoff=cutoff))) | ||
|
|
||
| total_cores = nxp.cpu_count() | ||
|
|
||
| return Parallel(n_jobs=total_cores, return_as="generator")( | ||
| delayed(_calculate_all_pairs_shortest_path_subset)(n) for n in G | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.