Expand description
§hypergraph-rs
A hypergraph library for Rust. A hypergraph is a graph whose edges can join any number of nodes, not just two. This crate is a port of XGI, the Python hypergraph library, and it builds on rustworkx-core. Node and edge ids are strings, and every listing keeps the order in which things were added.
Add it with cargo add hypergraph-rs.
§Quick start
use hypergraph_rs::algorithms::connected::number_connected_components;
use hypergraph_rs::Hypergraph;
// Nodes, edges and memberships carry no value here, so all three types are `()`.
let mut h: Hypergraph<(), (), ()> = Hypergraph::new();
// An edge joins any number of nodes. Nodes that do not exist yet are created.
h.add_edge(
vec!["ana".into(), "bo".into(), "cy".into()],
Some("club".into()),
(),
)
.unwrap();
h.add_edge(
vec!["bo".into(), "cy".into(), "di".into(), "ed".into()],
Some("choir".into()),
(),
)
.unwrap();
h.add_edge(vec!["fay".into(), "gus".into()], Some("pair".into()), ())
.unwrap();
// Listings keep the order in which things were added.
assert_eq!(h.node_ids(), ["ana", "bo", "cy", "di", "ed", "fay", "gus"]);
assert_eq!(h.members("choir").unwrap(), ["bo", "cy", "di", "ed"]);
assert_eq!(h.memberships("bo").unwrap(), ["club", "choir"]);
// One statistic: "pair" shares no member with the other two edges, so there are
// two connected components.
assert_eq!(number_connected_components(&h), 2);§What is in it
Hypergraph: undirected edges.DiHypergraph: each edge has a tail and a head.SimplicialComplex: a hypergraph that keeps every subface of each simplex.- A hypergraph has three type parameters: the value on a node, on an edge and on a membership. Each defaults to a JSON value. The statistics, readers, writers and conversions work on that default type.
- Modules, switched by the feature flags below:
algorithms,generators,stats,readwrite,layout,viz,raster,geometry,convert,dynamics,communities. The modulescore,linalgandutilsare always there.
§A value on a membership
A membership is the fact that one node belongs to one edge. XGI has no value on a
membership. The membership value is this crate’s own addition: the third type parameter,
read and written with member_data, set_member_data, members_with_data and
add_node_to_edge_with_data (on DiHypergraph, member_data, set_member_data and
add_node_to_edge_with_data also take the role, and dimembers_with_data lists the tail
and the head together). A new membership carries M::default(). The XGI-compatible
formats, the Python package and the WASM bindings do not carry the value.
use hypergraph_rs::Hypergraph;
let mut h: Hypergraph<(), (), u64> = Hypergraph::new();
h.add_node_to_edge_with_data("council", "teachers", 3).unwrap();
h.add_node_to_edge_with_data("union", "teachers", 40).unwrap();
assert_eq!(h.member_data("council", "teachers"), Some(&3));
assert_eq!(h.member_data("union", "teachers"), Some(&40));§Feature flags
The default features are algorithms, generators, stats, readwrite, layout,
viz, raster and geometry.
| Feature | Turns on |
|---|---|
algorithms | connected components, shortest paths, clustering, centrality, assortativity, simpliciality |
generators | classic, random, lattice, uniform and simplicial generators (seeded) |
stats | node and edge statistics, for the default type of hypergraph |
readwrite | edge list, bipartite edge list, JSON, HIF and incidence matrix readers and writers, and a BiGG dictionary reader |
layout | deterministic layouts: node positions and the shape drawn for each edge |
viz | a scene graph built from a layout, with JSON and SVG output (needs layout) |
raster | the base of the terminal-text rasterizer (needs viz and algorithms) |
dynamics | Kuramoto synchronization |
communities | spectral clustering |
convert | conversions between hypergraphs and edge lists, dictionaries and graphs |
network | declares readwrite::bigg::load_bigg_data, which is not implemented and always returns an error |
cells3d | hexagonal-cell scenes and instruments for the rasterizer (needs raster, communities and the h3o crate) |
raster-png | PNG output for the rasterizer (needs cells3d and the png crate) |
geometry | outlines of a weighted set (ring, capsule, membrane), placement at a weighted mix of fixed points, spreading in fixed steps; the same bits on every machine |
all | every feature above |
Every feature builds on its own, without the defaults.
§Minimum Rust version
Rust 1.90, for the workspace and for every feature of this crate.
Re-exports§
pub use core::dihypergraph::DiHypergraph;pub use core::error::EdgeError;pub use core::error::MembershipError;pub use core::error::NodeError;pub use core::error::SimplexError;pub use core::error::SwapError;pub use core::globalviews::subhypergraph;pub use core::hypergraph::CleanupOptions;pub use core::hypergraph::Hypergraph;pub use core::hypergraph::MergeRename;pub use core::hypergraph::MergeRule;pub use core::kinds::DiMembershipEdge;pub use core::kinds::DiRole;pub use core::kinds::MembershipEdge;pub use core::kinds::NodeKind;pub use core::simplicialcomplex::FaceLattice;pub use core::simplicialcomplex::SimplicialComplex;pub use core::views::EdgeView;pub use core::views::FilterMode;pub use core::views::NodeView;
Modules§
- algorithms
algorithms - Hypergraph algorithms. All functions take
&Hypergraph<N,E,M>first. - communities
communities - Spectral community detection ported from
xgi/communities/spectral.py. - convert
convert - Conversions to/from hyperedge lists/dicts, bipartite edgelists, bipartite petgraph graphs, the 1-skeleton graph, and order-cutting. (XGI 1.0 dropped its hypergraph dict; so did this module.)
- core
- Core hypergraph data structures.
- dynamics
dynamics - Kuramoto synchronization dynamics, first ported from
xgi/dynamics/synchronization.py. - generators
generators - Hypergraph generators (XGI
xgi/generators/*.pyport). - geometry
geometry - Geometry for weighted sets and fixed placements.
- layout
layout - Deterministic hypergraph layout: node positions + per-hyperedge geometry.
- linalg
- Matrices derived from the bipartite hypergraph substrate.
- raster
raster - Deterministic 3D-scene → terminal-text rasterizer (Phase R, PHASE-R-MAP §3/§4).
- readwrite
readwrite - Read/write hypergraphs in various formats (XGI
xgi/readwrite/*.pyport). - stats
stats - Node/edge statistics (XGI
xgi/stats/*.pyport). - utils
- Pure utility functions ported from
xgi/utils/(non-Python-machinery only). - viz
viz - Scene-graph serializer: the matplotlib-free rendering contract (spec §5.3).