Skip to content

BaseDataset

BaseDataset(
    name: str,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
)

Bases: ABC

Abstract base class for datasets.

Parameters:

Name Type Description Default
name str

The name of the dataset.

required
base_dir Optional[str]

The base directory where the dataset is stored. Default is in the local directory .mlx_graphs_data/.

None
pre_transform Optional[Callable]

A function to apply as a pre-transform to each graph in the dataset. Defaults to None.

None
transform

A function to apply as a transform to each graph in the dataset. Defaults to None.

required

Methods:

Name Description
download

Download the dataset at self.raw_path.

process

Process the dataset and store data in self.data

save

Save the processed dataset

load

Load the processed dataset

Attributes:

Name Type Description
name str

Name of the dataset

raw_path str

The path where raw files are stored.

processed_path str

The path where processed files are stored.

num_items int

Returns the number of items in the dataset.

Source code in mlx_graphs/datasets/base_dataset.py
def __init__(
    self,
    name: str,
    base_dir: Optional[str] = None,
    pre_transform: Optional[Callable] = None,
    transform: Optional[Callable] = None,
):
    self._name = name
    self._base_dir = base_dir if base_dir else DEFAULT_BASE_DIR
    self.transform = transform
    self.pre_transform = pre_transform
    self.graphs = []
    self._load()

name property

name: str

Name of the dataset

raw_path property

raw_path: str

The path where raw files are stored.

processed_path property

processed_path: str

The path where processed files are stored.

num_items property

num_items: int

Returns the number of items in the dataset.

download abstractmethod

download()

Download the dataset at self.raw_path.

Source code in mlx_graphs/datasets/base_dataset.py
@abstractmethod
def download(self):
    """Download the dataset at `self.raw_path`."""
    pass

process abstractmethod

process()

Process the dataset and store data in self.data

Source code in mlx_graphs/datasets/base_dataset.py
@abstractmethod
def process(self):
    """Process the dataset and store data in `self.data`"""
    pass

save

save()

Save the processed dataset

Source code in mlx_graphs/datasets/base_dataset.py
def save(self):
    """Save the processed dataset"""
    with open(os.path.join(self.processed_path, "graphs.pkl"), "wb") as f:
        pickle.dump(self.graphs, f)

load

load()

Load the processed dataset

Source code in mlx_graphs/datasets/base_dataset.py
def load(self):
    """Load the processed dataset"""
    with open(os.path.join(self.processed_path, "graphs.pkl"), "rb") as f:
        obj = pickle.load(f)  # nosec B301 - own pickle from save_graphs()
        self.graphs = obj

from mlx_graphs.datasets import BaseDataset · mlx_graphs/datasets/base_dataset.py