Skip to content

PyTorch Geometric Adapter

PyG conversion helpers from annnet.adapters.pyg_adapter.

annnet.adapters.pyg_adapter

AnnNet-PyTorch Geometric adapter for AnnNet.

Provides: to_pyg(G) -> torch_geometric.data.HeteroData

PyTorch Geometric represents graph data as tensors. This adapter exports AnnNet vertices and edges into a heterogeneous graph structure suitable for downstream GNN workflows.

AnnNet-specific structures such as slices, multilayer metadata, hyperedge semantics, and rich attribute tables are only exported where they can be mapped to tensor-compatible node, edge, or graph-level fields.

Classes

Functions

to_pyg
to_pyg(
    graph,
    node_features=None,
    edge_features=None,
    slice_id=None,
    hyperedge_mode="reify",
    device="cpu",
)

Export AnnNet → torch_geometric.data.HeteroData.

Builds a heterogeneous graph: vertices are grouped into node types by their kind attribute and edges into relation types by their endpoint kinds, so AnnNet's entity/edge typing is preserved. Selected vertex/edge attribute columns become node/edge feature tensors, and slice membership is carried as boolean masks. Hyperedges have no native PyG equivalent and are handled per hyperedge_mode.

Parameters:

Name Type Description Default
graph AnnNet
required
node_features dict[str, list[str]]

Per node-kind, the vertex-attribute columns to stack into the node feature tensor x. Kinds absent from the mapping get no features.

None
edge_features dict[tuple[str, str, str], list[str]]

Per relation triple (src_kind, relation, dst_kind), the edge-attribute columns to stack into edge_attr.

None
slice_id str

Slice to export; defaults to the graph's active slice (graph.slices.active).

None
hyperedge_mode ('reify', 'expand', 'skip')
  • "reify": add a node per hyperedge plus membership edges carrying per-endpoint roles/coefficients.
  • "expand": replace each hyperedge with binary edges over its endpoints.
  • "skip": drop hyperedges (kept only in the manifest).
"reify"
device str

Torch device the returned tensors are allocated on.

"cpu"

Returns:

Type Description
HeteroData

Heterogeneous graph with per-type x / edge_index / edge_attr and slice masks.