Skip to content

graph-tool adapter

Convert between an AnnNet object and a graph-tool graph. graph-tool holds nodes and binary edges, with one direction for the whole graph and a weight edge property. to_graphtool also gives back a manifest with everything else: hyperedges, the direction of each edge, layers, slices and the attribute tables. Give the manifest to from_graphtool to rebuild the full graph. graph-tool is not on PyPI: install it with conda or your system package manager. To run a graph-tool algorithm without converting yourself, use anet.gt.

annnet.adapters.graphtool_adapter.from_graphtool

from_graphtool(
    gtG,
    manifest=None,
    *,
    node_id_property="id",
    edge_id_property="id",
    weight_property="weight"
)

Convert graph_tool.AnnNet (+ optional manifest) back into AnnNet AnnNet.

  • Nodes: from node property node_id_property if present, else numeric index.
  • Edges: from edges in gtG; edge_id from edge property edge_id_property if present, else auto; weight from edge property weight_property if present, else 1.0.

If manifest is provided, rehydrates: - all attribute tables (node/edge/slice/edge_slice/layer), - _slices internal structure, - hyperedges, - edge_directed and edge_direction_policy, - multilayer (aspects, elem_layers, VM, aspect attrs, layer-tuple attrs, edge_kind, edge_layers, node-layer attrs), - graph_attributes.

annnet.adapters.graphtool_adapter.to_graphtool

to_graphtool(
    G,
    *,
    node_id_property="id",
    edge_id_property="id",
    weight_property="weight"
)

Convert an AnnNet AnnNet -> (graph_tool.AnnNet, manifest).

graph-tool graph: - nodes: only entities whose kind is a node - edges: only binary edges whose endpoints are such nodes - node property vp[node_id_property] = AnnNet node id - edge property ep[edge_id_property] = AnnNet edge id - edge property ep[weight_property] = edge weight (float)

manifest: - preserves everything graph-tool cannot: hyperedges, slices, multilayer, and ALL attribute tables.