MinariStorage

minari.dataset.minari_storage.MinariStorage

class minari.dataset.minari_storage.MinariStorage(data_path: Path, observation_space: Space, action_space: Space)[source]

Class that handles disk access to the data.

Methods

minari.dataset.minari_storage.MinariStorage.read(data_path: str | PathLike) MinariStorage

Create a MinariStorage to read data from a path.

Parameters:

data_path (str or Path) – directory where the data is stored.

Returns:

A new MinariStorage object to read the data.

Raises:

ValueError – if the specified path doesn’t exist or doesn’t contain any data.

minari.dataset.minari_storage.MinariStorage.new(observation_space: Space | None = None, action_space: Space | None = None, env_spec: EnvSpec | None = None, data_format: str = 'hdf5') MinariStorage

Class method to create a new data storage.

Parameters:
  • data_path (str or Path) – directory where the data will be stored.

  • observation_space (gymnasium.Space, optional) – Gymnasium observation space of the dataset.

  • action_space (gymnasium.Space, optional) – Gymnasium action space of the dataset.

  • env_spec (EnvSpec, optional) – Gymnasium EnvSpec of the environment that generates the dataset.

  • data_format (str) – Format of the data. Default value is “hdf5”.

Returns:

A new MinariStorage object to write new data.

Raises:

ValueError – if the data format is incorrect or the data path already exists. Moreover, you need to specify the env_spec or both the observation_space and action_space.

minari.dataset.minari_storage.MinariStorage.get_episodes(self, episode_indices: Iterable[int]) Iterable[dict]

Get a list of episodes.

Parameters:

episode_indices (Iterable[int]) – episodes id to return

Returns:

episodes (Iterable[dict]) – episodes data

minari.dataset.minari_storage.MinariStorage.update_episodes(self, episodes: Iterable[EpisodeBuffer])

Update episodes in the storage from a list of episode buffer.

Parameters:
  • episodes (Iterable[EpisodeBuffer]) – list of episodes buffer.

  • dataclass (They must contain the keys specified in EpsiodeData)

  • optional. (except for id which is)

  • exists (If id is specified and)

  • storage. (the new data is appended to the one in the)

minari.dataset.minari_storage.MinariStorage.update_metadata(self, metadata: Dict)

Update the metadata adding/modifying some keys.

Parameters:

metadata (dict) – dictionary of keys-values to add to the metadata.

minari.dataset.minari_storage.MinariStorage.update_episode_metadata(self, metadatas: Iterable[Dict], episode_indices: Iterable | None = None)

Update the metadata of episodes.

Parameters:
  • metadatas (Iterable[Dict]) – metadatas, one for each episode.

  • episode_indices (Iterable, optional) – episode indices to update.

  • specified (If not)

  • considered. (all the episodes are)

minari.dataset.minari_storage.MinariStorage.get_episode_metadata(self, episode_indices: Iterable[int]) Iterable[Dict]

Get the metadata of episodes.

Parameters:

episode_indices (Iterable[int]) – episodes id to return

Returns:

metadatas (Iterable[Dict]) – episodes metadata

minari.dataset.minari_storage.MinariStorage.apply(self, function: Callable[[dict], Any], episode_indices: Iterable | None = None) Iterable[Any]

Apply a function to a slice of the data.

Parameters:
  • function (Callable) – function to apply to episodes

  • episode_indices (Optional[Iterable]) – episodes id to consider

Returns:

outs (Iterable) – outputs returned by the function applied to episodes

minari.dataset.minari_storage.MinariStorage.update_from_storage(self, storage: MinariStorage)

Update the dataset using another MinariStorage.

Parameters:

storage (MinariStorage) – the other MinariStorage from which the data will be taken

minari.dataset.minari_storage.MinariStorage.get_size(self) float

Returns the dataset size in MB.

Returns:

datasize (float) – size of the dataset in MB

Attributes

MinariStorage.observation_space

Observation Space of the dataset.

MinariStorage.action_space

Action space of the dataset.

MinariStorage.total_episodes

Total episodes in the dataset.

MinariStorage.total_steps

Total steps in the dataset.

MinariStorage.metadata

Metadata of the dataset.

MinariStorage.data_path

Full path to the dataset.