Storing a Graph to Disk

This guide will explain to you how a graph loaded into memory can be saved to disk in various formats. By doing this, you can make sub-graphs and graph data computed at runtime through analytics persistent, for future use. The resulting file can be used later as input for PGX.

First, load a graph into memory and perform a PageRank analysis on it, to provide something interesting to save. To do so, you need create a new vertex property that will receive the PageRank values:

1graph = session.read_graph_with_properties(self.graph_path)
2analyst = session.create_analyst()
3rank = analyst.pagerank(graph, 0.001, 0.85, 100)

Next, store the graph, together with the result of the PageRank analysis and all original edge properties, as a file in edge-list format, on disk. When a graph is stored, you need to specify the graph format, a path where the file should be stored, the properties to store and a flag that specifies whether or not a file should be overwritten should a file with the same name already exist.

1config = graph.store(
2    'edge_list',
3    "/tmp/sample_pagerank.elist",
4    vertex_properties=[rank],
5    overwrite=True
6)

The graph data can now be found under /tmp/connections_pagerank.elist. The graph configuration returned by the store() method can be used to load the new graph back into memory. To persist the graph configuration to disk as well, you can use the config’s str() representation to get a JSON representation:

1with open("/tmp/connections_pagerank.elist.json", "w") as f:
2    f.write(str(config))