Interoperability
hypermesh.interop bridges a HyperMesh hypergraph snapshot to the wider
network-science ecosystem and to portable, library-agnostic exchange formats.
This makes HyperMesh a first-class citizen alongside NetworkX, HyperNetX and
XGI, and lets researchers move data in and out without lock-in.
pip install "hypermesh[interop]" # numpy + scipy + networkx + hypernetx + xgipip install "hypermesh[pandas]" # for to_pandas()Every exporter takes either a HypergraphPy snapshot or an embedded
Connection (with table=):
import hypermesh as hm
db = hm.connect("/var/lib/hypermesh/data")hg = db.to_hypergraph("CoProximity") # explicit snapshot
g = hm.interop.to_networkx(hg) # from a snapshotg = hm.interop.to_networkx(db, table="CoProximity") # straight from a ConnectionLibrary bridges
Section titled “Library bridges”| Function | Returns | Notes |
|---|---|---|
to_networkx(hg, kind="bipartite") | networkx.Graph | Lossless star expansion (node ↔ hyperedge incidence). |
to_networkx(hg, kind="clique") | networkx.Graph | Weighted two-section (clique) expansion; lossy. |
to_hypernetx(hg) | hypernetx.Hypergraph | Edge props: weight, event_ts, size. |
to_xgi(hg) | xgi.Hypergraph | Integer edge ids, same edge attributes. |
to_pandas(hg, orient="edgelist") | pandas.DataFrame | One row per incidence: edge, node, weight, event_ts. |
to_pandas(hg, orient="incidence") | pandas.DataFrame | Dense n_nodes × n_edges 0/1 matrix. |
g = hm.interop.to_networkx(hg) # bipartite by defaultimport networkx as nxprint(nx.density(g))
clq = hm.interop.to_networkx(hg, kind="clique")H = hm.interop.to_hypernetx(hg)X = hm.interop.to_xgi(hg)df = hm.interop.to_pandas(hg) # edge-list DataFrameNetworkX node namespaces
Section titled “NetworkX node namespaces”In the bipartite projection the two node populations share one graph, so IDs are prefixed to avoid collisions:
- member nodes →
"n{node_id}"withbipartite=0,kind="node" - hyperedge nodes →
"e{j}"withbipartite=1,kind="hyperedge"and theweight/event_ts/sizeattributes.
Exchange formats
Section titled “Exchange formats”HIF — Hypergraph Interchange Format
Section titled “HIF — Hypergraph Interchange Format”HIF is the portable JSON standard shared by HyperNetX, XGI and others. Round-trips through HyperMesh cleanly:
hm.interop.write_hif(hg, "graph.hif.json") # exporthg2 = hm.interop.read_hif("graph.hif.json") # import → HypergraphPy
doc = hm.interop.to_hif(hg) # in-memory dicthg3 = hm.interop.from_hif(doc) # rebuild from dict/JSON strThe document carries incidences, per-edge attrs (weight, event_ts,
size), and a nodes list so isolated nodes survive the round-trip.
GraphML
Section titled “GraphML”hm.interop.to_graphml(hg, "graph.graphml") # bipartitehm.interop.to_graphml(hg, "clique.graphml", kind="clique") # two-sectionGraphML is written through the NetworkX projection, so it opens directly in Gephi, yEd, Cytoscape and similar tools.
Remote clients
Section titled “Remote clients”Interop builds the hypergraph in-process and therefore needs an embedded
Connection. From a remote Client, fetch rows and build the snapshot
yourself:
from hypermesh.analytics import build_hypergraph
rows = list(client.execute("MATCH HYPEREDGE (he:CoProximity) RETURN *"))hg = build_hypergraph(rows)g = hm.interop.to_networkx(hg)