graphblas-algorithms is a collection of GraphBLAS algorithms written using
python-graphblas.
It may be used directly or as an experimental
backend to NetworkX.
Why use GraphBLAS Algorithms? Because it is fast, flexible, and familiar by using the NetworkX API.
Are we missing any algorithms that you want?
Please let us know!

conda install -c conda-forge graphblas-algorithms
pip install graphblas-algorithms
First, create a GraphBLAS Matrix.
import graphblas as gb
M = gb.Matrix.from_coo(
[0, 0, 1, 2, 2, 3],
[1, 3, 0, 0, 1, 2],
[1., 2., 3., 4., 5., 6.],
nrows=4, ncols=4, dtype='float32'
)Next wrap the Matrix as ga.Graph.
import graphblas_algorithms as ga
G = ga.Graph(M)Finally call an algorithm.
hubs, authorities = ga.hits(G)When the result is a value per node, a gb.Vector will be returned.
In the case of HITS,
two Vectors are returned representing the hubs and authorities values.
Algorithms whose result is a subgraph will return ga.Graph.
Dispatching to plugins is a new feature in Networkx 3.0.
When both networkx and graphblas-algorithms are installed in an
environment, calls to NetworkX algorithms can be dispatched to the
equivalent version in graphblas-algorithms.
import networkx as nx
import graphblas_algorithms as ga
# Generate a random graph (5000 nodes, 1_000_000 edges)
G = nx.erdos_renyi_graph(5000, 0.08)
# Explicitly convert to ga.Graph
G2 = ga.Graph.from_networkx(G)
# Pass G2 to NetworkX's k_truss
T5 = nx.k_truss(G2, 5)G2 is not a nx.Graph, but it does have an attribute
__networkx_plugin__ = "graphblas". This tells NetworkX to
dispatch the k_truss call to graphblas-algorithms. This link
connection exists because graphblas-algorithms registers
itself as a "networkx.plugin" entry point.
The result T5 is a ga.Graph representing the 5-truss structure of the
original graph. To convert to a NetworkX Graph, use:
T5.to_networkx()Note that even with the conversions to and from ga.Graph, this example still runs 10x
faster than using the native NetworkX k-truss implementation. Speed improvements scale
with graph size, so larger graphs will see an even larger speed-up relative to NetworkX.
The following NetworkX algorithms have been implemented by graphblas-algorithms and can be used following the dispatch pattern shown above.
graphblas_algorithms.nxapi
βββ boundary
β βββ edge_boundary
β βββ node_boundary
βββ centrality
β βββ degree_alg
β β βββ degree_centrality
β β βββ in_degree_centrality
β β βββ out_degree_centrality
β βββ eigenvector
β β βββ eigenvector_centrality
β βββ katz
β βββ katz_centrality
βββ cluster
β βββ average_clustering
β βββ clustering
β βββ generalized_degree
β βββ square_clustering
β βββ transitivity
β βββ triangles
βββ community
β βββ quality
β βββ inter_community_edges
β βββ intra_community_edges
βββ components
β βββ connected
β β βββ is_connected
β β βββ node_connected_component
β βββ weakly_connected
β βββ is_weakly_connected
βββ core
β βββ k_truss
βββ cuts
β βββ boundary_expansion
β βββ conductance
β βββ cut_size
β βββ edge_expansion
β βββ mixing_expansion
β βββ node_expansion
β βββ normalized_cut_size
β βββ volume
βββ dag
β βββ ancestors
β βββ descendants
βββ dominating
β βββ is_dominating_set
βββ efficiency_measures
β βββ efficiency
βββ generators
β βββ ego
β βββ ego_graph
βββ isolate
β βββ is_isolate
β βββ isolates
β βββ number_of_isolates
βββ isomorphism
β βββ isomorph
β βββ fast_could_be_isomorphic
β βββ faster_could_be_isomorphic
βββ linalg
β βββ bethehessianmatrix
β β βββ bethe_hessian_matrix
β βββ graphmatrix
β β βββ adjacency_matrix
β βββ laplacianmatrix
β β βββ laplacian_matrix
β β βββ normalized_laplacian_matrix
β βββ modularitymatrix
β βββ directed_modularity_matrix
β βββ modularity_matrix
βββ link_analysis
β βββ hits_alg
β β βββ hits
β βββ pagerank_alg
β βββ google_matrix
β βββ pagerank
βββ lowest_common_ancestors
β βββ lowest_common_ancestor
βββ operators
β βββ binary
β β βββ compose
β β βββ difference
β β βββ disjoint_union
β β βββ full_join
β β βββ intersection
β β βββ symmetric_difference
β β βββ union
β βββ unary
β βββ complement
β βββ reverse
βββ reciprocity
β βββ overall_reciprocity
β βββ reciprocity
βββ regular
β βββ is_k_regular
β βββ is_regular
βββ shortest_paths
β βββ dense
β β βββ floyd_warshall
β β βββ floyd_warshall_numpy
β β βββ floyd_warshall_predecessor_and_distance
β βββ generic
β β βββ has_path
β βββ unweighted
β β βββ all_pairs_shortest_path_length
β β βββ single_source_shortest_path_length
β β βββ single_target_shortest_path_length
β βββ weighted
β βββ all_pairs_bellman_ford_path_length
β βββ bellman_ford_path
β βββ bellman_ford_path_length
β βββ negative_edge_cycle
β βββ single_source_bellman_ford_path_length
βββ simple_paths
β βββ is_simple_path
βββ smetric
β βββ s_metric
βββ structuralholes
β βββ mutual_weight
βββ tournament
β βββ is_tournament
β βββ score_sequence
β βββ tournament_matrix
βββ traversal
β βββ breadth_first_search
β βββ bfs_layers
β βββ descendants_at_distance
βββ triads
βββ is_triad