czbenchmarks.datasets.base

Classes

BaseDataset

Helper class that provides a standard way to create an ABC using

Module Contents

class czbenchmarks.datasets.base.BaseDataset(path: str, **kwargs: Any)[source]

Bases: abc.ABC

Helper class that provides a standard way to create an ABC using inheritance.

path
kwargs
property inputs: Dict[czbenchmarks.datasets.types.DataType, czbenchmarks.datasets.types.DataValue]

Get the inputs dictionary.

property outputs: czbenchmarks.models.types.ModelOutputs

Get the outputs dictionary.

set_input(data_type: czbenchmarks.datasets.types.DataType, value: czbenchmarks.datasets.types.DataValue) None[source]

Safely set an input with type checking.

set_output(model_type: czbenchmarks.models.types.ModelType | None, data_type: czbenchmarks.datasets.types.DataType, value: czbenchmarks.datasets.types.DataValue) None[source]

Safely set an output with type checking. :param model_type: The type of model associated with the output.

This parameter is used to differentiate between outputs from various models. It can be set to None if the output is not tied to a specific model type defined in the ModelType enum.

Parameters:
  • data_type (DataType) – Specifies the data type of the output.

  • value (Any) – The value to assign to the output.

get_input(data_type: czbenchmarks.datasets.types.DataType) czbenchmarks.datasets.types.DataValue[source]

Safely get an input with error handling.

get_output(model_type: czbenchmarks.models.types.ModelType | None, data_type: czbenchmarks.datasets.types.DataType) czbenchmarks.datasets.types.DataValue[source]

Safely get an output with error handling. :param model_type: The type of model associated with the output.

This parameter is used to differentiate between outputs from various models. It can be set to None if the output is not tied to a specific model type defined in the ModelType enum.

Parameters:

data_type (DataType) – Specifies the data type of the output.

Returns:

The value of the output.

Return type:

DataValue

validate() None[source]

Validate that all inputs and outputs match their expected types

abstract load_data() None[source]

Load the dataset into memory.

This method should be implemented by subclasses to load their specific data format. For example, SingleCellDataset loads an AnnData object from an h5ad file.

The loaded data should be stored as instance attributes that can be accessed by other methods.

abstract unload_data() None[source]

Unload the dataset from memory.

This method should be implemented by subclasses to free memory by clearing loaded data. For example, SingleCellDataset sets its AnnData object to None.

This is used to clear memory-intensive data before serialization, since serializing large raw data artifacts can be error-prone and inefficient.

Any instance attributes containing loaded data should be cleared or set to None.

serialize(path: str) None[source]

Serialize this dataset instance to disk using dill.

Parameters:

path – Path where the serialized dataset should be saved

static deserialize(path: str) BaseDataset[source]

Load a serialized dataset from disk.

Parameters:

path – Path to the serialized dataset file

Returns:

The deserialized dataset instance

Return type:

BaseDataset