Skip to content

NetworkX Adapter

NetworkX conversion helpers from annnet.adapters.networkx_adapter.

annnet.adapters.networkx_adapter

Classes

Functions

to_nx
to_nx(
    graph,
    directed=True,
    hyperedge_mode="skip",
    slice=None,
    slices=None,
    public_only=False,
    reify_prefix="he::",
)

Export AnnNet → (networkx.AnnNet, manifest).

Manifest preserves hyperedges with per-endpoint coefficients, slices, vertex/edge attrs, and stable edge IDs.

Parameters:

Name Type Description Default
graph AnnNet
required
directed bool
True
hyperedge_mode ('skip', 'expand', 'reify')
"skip"
slice str

Export single slice only (affects which hyperedges are reified).

None
slices list[str]

Export union of specified slices (affects which hyperedges are reified).

None
public_only bool
False

Returns:

Type Description
tuple[AnnNet, dict]

(nxG, manifest)

from_nx
from_nx(
    nxG,
    manifest,
    *,
    hyperedge="none",
    he_node_flag="is_hyperedge",
    he_id_attr="eid",
    role_attr="role",
    coeff_attr="coeff",
    membership_attr="membership_of",
    reify_prefix="he::"
)

Reconstruct a AnnNet from NetworkX graph + manifest.

hyperedge: "none" (default) | "reified" When "reified", also detect hyperedge nodes in nxG and rebuild true hyperedges (in addition to those specified in the manifest).