Skip to content

feat(base_graph): add topology queries, hypergraph incidence/adjacency matrix exports, and serialization - #74

Open
ashishsoni-ai wants to merge 1 commit into
DevoLearn:mainfrom
ashishsoni-ai:feat/base-graph-methods-and-matrices
Open

ashishsoni-ai wants to merge 1 commit into
DevoLearn:mainfrom
ashishsoni-ai:feat/base-graph-methods-and-matrices

Conversation

@ashishsoni-ai

Copy link
Copy Markdown

Description

This PR enhances \devograph.base_graph.BaseGraph, the core graph data structure in DevoGraph, by adding essential topology query methods, hypergraph matrix representations for GNN models, removal operations, and serialization support.

Previously, \BaseGraph\ provided only basic \�dd_node, \�dd_edge,
um_nodes, and
um_edges. Downstream pipelines in DevoGraph (such as \Dynamic-HGNN\ and \HyperDevoGraph) require querying node neighborhoods, computing node degrees, generating hypergraph incidence matrices, and exporting PyG-compatible edge indices.

Changes Made

  1. Node and Edge Queries:

    • \has_node(node_id): verify node membership.
    • \get_node(node_id): retrieve node attribute dictionary.
    • \get_nodes(): list all node IDs.
    • \has_edge(node_ids): check for the existence of an edge or hyperedge.
    • \get_edge(index)\ and \get_edges(): access edge records.
  2. Graph Topology Operations:


    • eighbors(node_id): retrieve all neighboring nodes connected via pairwise edges or multi-node hyperedges.
    • \degree(node_id): count incident edges / hyperedges for a node.
    • \incident_edges(node_id): list edge indices incident to a given node.

    • emove_node(node_id): remove a node and prune all incident edges.

    • emove_edge(index): remove an edge by index.
  3. Hypergraph & GNN Matrix Exports:

    • \ o_incidence_matrix(): returns an (N, E)\ binary matrix (H) where (H_{i, j} = 1) if node (i) belongs to edge/hyperedge (j). This directly supports Hypergraph Neural Networks (HGNN / Hyper-SAGNN).
    • \ o_adjacency_matrix(weighted=False): generates an (N, N)\ adjacency matrix using clique expansion for hyperedges of size > 2.
    • \ o_edge_index(bidirectional=True): exports edge index array of shape (2, E)\ in PyTorch Geometric (PyG) format.
  4. Serialization & Magic Methods:

    • \ o_dict()\ and \ rom_dict(): serialization round-trip to easily save/load graphs in JSON/dict format.
    • _len_(): returns node count.
    • _repr_(): clean string representation (\BaseGraph(num_nodes=..., num_edges=...)).
  5. Top-Level Package Export:

    • Exported \BaseGraph\ in \devograph/init.py\ for \ rom devograph import BaseGraph.
  6. Comprehensive Unit Testing:

    • Added 9 unit tests in \ est/test_base_graph.py\ verifying all query methods, matrix conversions, hyperedge handling, error checks, and dictionary round-trip serialization.
    • All tests pass: \pytest test/test_base_graph.py.

…y matrix exports, and serialization

- Implemented node and edge query methods: has_node, get_node, get_nodes, has_edge, get_edge, get_edges.
- Added graph topology operations: neighbors, degree, incident_edges, remove_node (with automatic incident edge pruning), and remove_edge.
- Added hypergraph and GNN export utilities:
  * to_incidence_matrix: generates (N, E) node-edge incidence matrix for Hyper-SAGNN and HGNN models.
  * to_adjacency_matrix: computes (N, N) binary/weighted adjacency matrix with hyperedge clique expansion.
  * to_edge_index: exports PyG-style (2, E) edge index for GNN pipelines.
- Added dictionary serialization: to_dict and from_dict.
- Added __len__ and __repr__ for clean Pythonic representation.
- Exported BaseGraph at top-level devograph module.
- Added comprehensive unit tests in test/test_base_graph.py covering all added functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant