Skip to content

MemmapGraphStore

MemmapGraphStore(root: str)

Bases: GraphStore

A GraphStore keeping its edges in .npy files, read through memory mapping, so that a graph converted once (e.g. to CSC) can be reopened instantly, without parsing or sorting its edges again.

Only homogeneous graphs (edge_type=None) and string edge types are supported. Files are <root>/<edge_type or "_">.{0,1}.npy plus a <root>/edges.json index.

Example:

from mlx_graphs.data import MemmapGraphStore

store = MemmapGraphStore("graph/")
colptr, row, perm = InMemoryGraphStore.from_data(data).csc()
store.put_edge_index((row, colptr), layout="csc", size=(n, n))

# later, in another process
store = MemmapGraphStore("graph/")
colptr, row, _ = store.csc()

Parameters:

Name Type Description Default
root str

Directory of the store (created if needed).

required
Source code in mlx_graphs/data/graph_store.py
def __init__(self, root: str):
    super().__init__()
    self.root = os.path.expanduser(root)
    os.makedirs(self.root, exist_ok=True)
    self._attrs: dict[Any, EdgeAttr] = {}
    index = os.path.join(self.root, "edges.json")
    if os.path.exists(index):
        with open(index) as f:
            for entry in json.load(f):
                attr = EdgeAttr(**entry)
                self._attrs[attr.edge_type] = attr

from mlx_graphs.data import MemmapGraphStore · mlx_graphs/data/graph_store.py