hypergraph-rs
A hypergraph library for Rust. A hypergraph is a graph whose edges can join any number of nodes, not just two.
It is a port of XGI, the Python hypergraph library, and it builds on rustworkx-core. A hypergraph is stored as a bipartite graph, so the algorithms of rustworkx-core work on it. Node and edge ids are strings. Every listing keeps the order in which things were added, so the same steps always give the same output.
What it is, and what it is not
It has:
- an undirected
Hypergraph, a directedDiHypergraph(each edge has a tail and a head) and aSimplicialComplex; - a value on every membership, which XGI does not have (see below);
- algorithms, statistics, generators, readers and writers, layouts, conversions, Kuramoto dynamics, spectral clustering, and a text and PNG rasterizer, each behind a feature flag.
It is not all of XGI. The symbols of XGI that are not ported are listed in
tests/DEFERRED_SYMBOLS.md. It does not draw with matplotlib, and it has no pandas
conversions. The hypergraph-rs-cli and hypergraph-rs-wasm crates in this repository are
stubs: they do nothing yet.
Use it
Add it from crates.io:
To follow main between releases, depend on it from git, and pin a commit with rev = "..."
if you want a build that does not move:
[]
= { = "https://github.com/percy-raskova/hypergraph-rs" }
The API reference is on docs.rs. Only the core crate is published; the other crates in this repository are not.
Quick start
use number_connected_components;
use Hypergraph;
// Nodes, edges and memberships carry no value here, so all three types are `()`.
let mut h: = new;
// An edge joins any number of nodes. Nodes that do not exist yet are created.
h.add_edge
.unwrap;
h.add_edge
.unwrap;
h.add_edge
.unwrap;
// Listings keep the order in which things were added.
assert_eq!;
assert_eq!;
assert_eq!;
// One statistic: "pair" shares no member with the other two edges, so there are
// two connected components.
assert_eq!;
The same code runs as cargo run -p hypergraph-rs --example quickstart.
The statistics in hypergraph_rs::stats, the readers and writers, and the conversions work
on the default type, Hypergraph, which carries a JSON value on every node, edge and
membership. The algorithms work on any type.
Feature flags
The default features are algorithms, generators, stats, readwrite, layout, viz,
raster and geometry. Every feature builds on its own, without the defaults.
| Feature | Turns on |
|---|---|
algorithms |
connected components, shortest paths, clustering, centrality, assortativity, simpliciality |
generators |
classic, random, lattice, uniform and simplicial generators, all 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 |
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: it is the third type parameter, and a new
membership carries M::default().
use Hypergraph;
let mut h: = new;
h.add_node_to_edge_with_data.unwrap;
h.add_node_to_edge_with_data.unwrap;
h.set_member_data.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
On DiHypergraph, member_data, set_member_data and add_node_to_edge_with_data also take
the role (DiRole::Tail or DiRole::Head), and dimembers_with_data(edge_id) returns the tail
and the head lists together. The XGI-compatible formats, the Python package and the WASM bindings
do not carry the value. See cargo run -p hypergraph-rs --example membership_data.
Python
A Python package follows XGI's names. It is built from crates/hypergraph-rs-python with
maturin. A conformance gate replays XGI's own test suite against it
and checks it against XGI, pinned at exactly 1.1: run it with mise run py:gate (it needs a
.venv with XGI and the test tools, as .github/workflows/ci.yml sets one up). Nothing is
published to PyPI.
The copied tests in tests/ported carry XGI's license in tests/ported/LICENSE-XGI.md. The
known differences from XGI are measured in compat/divergences.toml. Three parts of XGI 1.1
are not mirrored yet, each the subject of a later plan: the online data loaders, user-defined
statistics (nodestat_func and its siblings), and XGI's documentation examples run as tests.
Drawing with matplotlib and xgi.skill are out of scope. CHANGELOG.md lists the rest.
Bevy
crates/hypergraph-rs-bevy draws a hypergraph in Bevy 0.20.1: a ground
of regions, hatched outlines of hyperedges, particles, and marks that move along paths in
beats. It turns on only the Bevy features std and bevy_pbr (its example adds
bevy_winit, x11 and multi_threaded). It has its own minimum Rust version, 1.97.1
(Bevy's), and is not published. Its
README says how to use it and how to run the example.
Rust version
The minimum Rust version is 1.90, for the workspace and for every feature of the core crate.
It is the lowest version the newest dependencies allow, and it rises when they need it.
rust-toolchain.toml pins the toolchain used for development, 1.100.0. mise run rust:msrv
checks the floor. The Bevy crate has its own floor, 1.97.1, which mise run rust:bevy
checks.
Checks
Run these with mise:
mise run rust:check: format, lint, tests and docs, then the same with every feature on, then every feature alone. CI runs the same task.mise run rust:msrv: the build at the minimum Rust version.mise run rust:bevy: the Bevy crate, in its own job, then the build at its own floor.mise run py:gate: the XGI conformance gate.cargo deny check: advisories, licenses and sources.
CONTRIBUTING.md has more.
Security
To report a vulnerability, see SECURITY.md.
License
BSD-3-Clause, the same license as XGI. See LICENSE. The crate is a port of XGI, so it also
carries XGI's license, in crates/hypergraph-rs/LICENSE-XGI.md.