Storing and Serializing Graphs

We store graphs in GraphStorage objects. These objects are safely serializable and can be indexed efficiently to retrieve PyTorch Geometric Data objects.

polygraph.datasets.base.GraphStorage

Bases: BaseModel

Serializable collection of graphs.

Attributes:
  • description (Optional[str]) –

    Optional description of the collection of graphs.

  • module_version (Optional[str]) –

    Version of the polygraph package that created the GraphStorage object.

  • extra_data (Any) –

    Any additional primitive metadata.

from_nx_graphs(graphs, edge_attrs=None, node_attrs=None, graph_attrs=None) staticmethod

Construct a GraphStorage object from a sequence of NetworkX graphs.

The specified attributes must be numpy arrays and must have consistent dimensions across all graphs and nodes/edges.

Parameters:
  • graphs (Sequence[Graph]) –

    List or tuple of NetworkX graphs.

  • edge_attrs (Optional[List[str]], default: None ) –

    List of edge-level attributes to include, must be present in each networkx graph.

  • node_attrs (Optional[List[str]], default: None ) –

    List of node-level attributes to include, must be present in each networkx graph.

  • graph_attrs (Optional[List[str]], default: None ) –

    List of graph-level attributes to include, must be present in each networkx graph.

from_pyg_batch(batch, edge_attrs=None, node_attrs=None, graph_attrs=None) staticmethod

Construct a GraphStorage object from a PyTorch Geometric Batch object.

Parameters:
  • batch (Batch) –

    PyTorch Geometric Batch object.

  • edge_attrs (Optional[List[str]], default: None ) –

    List of edge-level attributes to include, must be present in the Batch object.

  • node_attrs (Optional[List[str]], default: None ) –

    List of node-level attributes to include, must be present in the Batch object.

  • graph_attrs (Optional[List[str]], default: None ) –

    List of graph-level attributes to include, must be present in the Batch object.

get_example(idx)

Retrieve a single graph from the collection.

Parameters:
  • idx (int) –

    Index of the graph to retrieve.

Returns:
  • Data

    PyTorch Geometric Data object containing the graph.

__len__()

Number of graphs in the collection.