Skip to content

A graph data science library for Rust πŸ¦€ with Python bindings 🐍

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

habedi/graphina

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Graphina the Dinosaur

Graphina

Tests Code Coverage Crates.io Docs.rs Docs License

Graphina is a graph data science library for Rust. It provides common data structures and algorithms for analyzing real-world networks, such as social, transportation, and biological networks.

Compared to other Rust graph libraries like petgraph and rustworkx, Graphina aims to provide a more high-level API and a wide range of ready-to-use algorithms for network analysis and graph mining tasks. Graphina aims to be as feature-rich as NetworkX but with the speed and performance benefits of Rust.

Additionally, PyGraphina Python library allows users to use Graphina in Python. Check out pygraphina directory for more details.

See ROADMAP.md for the list of implemented and planned features.

Important

This project is in early development, so bugs and breaking changes are expected. Please use the issues page to report bugs or request features.


Structure

Graphina consists of two main parts: a core library and extensions. The core library provides the basic data structures and algorithms for working with graphs. The extensions are modules outside the core library that contain more advanced algorithms for specific tasks like community detection, link prediction, and calculating node and edge centrality scores.

Extensions are independent of each other but depend on the core library. To use an extension, you must enable it in your Cargo.toml file as a feature (see Installation section below).

Graphina Core

Module Feature or Algorithm Notes
Types
  • Directed and undirected graphs
  • Weighted and unweighted graphs
  • NodeId and EdgeId wrappers
  • NodeMap and EdgeMap type aliases
  • OrderedNodeMap for deterministic iteration
Base types (graph, node, and edge) that Graphina supports
Error Handling
  • Unified GraphinaError for all Graphina modules
  • Result type alias
  • Error conversion helpers
Error handling utilities for Graphina
Builders
  • AdvancedGraphBuilder with validation
  • TopologyBuilder (path, cycle, star, and complete graph builders)
  • Type aliases (DirectedGraphBuilder, UndirectedGraphBuilder)
Ergonomic graph construction utilities
IO
  • Edge list (read and write)
  • Adjacency list (read and write)
I/O routines for reading and writing graph data
Serialization
  • JSON serialization
  • Binary serialization
  • GraphML export
  • SerializableGraph format
Multiple serialization formats for interoperability
Generators
  • ErdΕ‘s–RΓ©nyi graph
  • Watts–Strogatz graph
  • BarabΓ‘si–Albert graph
  • Complete graph (directed and undirected)
  • Bipartite graph
  • Star graph
  • Cycle graph
  • Path graph
  • Random tree
Graph generators for random and structured graphs
Paths
  • Dijkstra's algorithm
  • Bellman-Ford algorithm
  • Floyd-Warshall algorithm
  • Johnson's algorithm
  • A* search algorithm
  • Iterative deepening A* (IDA*)
Shortest paths algorithms
Validation
  • Graph connectivity check
  • DAG validation
  • Bipartite check
  • Negative weights detection
  • Self-loops detection
  • Component counting
  • Algorithm precondition validators
Graph property validation utilities
Pool
  • NodeSet pool
  • NodeMap pool
  • NodeQueue pool
  • Thread-local default pools
Experimental memory pooling utilities

Extensions

Module Feature/Algorithm Notes
Centrality
  • Degree
  • Closeness
  • Betweenness (node and edge)
  • Eigenvector
  • PageRank (standard and personalized)
  • Katz
  • Harmonic
  • Local reaching
  • Global reaching
  • VoteRank (seed selector)
  • Laplacian
  • Percolation (planned)
Centrality and influence measures
Metrics
  • Diameter
  • Radius
  • Average clustering coefficient
  • Clustering coefficient (local)
  • Average path length
  • Transitivity
  • Triangles count
  • Assortativity coefficient
Graph-level and node-level metrics
MST
  • Prim's algorithm
  • Kruskal's algorithm
  • BorΕ―vka's algorithm
Minimum spanning tree algorithms
Traversal
  • Breadth-first search (BFS)
  • Depth-first search (DFS)
  • Iterative deepening DFS (IDDFS)
  • Bidirectional search
Graph traversal algorithms
Subgraphs
  • Subgraph extraction
  • Induced subgraph
  • Ego graph
  • K-hop neighbors
  • Filter nodes or edges
  • Connected component extraction
  • Component subgraph
Subgraph operations and filtering
Links
  • Resource allocation index
  • Jaccard coefficient
  • Adamic-Adar index
  • Preferential attachment
  • Common neighbors
  • CN Soundarajan-Hopcroft
  • RA index Soundarajan-Hopcroft
  • Within-inter-cluster ratio
  • Common neighbor centrality
Link prediction algorithms
Community
  • Label propagation
  • Louvain method
  • Girvan-Newman algorithm
  • Spectral clustering
  • Personalized PageRank
  • Infomap
  • Connected components
Community detection and clustering algorithms
Approximation
  • Node connectivity (BFS-based)
  • Maximum independent set (greedy)
  • Maximum clique (greedy heuristic)
  • Clique removal
  • Large clique size
  • Average clustering coefficient (approximate)
  • Densest subgraph (greedy peeling)
  • Diameter lower bound
  • Minimum weighted vertex cover (greedy)
  • Minimum maximal matching (greedy)
  • Ramsey number R(2,t) approximation
  • TSP approximations (greedy, simulated annealing, threshold accepting, and Christofides)
  • Treewidth decompositions (min degree, and min fill-in)
Approximation algorithms for NP-hard problems
Parallel
  • Parallel BFS
  • Parallel degree computation
  • Parallel clustering coefficients
  • Parallel triangles counting
  • Parallel PageRank
  • Parallel shortest paths
  • Parallel connected components
Parallel implementations of popular graph algorithms
Visualization
  • ASCII art visualization
  • Force-directed layout
  • Circular layout
  • Grid layout
  • Hierarchical layout
  • HTML generation
  • SVG export
  • PNG export
  • D3.js JSON format
Graph visualization algorithms

Installation

cargo add graphina

Or add this to your Cargo.toml:

[dependencies]
graphina = "0.3.0-alpha.4"

Or enable all features with:

[dependencies]
graphina = { version = "0.3.0-alpha.4", features = ["centrality", "community", "approximation", "mst", "traversal", "subgraphs", "visualization", "parallel", "pool"] }

Note

Graphina requires Rust 1.86 or later.

Documentation

See docs and docs.rs/graphina for more information for the detailed documentation including examples and API references.

API Examples

Simple Example
use graphina::core::types::Graph;

fn main() {
    // Create a new undirected graph
    let mut graph = Graph::new();

    // Add nodes and edges to the graph
    let n0 = graph.add_node(1);
    let n1 = graph.add_node(1);
    let n2 = graph.add_node(2);
    let n3 = graph.add_node(3);
    graph.add_edge(n0, n1, 1.0);
    graph.add_edge(n1, n2, 1.0);
    graph.add_edge(n2, n3, 1.0);

    // Get the neighbors of node 1
    for neighbor in graph.neighbors(n1) {
        println!("Node 1 has neighbor: {}", neighbor.index());
    }
}
Graph Builder API
use graphina::core::builders::UndirectedGraphBuilder;

// Use graph builder API to create an undirected graph
let g = UndirectedGraphBuilder::<i32, f64>::undirected()
.with_capacity(4, 3)
.add_node(1)
.add_node(2)
.add_node(3)
.add_edge(0, 1, 1.0)
.add_edge(1, 2, 2.0)
.build()
.unwrap();
Seeded Generators
use graphina::core::generators::{erdos_renyi_graph, barabasi_albert_graph};
use graphina::core::types::Undirected;

// Use 42 for pseudo-random seed (for deterministic results)
let er = erdos_renyi_graph::<Undirected>(100, 0.2, 42).unwrap();
let ba = barabasi_albert_graph::<Undirected>(1000, 3, 42).unwrap();

Contributing

See CONTRIBUTING.md for details on how to make a contribution.

Logo

The mascot is named "Graphina the Dinosaur". As the name implies, she's a dinosaur, however, she herself thinks she's a dragon.

The logo was created using GIMP, ComfyUI, and a Flux Schnell v2 model.

Licensing

Graphina is licensed under either of these:

PyGraphina is licensed under the MIT License (LICENSE).

About

A graph data science library for Rust πŸ¦€ with Python bindings 🐍

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Contributing

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •