Skip to content

lit_sb3.vec_env.util

source module lit_sb3.vec_env.util

Helpers for dealing with vectorized environments.

Functions

  • dict_to_obs — Convert an internal representation raw_obs into the appropriate type.

  • obs_space_info — Get dict-structured information about a gym.Space.

source dict_to_obs(obs_space: spaces.Space, obs_dict: dict[Any, np.ndarray]) → VecEnvObs

Convert an internal representation raw_obs into the appropriate type.

specified by space.

Parameters

  • obs_space : spaces.Space — an observation space.

  • obs_dict : dict[Any, np.ndarray] — a dict of numpy arrays.

Returns

  • VecEnvObs — returns an observation of the same type as space. If space is Dict, function is identity; if space is Tuple, converts dict to Tuple; otherwise, space is unstructured and returns the value raw_obs[None].

source obs_space_info(obs_space: spaces.Space) → tuple[list[str], dict[Any, tuple[int, ...]], dict[Any, np.dtype]]

Get dict-structured information about a gym.Space.

Dict spaces are represented directly by their dict of subspaces. Tuple spaces are converted into a dict with keys indexing into the tuple. Unstructured spaces are represented by {None: obs_space}.

Parameters

  • obs_space : spaces.Space — an observation space

Returns

  • A tuple (keys, shapes, dtypes) —

    keys: a list of dict keys. shapes: a dict mapping keys to shapes. dtypes: a dict mapping keys to dtypes.