Skip to content

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.

Terminal window
pip install "hypermesh[interop]" # numpy + scipy + networkx + hypernetx + xgi
pip 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 snapshot
g = hm.interop.to_networkx(db, table="CoProximity") # straight from a Connection
FunctionReturnsNotes
to_networkx(hg, kind="bipartite")networkx.GraphLossless star expansion (node ↔ hyperedge incidence).
to_networkx(hg, kind="clique")networkx.GraphWeighted two-section (clique) expansion; lossy.
to_hypernetx(hg)hypernetx.HypergraphEdge props: weight, event_ts, size.
to_xgi(hg)xgi.HypergraphInteger edge ids, same edge attributes.
to_pandas(hg, orient="edgelist")pandas.DataFrameOne row per incidence: edge, node, weight, event_ts.
to_pandas(hg, orient="incidence")pandas.DataFrameDense n_nodes × n_edges 0/1 matrix.
g = hm.interop.to_networkx(hg) # bipartite by default
import networkx as nx
print(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 DataFrame

In the bipartite projection the two node populations share one graph, so IDs are prefixed to avoid collisions:

  • member nodes → "n{node_id}" with bipartite=0, kind="node"
  • hyperedge nodes → "e{j}" with bipartite=1, kind="hyperedge" and the weight / event_ts / size attributes.

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") # export
hg2 = hm.interop.read_hif("graph.hif.json") # import → HypergraphPy
doc = hm.interop.to_hif(hg) # in-memory dict
hg3 = hm.interop.from_hif(doc) # rebuild from dict/JSON str

The document carries incidences, per-edge attrs (weight, event_ts, size), and a nodes list so isolated nodes survive the round-trip.

hm.interop.to_graphml(hg, "graph.graphml") # bipartite
hm.interop.to_graphml(hg, "clique.graphml", kind="clique") # two-section

GraphML is written through the NetworkX projection, so it opens directly in Gephi, yEd, Cytoscape and similar tools.

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)