SciRS2 Graph
scirs2-graph is the graph theory and network analysis crate for the SciRS2 scientific computing library. It provides a comprehensive suite of graph algorithms, data structures, graph neural networks, embeddings, and visualization tools for scientific computing, machine learning, and network science applications.
Status (2026-07-22, v0.6.2): Stable. No todo!()/unimplemented!() stubs found anywhere in src/. Test suite: 1418/1418 passing with default features (8 skipped), 1479/1479 passing with --all-features (8 skipped, including GPU-dispatch smoke tests under the wgpu feature) — 0 failures in either configuration.
What scirs2-graph Provides
Use scirs2-graph when you need to:
- Analyze social, biological, or infrastructure networks
- Run community detection or graph clustering
- Compute shortest paths, centrality, or flow in large graphs
- Train graph neural networks (GCN, GAT, GraphSAGE, Graph Transformers)
- Generate graph embeddings with Node2Vec or spectral methods
- Work with temporal, heterogeneous, or knowledge graphs
- Visualize graphs as SVG or DOT output
- Detect graph isomorphism or subgraph patterns
Features (v0.6.2)
Core Graph Representations
- Directed and undirected graphs with efficient adjacency storage
- Multi-graphs with parallel edges
- Bipartite graphs with specialized bipartite algorithms
- Hypergraphs for higher-order relationships
- Attributed graphs with rich vertex and edge metadata
- Temporal graphs and dynamic graph algorithms
- Heterogeneous graphs and knowledge graphs
- CSR (Compressed Sparse Row) graph representation for large-scale graphs
Graph Traversal and Search
- Breadth-first search (BFS), depth-first search (DFS)
- Bidirectional search, priority-first search
- A* pathfinding with custom heuristics
Shortest Paths
- Dijkstra's algorithm (single-source)
- Bellman-Ford (handles negative weights)
- Floyd-Warshall (all-pairs)
- k-shortest paths
Connectivity and Structure
- Connected components, strongly connected components
- Articulation points and bridges
- Topological sorting
- k-core decomposition
- Clique enumeration and motif detection (triangles, stars)
Network Flow
- Ford-Fulkerson, Dinic's algorithm, push-relabel
- Minimum-cost flow
- Minimum cut
Matching
- Bipartite matching (Hopcroft-Karp)
- Maximum cardinality matching
- Stable marriage problem
Centrality Measures
- Degree, betweenness, closeness, eigenvector centrality
- PageRank, personalized PageRank, Katz centrality
- HITS algorithm (hubs and authorities)
Community Detection
- Louvain method (modularity optimization)
- Girvan-Newman (edge betweenness)
- Label propagation
- Infomap algorithm
- Fluid communities
- Hierarchical clustering
Spectral Graph Theory
- Graph Laplacian and normalized Laplacian
- Spectral clustering
- Algebraic connectivity (Fiedler value)
- Normalized cut
Graph Neural Networks
- Graph Convolutional Network (GCN)
- Graph Attention Network (GAT)
- GraphSAGE (inductive representation learning)
- Message-passing framework
- Graph Transformers (Graphormer, GPS) with positional encodings
- Equivariant GNNs (E(n)-GNN, SE(3)-Transformer) for molecular applications
- Relational GCN (R-GCN) and Heterogeneous Graph Transformer (HGT) for knowledge graphs
Graph Self-Supervised Learning
- Contrastive learning (GraphCL-style augmentation, SimGRACE weight perturbation, NT-Xent loss)
- Graph masked autoencoders (GraphMAE)
- Node-masking and graph-context pre-training objectives
Hypergraph Neural Networks
- Hypergraph convolution layers (HGNN)
- Hypergraph attention networks
- Hyperedge prediction
Signed and Directed Graph Learning
- Signed Laplacian, SPONGE embedding, signed ratio-cut clustering
- Balance-theory Signed GCN (SGCN)
- HOPE and APP directed graph embeddings
Graph Embeddings
- Node2Vec random walk embeddings
- DeepWalk
- Spectral embeddings
- Diffusion-based embeddings
Graph Isomorphism and Matching
- VF2 algorithm for graph/subgraph isomorphism
- Subgraph matching with constraints
Graph Alignment
- IsoRank spectral alignment (Kronecker product power iteration)
- GRASP (greedy randomized construction + local search) alignment
Graph Signal Processing
- Graph Fourier transform
- Graph wavelets
- Graph filtering in spectral domain
Network Analysis
- Graph diameter, radius, density
- Clustering coefficient (local and global)
- Average shortest path length
- Small-world metrics
- Network robustness and reliability analysis
- Social network analysis (influence propagation, role detection)
Graph Generators
- Erdos-Renyi random graphs
- Barabasi-Albert (preferential attachment)
- Watts-Strogatz (small-world)
- Regular graphs, complete graphs, path graphs, cycle graphs
- Grid graphs, tree generators
Graph I/O
- GraphML, GML, DOT (Graphviz), JSON
- Edge list and adjacency list formats
- Matrix Market for sparse representations
Graph Visualization
- SVG output with customizable layouts
- DOT format for Graphviz rendering
- Force-directed, circular, hierarchical layouts
Large-Scale Partitioning and Distributed Storage
- Multilevel k-way partitioning (METIS-style coarsen/uncoarsen/refine)
- Streaming partitioning for dynamic graphs
- Distributed graph shards with hash and Fennel partitioning
Graph Condensation
- Coreset selection (k-center, importance sampling, kernel herding)
- Gradient-matching graph distillation
- Condensation-quality evaluation (degree/spectral distance, label coverage)
Additional Features
- Domination problems (dominating sets, independent sets)
- Planarity testing
- Algebraic graph theory
- Reliability and robustness analysis
- Sampling algorithms for large graphs
Installation
[]
= "0.6.2"
For parallel processing support:
[]
= { = "0.6.2", = ["parallel"] }
Quick Start
Basic Graph Operations
use ;
Community Detection
use ;
use barabasi_albert_graph;
Graph Neural Networks
use ;
Node2Vec Embeddings
use ;
use Result;
Subgraph Isomorphism (VF2)
use vf2_subgraph_isomorphism;
use Result;
Graph Visualization
use ;
use ;
Temporal Graphs
use ;
GPU Acceleration (v0.5.0)
scirs2-graph provides real wgpu GPU dispatch for large-scale graph traversal and shortest paths (feature wgpu):
| Algorithm | Implementation |
|---|---|
| BFS | WGSL level-sync kernel with atomicCompareExchange on distances; CPU fallback for n_edges < 4096 |
| Bellman-Ford SSSP | WGSL edge-parallel kernel with atomicMin (f32-bits trick); handles non-negative weights |
| Delta-stepping SSSP | True WGSL bucket-based relaxation: DELTA_LIGHT_WGSL + DELTA_APPLY_WGSL + DELTA_HEAVY_WGSL with changed_flag convergence; adaptive delta heuristic |
| CPU-parallel BFS | parallel_bfs_atomic via rayon + AtomicI32 distance array |
| CPU-parallel Bellman-Ford | parallel_bellman_ford_atomic via rayon + AtomicU32 (f32 bits) |
All GPU algorithms gracefully skip to CPU when no wgpu adapter is available (tested on Darwin Metal and Linux Vulkan).
Feature Flags
| Flag | Description |
|---|---|
parallel |
Enable Rayon-based parallel processing for large graph algorithms |
simd |
Enable SIMD-accelerated numerical operations |
wgpu |
Enable wgpu GPU dispatch for BFS, SSSP, delta-stepping (requires wgpu/pollster/bytemuck) |
cuda |
Off-by-default, NVIDIA-only CUDA CSR SpMV for graph adjacency matrices via the pure-Rust oxicuda-* crates; runtime-probed, falls back to CPU when no NVIDIA device is present (e.g. macOS) |
Performance
- Multi-threaded algorithms via Rayon for large graphs (millions of nodes/edges)
- GPU dispatch (wgpu) for BFS and SSSP on large graphs (n_edges ≥ 4096)
- CSR representation for cache-efficient traversal
- Memory profiling tools built in
- Validated against NetworkX and igraph reference implementations
- 10-50x faster than NetworkX for most core operations
Documentation
Full API reference: docs.rs/scirs2-graph
License
Licensed under the Apache License 2.0. See LICENSE for details.