Skip to main content

GraphBLAS Algorithms
conda-forge pypi PyPI - Python Version License
Tests Coverage DOI Discord

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!
GraphBLAS vs NetworkX
GraphBLAS vs igraph

Installation

conda install -c conda-forge graphblas-algorithms
pip install graphblas-algorithms

Basic Usage

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.

Plugin for NetworkX

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.

Dispatch Example

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.

Plugin Algorithms

The following NetworkX algorithms have been implemented by graphblas-algorithms and can be used following the dispatch pattern shown above.

  • Boundary
    • edge_boundary
    • node_boundary
  • Centrality
    • degree_centrality
    • eigenvector_centrality
    • in_degree_centrality
    • katz_centrality
    • out_degree_centrality
  • Cluster
    • average_clustering
    • clustering
    • generalized_degree
    • square_clustering
    • transitivity
    • triangles
  • Community
    • inter_community_edges
    • intra_community_edges
  • Components
    • is_connected
    • is_weakly_connected
    • node_connected_component
  • 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
  • Generators
    • ego_graph
  • Isolate
    • is_isolate
    • isolates
    • number_of_isolates
  • Link Analysis
    • google_matrix
    • hits
    • pagerank
  • Operators
    • compose
    • difference
    • disjoint_union
    • full_join
    • intersection
    • symmetric_difference
    • union
  • Reciprocity
    • overall_reciprocity
    • reciprocity
  • Regular
    • is_k_regular
    • is_regular
  • Shortest Paths
    • all_pairs_bellman_ford_path_length
    • all_pairs_shortest_path_length
    • bellman_ford_path
    • floyd_warshall
    • floyd_warshall_numpy
    • floyd_warshall_predecessor_and_distance
    • has_path
    • negative_edge_cycle
    • single_source_bellman_ford_path_length
    • single_source_shortest_path_length
    • single_target_shortest_path_length
  • Simple Paths
    • is_simple_path
  • S Metric
    • s_metric
  • Structural Holes
    • mutual_weight
  • Tournament
    • is_tournament
    • score_sequence
    • tournament_matrix
  • Traversal
    • bfs_layers
    • descendants_at_distance
  • Triads
    • is_triad

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphblas-algorithms-2023.5.0.tar.gz (61.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphblas_algorithms-2023.5.0-py3-none-any.whl (85.5 kB view details)

Uploaded Python 3

File details

Details for the file graphblas-algorithms-2023.5.0.tar.gz.

File metadata

  • Download URL: graphblas-algorithms-2023.5.0.tar.gz
  • Upload date:
  • Size: 61.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.3

File hashes

Hashes for graphblas-algorithms-2023.5.0.tar.gz
Algorithm Hash digest
SHA256 efcfcb295a9390f1cde5dc7eb858b4087ca004dd897cfe1e5b77dc7b0f1679f7
MD5 7118f024bd3fda1834dc60980291a8c8
BLAKE2b-256 19c34600843947ff45241dc8f31e55198bc48de81d0acc8a4cd4b1d98667b526

See more details on using hashes here.

File details

Details for the file graphblas_algorithms-2023.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for graphblas_algorithms-2023.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2eab5206289f290c9d8533f5a5eec29dd791ee9f3bf9aa0823c6e4770e78b206
MD5 101ca0a8561b69fa5e87e3e57842d84d
BLAKE2b-256 b13107f4babb221632b65f99446ea5bf52b9b70a415814014346198e6287cf45

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page