Pipeline

Helper methods to generate learning environment pipeline, consisting in an bare-bone environment inheriting from BaseJiminyEnv, wrapped together with any number of successive blocks as a unified environment, in Matlab Simulink fashion.

It enables to break down a complex control architectures in many submodules, making it easier to maintain and avoiding code duplications between use cases.

class gym_jiminy.common.utils.pipeline.CompositionConfig[source]

Bases: TypedDict

Store information required for instantiating a given composition, which comprises reward components or a termination condition at the time being.

Specifically, it is a dictionary comprising the class of the composition that must derive from AbstractReward or AbstractTerminationCondition], and optionally some keyword-arguments to pass to its constructor.

cls: Type[AbstractReward] | Type[AbstractTerminationCondition] | str

Composition class type.

Note

Both class type or fully qualified dotted path are supported.

kwargs: Dict[str, Any]

Composition constructor keyword-arguments.

This attribute can be omitted.

class gym_jiminy.common.utils.pipeline.TrajectoryDatabaseConfig[source]

Bases: TypedDict

Store information required for adding a database of reference trajectories to the environment.

Specifically, it is a dictionary comprising a set of named trajectories as a dictionary whose keys are the name of the trajectories and values are either the trajectory itself or the path of a file storing its dump in HDF5 format, the name of the selected trajectory, and its interpolation mode.

dataset: Dict[str, str | Trajectory]

Set of named trajectories as a dictionary.

Note

Both Trajectory objects or path (absolute or relative) are supported.

name: str

Name of the selected trajectory if any.

This attribute can be omitted.

mode: Literal['raise', 'wrap', 'clip']

Interpolation mode of the selected trajectory if any.

This attribute can be omitted.

class gym_jiminy.common.utils.pipeline.EnvConfig[source]

Bases: TypedDict

Store information required for instantiating a given base environment and compose it with some additional reward components and termination conditions.

Specifically, it is a dictionary comprising the class of the base environment, which must derive from BaseJiminyEnv, optionally some keyword-arguments that must be passed to its corresponding constructor, and eventually the configuration of some additional reward with which to compose the base environment.

cls: Type[BaseJiminyEnv] | str

Environment class type.

Note

Both class type or fully qualified dotted path are supported.

kwargs: Dict[str, Any]

Environment constructor default arguments.

This attribute can be omitted.

reward: CompositionConfig

Reward configuration.

This attribute can be omitted.

terminations: Sequence[CompositionConfig]

Sequence of configuration for every individual termination conditions.

This attribute can be omitted.

trajectories: TrajectoryDatabaseConfig

Reference trajectory database configuration.

This attribute can be omitted.

class gym_jiminy.common.utils.pipeline.BlockConfig[source]

Bases: TypedDict

Store information required for instantiating a given observation or control block.

Specifically, it is a dictionary comprising the class of the block, which must derive from BaseControllerBlock or BaseObserverBlock, and optionally some keyword-arguments that must be passed to its corresponding constructor.

cls: Type[BaseControllerBlock] | Type[BaseObserverBlock] | str

Block class type. If must derive from BaseControllerBlock for controller blocks or from BaseObserverBlock for observer blocks.

Note

Both class type or fully qualified dotted path are supported.

kwargs: Dict[str, Any]

Block constructor default arguments.

This attribute can be omitted.

class gym_jiminy.common.utils.pipeline.WrapperConfig[source]

Bases: TypedDict

Store information required for instantiating a given environment pipeline wrapper.

Specifically, it is a dictionary comprising the class of the wrapper, which must derive from BasePipelineWrapper, and optionally some keyword-arguments that must be passed to its corresponding constructor.

cls: Type[BasePipelineWrapper] | str

Wrapper class type.

Note

Both class type or fully qualified dotted path are supported.

kwargs: Dict[str, Any]

Wrapper constructor default arguments.

This attribute can be omitted.

class gym_jiminy.common.utils.pipeline.LayerConfig[source]

Bases: TypedDict

Store information required for instantiating a given environment pipeline layer, ie either a wrapper, or the combination of an observer / controller block with its corresponding wrapper.

Specifically, it is a dictionary comprising the configuration of the block if any, and optionally the configuration of the reward and termination. It is generally sufficient to specify either one or the other. See the documentation of the both fields for details.

block: BlockConfig

Block configuration.

This attribute can be omitted. If so, then ‘wrapper_cls’ must be specified and must not require any block. Typically, it happens when the wrapper is not doing any computation on its own but just transforming the action or observation, e.g. stacking observation frames.

wrapper: WrapperConfig

Wrapper configuration.

This attribute can be omitted. If so, then ‘block’ must be specified and must this block must be associated with a unique wrapper type to allow for automatic type inference. It works with any observer and controller block.

gym_jiminy.common.utils.pipeline.build_pipeline(env_config, layers_config, *, root_path=None)[source]

Wrap together an environment inheriting from BaseJiminyEnv with any number of layers, as a unified pipeline environment class inheriting from BasePipelineWrapper. Each layer is wrapped individually and successively.

Parameters:
  • env_config (EnvConfig) – Configuration of the environment, as a dict of type EnvConfig.

  • layers_config (Sequence[LayerConfig]) – Configuration of the blocks, as a list. The list is ordered from the lowest level layer to the highest, each element corresponding to the configuration of a individual layer, as a dict of type LayerConfig.

  • root_path (str | Path | None)

Return type:

Callable[[…], InterfaceJiminyEnv]

gym_jiminy.common.utils.pipeline.load_pipeline(fullpath)[source]

Load pipeline from JSON or TOML configuration file.

Param:

Fullpath of the configuration file.

Parameters:

fullpath (str | Path)

Return type:

Callable[[…], InterfaceJiminyEnv]

gym_jiminy.common.utils.pipeline.save_trajectory_to_hdf5(trajectory, fullpath)[source]

Export a trajectory object to HDF5 format.

Parameters:
  • trajectory (Trajectory) – Trajectory object to save.

  • fullpath (str | Path) – Fullpath of the generated HDF5 file.

Return type:

None

gym_jiminy.common.utils.pipeline.load_trajectory_from_hdf5(fullpath)[source]

Import a trajectory object from file in HDF5 format.

Parameters:

fullpath (str | Path) – Fullpath of the HDF5 file to import.

Returns:

Loaded trajectory object.

Return type:

Trajectory