mtrl.utils package

Submodules

mtrl.utils.checkpointable module

Interface for the objects that can be checkpointed on the filesystem.

class mtrl.utils.checkpointable.Checkpointable[source]

Bases: abc.ABC

All classes that want to support checkpointing should extend this class.

abstract load(*args, **kwargs) → Any[source]

Load the object from a checkpoint.

Returns

Any

abstract save(*args, **kwargs) → Any[source]

Save the object to a checkpoint.

Returns

Any

mtrl.utils.config module

Code to interface with the config.

mtrl.utils.config.dict_to_config(dictionary: Dict) → omegaconf.dictconfig.DictConfig[source]

Convert the dictionary to a config.

Parameters

dictionary (Dict) – dictionary to convert.

Returns

config made from the dictionary.

Return type

ConfigType

mtrl.utils.config.get_env_params_from_config(config: omegaconf.dictconfig.DictConfig) → omegaconf.dictconfig.DictConfig[source]

Get the params needed for building the environment from a config.

Parameters

config (ConfigType) –

Returns

params for building the environment, encoded as a config.

Return type

ConfigType

mtrl.utils.config.make_config_immutable(config: omegaconf.dictconfig.DictConfig) → omegaconf.dictconfig.DictConfig[source]

Set the config to be immutable.

Parameters

config (ConfigType) –

Returns

Return type

ConfigType

mtrl.utils.config.make_config_mutable(config: omegaconf.dictconfig.DictConfig) → omegaconf.dictconfig.DictConfig[source]

Set the config to be mutable.

Parameters

config (ConfigType) –

Returns

Return type

ConfigType

mtrl.utils.config.pretty_print(config, resolve: bool = True)[source]

Prettyprint the config.

Parameters
  • config ([type]) –

  • resolve (bool, optional) – should resolve the config before printing. Defaults to True.

mtrl.utils.config.process_config(config: omegaconf.dictconfig.DictConfig, should_make_dir: bool = True) → omegaconf.dictconfig.DictConfig[source]

Process the config.

Parameters
  • config (ConfigType) – config object to process.

  • should_make_dir (bool, optional) – should make dir for saving logs, models etc? Defaults to True.

Returns

processed config.

Return type

ConfigType

mtrl.utils.config.read_config_from_file(config_path: str) → omegaconf.dictconfig.DictConfig[source]

Read the config from filesystem.

Parameters

config_path (str) – path to read config from.

Returns

Return type

ConfigType

mtrl.utils.config.set_struct(config: omegaconf.dictconfig.DictConfig) → omegaconf.dictconfig.DictConfig[source]

Set the struct flag in the config.

Parameters

config (ConfigType) –

Returns

Return type

ConfigType

mtrl.utils.config.to_dict(config: omegaconf.dictconfig.DictConfig) → Dict[str, Any][source]

Convert config to a dictionary.

Parameters

config (ConfigType) –

Returns

Return type

Dict

mtrl.utils.config.unset_struct(config: omegaconf.dictconfig.DictConfig) → omegaconf.dictconfig.DictConfig[source]

Unset the struct flag in the config.

Parameters

config (ConfigType) –

Returns

Return type

ConfigType

mtrl.utils.types module

Collection of types used in the code.

mtrl.utils.utils module

Collection of utility functions

mtrl.utils.utils.chunks(_list: List[T], n: int) → Iterator[List[T]][source]

Yield successive n-sized chunks from given list. Taken from https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks

Parameters
  • _list (List[T]) – list to chunk.

  • n (int) – size of chunks.

Yields

Iterator[List[T]] – iterable over the chunks

mtrl.utils.utils.flatten_list(_list: List[List[Any]]) → List[Any][source]

Flatten a list of lists into a single list

Parameters

_list (List[List[Any]]) – List of lists

Returns

Flattened list

Return type

List[Any]

mtrl.utils.utils.get_current_commit_id() → str[source]

Get current commit id.

Returns

current commit id.

Return type

str

mtrl.utils.utils.has_uncommitted_changes() → bool[source]

Check if there are uncommited changes.

Returns

wether there are uncommiteed changes.

Return type

bool

mtrl.utils.utils.is_integer(n: Union[int, str, float]) → bool[source]

Check if the given value can be interpreted as an integer.

Parameters

n (Union[int, str, float]) – value to check.

Returns

can be the value be interpreted as an integer.

Return type

bool

mtrl.utils.utils.make_dir(path: str) → str[source]

Make a directory, along with parent directories. Does not return an error if the directory already exists.

Parameters

path (str) – path to make the directory.

Returns

path of the new directory.

Return type

str

mtrl.utils.utils.set_seed(seed: int) → None[source]

Set the seed for python, numpy, and torch.

Parameters

seed (int) – seed to set.

mtrl.utils.utils.split_on_caps(input_str: str) → List[str][source]

Split a given string at uppercase characters. Taken from: https://stackoverflow.com/questions/2277352/split-a-string-at-uppercase-letters

Parameters

input_str (str) – string to split.

Returns

splits of the given string.

Return type

List[str]

mtrl.utils.video module

Utility to record the environment frames into a video.

class mtrl.utils.video.VideoRecorder(dir_name, height=256, width=256, camera_id=0, fps=30)[source]

Bases: object

Class to record the environment frames into a video.

Parameters
  • dir_name ([type]) – directory to save the recording.

  • height (int, optional) – height of the frame. Defaults to 256.

  • width (int, optional) – width of the frame. Defaults to 256.

  • camera_id (int, optional) – id of the camera for recording. Defaults to 0.

  • fps (int, optional) – frames-per-second for the recording. Defaults to 30.

init(enabled=True)[source]

Initialize the recorder.

Parameters

enabled (bool, optional) – should enable the recorder or not. Defaults to True.

record(frame, env=None)[source]

Record the frames.

Parameters

env ([type]) – environment to record the frames.

save(file_name)[source]

Save the frames as video to self.dir_name in a file named file_name.

Parameters

file_name ([type]) – name of the file to store the video frames.

Module contents