imitation.util.registry#

Registry mapping IDs to objects, such as environments or policy loaders.

Module Attributes

LoaderFn

The type stored in Registry is commonly an instance of LoaderFn.

Functions

build_loader_fn_require_env(fn, **kwargs)

Converts a factory taking an environment into a LoaderFn.

build_loader_fn_require_space(fn, **kwargs)

Converts a factory taking observation and action space into a LoaderFn.

load_attr(name)

Load an attribute in format path.to.module:attribute.

Classes

Registry()

A registry mapping IDs to type T objects, with support for lazy loading.

imitation.util.registry.LoaderFn#

The type stored in Registry is commonly an instance of LoaderFn.

alias of Callable[[…], T]

class imitation.util.registry.Registry[source]#

Bases: Generic[T]

A registry mapping IDs to type T objects, with support for lazy loading.

The registry allows for insertion and retrieval. Modification of existing elements is not allowed.

If the registered item is a string, it is assumed to be a path to an attribute in the form path.to.module:attribute. In this case, the module is loaded only if and when the registered item is retrieved.

This is helpful both to reduce overhead from importing unused modules, and when some modules may have additional dependencies that are not installed in all deployments.

Note: This is a similar idea to gym.EnvRegistry.

__init__()[source]#

Builds empty Registry.

get(key)[source]#
Return type

TypeVar(T)

keys()[source]#
Return type

Iterable[str]

register(key, *, value=None, indirect=None)[source]#
imitation.util.registry.build_loader_fn_require_env(fn, **kwargs)[source]#

Converts a factory taking an environment into a LoaderFn.

Return type

Callable[..., TypeVar(T)]

imitation.util.registry.build_loader_fn_require_space(fn, **kwargs)[source]#

Converts a factory taking observation and action space into a LoaderFn.

Return type

Callable[..., TypeVar(T)]

imitation.util.registry.load_attr(name)[source]#

Load an attribute in format path.to.module:attribute.