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:
EnvA 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
actiontrimmed to its action dimension, then pad the returned observation to the unifiedmax_obs_dimand stampinfo["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
seedparameter otherwise if the environment already has a random number generator andreset()is called withseed=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 besuper().reset(seed=seed)which implements the seeding correctly.Changed in version v0.25: The
return_infoparameter 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 andseed=Noneis 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
inforeturned bystep().
- Observation of the initial state. This will be an element of
- Return type:
observation (ObsType)
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:
GoalEnvA 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
actiontrimmed to its action dimension, then pad each piece of the returned observation dict (observation/achieved_goal/desired_goal) to the unified maximum dims and stampinfo["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
closeon 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 thanself.current_env.Falls back to
self.current_envif task_id is missing frominfo(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.