gymbag.hdf5

HDF5 support for Gymbag OpenAI Gym data recorder.

Functions

record_hdf5((env: gym.core.Env, …) Wrap an env and record its data to an HDF5 file.

Classes

HDF5Reader((filename: str, …) Iterate over gym data recorded in HDF5.
HDF5Recorder((filename: str, …) Record to HDF5 independent of an environment (e.g.
gymbag.hdf5.record_hdf5(env: gym.core.Env, filename: str, description: str = '') → gymbag.core.RecordEnv[TObs, TAct][source]

Wrap an env and record its data to an HDF5 file.

Data is recorded to table with the same name as the environment (spec), or the env class name if env has no spec.

Parameters:description – Human-readable string that goes in the HDF5 table metadata so you can remember where this data came from later.
class gymbag.hdf5.HDF5Recorder(filename: str, observation_space: typing.Union[gym.core.Space, typing.Tuple[int, ...]], action_space: typing.Union[gym.core.Space, typing.Tuple[int, ...]], table_name: str = '', description: str = '', max_info_bytes: int = 1024) → None[source]

Record to HDF5 independent of an environment (e.g. for saving test data).

Data is saved at the root node unless table_name is a path. Data is saved to a table named table_name if given, else the filename is used as the table name. Will set the last done value to True before a reset or close, even if passed done == False. Observations and actions are always stored as floats (Discrete spaces are converted to int by the Reader). All floats are stored as 32-bit. Tables are compressed with blosc:zstd (or zlib if unavailable).

Parameters:
  • max_info_bytes – info dicts are encoded as JSON strings, and PyTables only supports fixed-length strings, so you gotta choose an upper bound. If you set this to 0, info will not be stored.
  • observation_space – If you pass a gym.Space, it will be stored in the table metadata for use by the reader.
  • action_space – If you pass a gym.Space, it will be stored in the table metadata for use the by reader.
on_reset(unix_time: float, observation: TObs, action: TAct, reward: float = nan, done: bool = False, info: typing.Union[typing.Dict[typing.Any, typing.Any], NoneType] = None) → None[source]

Start a new episode.

on_step(unix_time: float, observation: TObs, action: TAct, reward: float, done: bool, info: typing.Union[typing.Dict[typing.Any, typing.Any], NoneType]) → None[source]

Record step data. Note that observation is the one that comes before the action and reward.

on_close() → None[source]

Close the underlying HDF5 file.

class gymbag.hdf5.HDF5Reader(filename: str, table: typing.Union[str, NoneType] = None) → None[source]

Iterate over gym data recorded in HDF5.

Return:an iterable of episodes of step data read from HDF5 filename.

Each step is a tuple of (time, observation, action, reward, done, info). The first step in an episode will have NaN action and reward. The last step in an episode will have done == True. Observations and actions are stored as floats, but converted to int if the corresponding space is Discrete.

name = None

The environment name

nsteps = None

The total number of steps (in all episodes) in this Reader.

description = None

The human-readable description

observation_space = None

The observation space

action_space = None

The action space

close() → None[source]

Close the underlying HDF5 file.