python-graphblas / graphblas-algorithms

Graph algorithms written in GraphBLAS
Apache License 2.0
73 stars 4 forks source link

Implement `.generators.ego.ego_graph` #61

Closed eriknw closed 1 year ago

eriknw commented 1 year ago

Also, clean up shared BFS functions and move to _bfs.py.

Don't be alarmed if there's a failing test. I think we need to make a small change upstream to networkx to handle a weight argument that uses the keyword distance=.

eriknw commented 1 year ago

fyi, this PR also added tests that show what functions have and have not been implemented. For example:

$ pytest -s -k test_print_dispatched_not_implemented

graphblas_algorithms/tests/test_match_nx.py
=================================================================================
Functions dispatched in NetworkX that ARE NOT implemented in graphblas-algorithms
---------------------------------------------------------------------------------
0 networkx.algorithms.bipartite.basic.is_bipartite
1 networkx.algorithms.centrality.betweenness.betweenness_centrality
2 networkx.algorithms.centrality.betweenness.edge_betweenness_centrality
3 networkx.algorithms.components.connected.connected_components
4 networkx.algorithms.components.strongly_connected.strongly_connected_components
5 networkx.algorithms.components.weakly_connected.weakly_connected_components
6 networkx.algorithms.core.core_number
7 networkx.algorithms.core.k_core
8 networkx.algorithms.link_prediction.jaccard_coefficient
9 networkx.algorithms.shortest_paths.generic.shortest_path
10 networkx.algorithms.shortest_paths.generic.shortest_path_length
11 networkx.algorithms.shortest_paths.unweighted.all_pairs_shortest_path
12 networkx.algorithms.shortest_paths.unweighted.single_source_shortest_path
13 networkx.algorithms.shortest_paths.unweighted.single_target_shortest_path
14 networkx.algorithms.shortest_paths.weighted.all_pairs_bellman_ford_path
15 networkx.algorithms.shortest_paths.weighted.bellman_ford_path
16 networkx.algorithms.shortest_paths.weighted.bellman_ford_path_length
17 networkx.algorithms.shortest_paths.weighted.bellman_ford_predecessor_and_distance
18 networkx.algorithms.shortest_paths.weighted.single_source_bellman_ford
19 networkx.algorithms.shortest_paths.weighted.single_source_bellman_ford_path
20 networkx.algorithms.traversal.breadth_first_search.bfs_edges
21 networkx.algorithms.traversal.breadth_first_search.bfs_predecessors
22 networkx.algorithms.traversal.breadth_first_search.bfs_successors
23 networkx.algorithms.traversal.edgebfs.edge_bfs
=================================================================================

and

$ pytest -s -k test_print_dispatched_implemented

graphblas_algorithms/tests/test_match_nx.py
=============================================================================
Functions dispatched in NetworkX that ARE implemented in graphblas-algorithms
-----------------------------------------------------------------------------
0 networkx.algorithms.boundary.edge_boundary
1 networkx.algorithms.boundary.node_boundary
2 networkx.algorithms.centrality.degree_alg.degree_centrality
3 networkx.algorithms.centrality.degree_alg.in_degree_centrality
4 networkx.algorithms.centrality.degree_alg.out_degree_centrality
5 networkx.algorithms.centrality.eigenvector.eigenvector_centrality
6 networkx.algorithms.centrality.katz.katz_centrality
7 networkx.algorithms.cluster.average_clustering
8 networkx.algorithms.cluster.clustering
9 networkx.algorithms.cluster.generalized_degree
10 networkx.algorithms.cluster.square_clustering
11 networkx.algorithms.cluster.transitivity
12 networkx.algorithms.cluster.triangles
13 networkx.algorithms.community.quality.inter_community_edges
14 networkx.algorithms.community.quality.intra_community_edges
15 networkx.algorithms.components.connected.is_connected
16 networkx.algorithms.components.connected.node_connected_component
17 networkx.algorithms.components.weakly_connected.is_weakly_connected
18 networkx.algorithms.core.k_truss
19 networkx.algorithms.cuts.boundary_expansion
20 networkx.algorithms.cuts.conductance
21 networkx.algorithms.cuts.cut_size
22 networkx.algorithms.cuts.edge_expansion
23 networkx.algorithms.cuts.mixing_expansion
24 networkx.algorithms.cuts.node_expansion
25 networkx.algorithms.cuts.normalized_cut_size
26 networkx.algorithms.cuts.volume
27 networkx.algorithms.dag.ancestors
28 networkx.algorithms.dag.descendants
29 networkx.algorithms.dominating.is_dominating_set
30 networkx.algorithms.isolate.is_isolate
31 networkx.algorithms.isolate.isolates
32 networkx.algorithms.isolate.number_of_isolates
33 networkx.algorithms.link_analysis.hits_alg.hits
34 networkx.algorithms.link_analysis.pagerank_alg.google_matrix
35 networkx.algorithms.link_analysis.pagerank_alg.pagerank
36 networkx.algorithms.operators.binary.compose
37 networkx.algorithms.operators.binary.difference
38 networkx.algorithms.operators.binary.disjoint_union
39 networkx.algorithms.operators.binary.full_join
40 networkx.algorithms.operators.binary.intersection
41 networkx.algorithms.operators.binary.symmetric_difference
42 networkx.algorithms.operators.binary.union
43 networkx.algorithms.reciprocity.overall_reciprocity
44 networkx.algorithms.reciprocity.reciprocity
45 networkx.algorithms.regular.is_k_regular
46 networkx.algorithms.regular.is_regular
47 networkx.algorithms.shortest_paths.dense.floyd_warshall
48 networkx.algorithms.shortest_paths.dense.floyd_warshall_numpy
49 networkx.algorithms.shortest_paths.dense.floyd_warshall_predecessor_and_distance
50 networkx.algorithms.shortest_paths.generic.has_path
51 networkx.algorithms.shortest_paths.unweighted.all_pairs_shortest_path_length
52 networkx.algorithms.shortest_paths.unweighted.single_source_shortest_path_length
53 networkx.algorithms.shortest_paths.unweighted.single_target_shortest_path_length
54 networkx.algorithms.shortest_paths.weighted.all_pairs_bellman_ford_path_length
55 networkx.algorithms.shortest_paths.weighted.negative_edge_cycle
56 networkx.algorithms.shortest_paths.weighted.single_source_bellman_ford_path_length
57 networkx.algorithms.simple_paths.is_simple_path
58 networkx.algorithms.smetric.s_metric
59 networkx.algorithms.structuralholes.mutual_weight
60 networkx.algorithms.tournament.is_tournament
61 networkx.algorithms.tournament.score_sequence
62 networkx.algorithms.tournament.tournament_matrix
63 networkx.algorithms.traversal.breadth_first_search.bfs_layers
64 networkx.algorithms.traversal.breadth_first_search.descendants_at_distance
65 networkx.algorithms.triads.is_triad
66 networkx.generators.ego.ego_graph
=============================================================================

You can see we're making some progress!