rl_training_validation API reference

Training and validation scripts for the pre-built environments in rl_environments. Each script wires a gym.make() env to an sb3_ros_support algorithm wrapper and a YAML config file.

For the user-facing training guide see Training a model.

Top-level package

Utilities

MultiTaskEnv

Wrapper for training a single policy across several task envs in one process. Used by the multi-task training scripts below.

class rl_training_validation.utils.multi_task_env.MultiTaskEnv(env_list, env_args_list=None, wrapper_list=None, wrapper_args_dict=None)[source]

Bases: Env

A wrapper that trains multiple UniROS-based Gym environments in one agent. Not MPI-parallel; it simply samples a different task each reset.

Parameters:
  • env_list (List[str]) – list of registered gym env names (e.g. UniROS names)

  • env_args_list (List[dict] | None) – list of dicts, one per env in env_list, passed to make()

  • wrapper_list (List[str] | None) – list of wrapper class names (strings) to apply to every env

  • wrapper_args_dict (dict | None) – mapping from wrapper name → kwargs dict

step(action)[source]

Step the currently-active sub-env with action trimmed to its action dimension, then pad the returned observation to the unified max_obs_dim and stamp info["task_id"].

reset(*, seed=None, options=None, **kwargs)[source]

Resets the environment to an initial internal state, returning an initial observation and info.

This method generates a new starting state often with some randomness to ensure that the agent explores the state space and learns a generalised policy about the environment. This randomness can be controlled with the seed parameter otherwise if the environment already has a random number generator and reset() is called with seed=None, the RNG is not reset.

Therefore, reset() should (in the typical use case) be called with a seed right after initialization and then never again.

For Custom environments, the first line of reset() should be super().reset(seed=seed) which implements the seeding correctly.

Changed in version v0.25: The return_info parameter was removed and now info is expected to be returned.

Parameters:
  • seed (optional int) – The seed that is used to initialize the environment’s PRNG (np_random). If the environment does not already have a PRNG and seed=None (the default option) is passed, a seed will be chosen from some source of entropy (e.g. timestamp or /dev/urandom). However, if the environment already has a PRNG and seed=None is passed, the PRNG will not be reset. If you pass an integer, the PRNG will be reset even if it already exists. Usually, you want to pass an integer right after the environment has been initialized and then never again. Please refer to the minimal example above to see this paradigm in action.

  • options (optional dict) – Additional information to specify how the environment is reset (optional, depending on the specific environment)

Returns:

Observation of the initial state. This will be an element of observation_space

(typically a numpy array) and is analogous to the observation returned by step().

info (dictionary): This dictionary contains auxiliary information complementing observation. It should be analogous to

the info returned by step().

Return type:

observation (ObsType)

close()[source]

After the user has finished using the environment, close contains the code necessary to “clean up” the environment.

This is critical for closing rendering windows, database or HTTP connections. Calling close on an already closed environment has no effect and won’t raise an error.

MultiTaskGoalEnv

Goal-conditioned variant of MultiTaskEnv, routes HER reward recomputation per sub-env via info["task_id"].

class rl_training_validation.utils.multi_task_goal_env.MultiTaskGoalEnv(env_list, env_args_list=None, wrapper_list=None, wrapper_args_dict=None)[source]

Bases: GoalEnv

A wrapper that trains multiple UniROS-based GoalEnv gymnasium environments in one agent. Not MPI-parallel; it simply samples a different task each reset.

Parameters:
  • env_list (List[str]) – list of registered gym env names (must be GoalEnv)

  • env_args_list (List[dict] | None) – list of dicts, one per env in env_list, passed to make()

  • wrapper_list (List[str] | None) – list of wrapper class names (strings) to apply to every env

  • wrapper_args_dict (dict | None) – mapping from wrapper name → kwargs dict

step(action)[source]

Step the currently-active sub-env with action trimmed to its action dimension, then pad each piece of the returned observation dict (observation / achieved_goal / desired_goal) to the unified maximum dims and stamp info["task_id"].

reset(*, seed=None, options=None, **kwargs)[source]

Reset the environment.

In addition, check if the observation space is correct by inspecting the observation, achieved_goal, and desired_goal keys.

close()[source]

After the user has finished using the environment, close contains the code necessary to “clean up” the environment.

This is critical for closing rendering windows, database or HTTP connections. Calling close on an already closed environment has no effect and won’t raise an error.

compute_reward(achieved_goal, desired_goal, info)[source]

Called by HER to recompute rewards when relabelling experience.

HER batches transitions from possibly-different sub-envs; the “currently active” sub-env at recompute time may not be the same as the sub-env that produced the transition. We therefore route by info["task_id"] (stamped at reset() and step() time) rather than self.current_env.

Falls back to self.current_env if task_id is missing from info (e.g. info dict was constructed by hand for a single-task test). This is a best-effort fallback; for HER correctness, info["task_id"] should be present.

Parameters:
Return type:

float

RX200 reach scripts

Sim training / validation

Real-hardware training / validation

Multi-task learning