GenesisEnv#
- class genesis_forge.GenesisEnv(num_envs: int = 1, dt: float = 0.01, max_episode_length_sec: int | None = 10, max_episode_random_scaling: float = 0.0, extras_logging_key: str = 'episode')[source]#
Bases:
objectBase environment class for your simulated robot environment.
- Parameters:
num_envs – Number of parallel environments.
dt – Simulation time step.
max_episode_length_sec – Maximum episode length in seconds.
max_episode_random_scaling – Scale the maximum episode length by this amount (+/-) so that not all environments reset at the same time.
extras_logging_key – The key used, in info/extras dict, which is returned by step and reset functions, to send data to tensorboard by the RL agent.
Example:
class MyEnv(GenesisEnv): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # ...Define scene here... self.scene = gs.Scene() self.terrain = self.scene.add_entity(gs.morphs.Plane()) self.robot = self.scene.add_entity( ... ) def step(self, actions: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, dict[str, Any]]: # ...step logic here... return obs, rewards, terminations, truncations, info def reset(self, envs_idx: list[int] = None) -> tuple[torch.Tensor, dict[str, Any]]: # ...reset logic here... return obs, info def get_observations(self) -> torch.Tensor: # ...define current observations here... return obs
- build() None[source]#
Builds the environment before the first step. The Genesis scene and all the scene entities must be added before calling this method.
- get_observations() torch.Tensor[source]#
Returns the current observations for each environment. Override this method to return the observations for your environment.
Example:
def get_observations(self) -> torch.Tensor: return torch.cat( [ self.base_ang_vel * self.obs_scales["ang_vel"], # 3 self.projected_gravity, # 3 self.commands * self.commands_scale, # 3 (self.dof_pos - self.default_dof_pos) * self.obs_scales["dof_pos"], # 12 self.dof_vel * self.obs_scales["dof_vel"], # 12 self.actions, # 12 ], axis=-1, )
- reset(envs_idx: list[int] = None) tuple[torch.Tensor, dict[str, Any]][source]#
Reset one or more environments. Each of the registered managers will also be reset for those environments.
- Parameters:
env_ids – The environment ids to reset. If None, all environments are reset.
- Returns:
A batch of observations and info from the vectorized environment.
- set_max_episode_length(max_episode_length_sec: int) int[source]#
Set or change the maximum episode length.
- Parameters:
max_episode_length_sec – The maximum episode length in seconds.
- Returns:
The maximum episode length in steps.
- step(actions: torch.Tensor) tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, dict[str, Any]][source]#
Performs a step in all environments with the given actions.
- Parameters:
actions – Batch of actions for each environment with the
action_spaceshape.- Returns:
Batch of (observations, rewards, terminations, truncations, info/extras)
- property actions: torch.Tensor#
The actions for each environment for this step. If you’re using an action manager, these are the actions prior to being handled by the action manager.
- property extras: dict#
The extras/infos dictionary reset at the start of every step, and contains additional data about the environment during that step.
- property last_actions: torch.Tensor#
The actions for for the previous step.
- property max_episode_length_sec: int | None#
The max episode length, in seconds, for each environment.
- property max_episode_length_steps: int | None#
The max episode length, in steps, for each environment. If episode randomization scaling is enabled, this will be the base max episode length before scaling.
- property unwrapped#
Returns this environment, not a wrapped version of it.