mani_skill.envs.template#

Code for a minimal environment/task with just a robot being loaded. We recommend copying this template and modifying as you need.

At a high-level, ManiSkill tasks can minimally be defined by what agents/actors are loaded, how agents/actors are randomly initialized during env resets, how goals are randomized and parameterized in observations, and success conditions

Environment reset is comprised of running two functions, self._reconfigure and self.initialize_episode, which is auto run by ManiSkill. As a user, you can override a number of functions that affect reconfiguration and episode initialization.

Reconfiguration will reset the entire environment scene and allow you to load/swap assets and agents.

Episode initialization will reset the poses of all actors, articulations, and agents, in addition to initializing any task relevant data like a goal

See comments for how to make your own environment and what each required function should do. If followed correctly you can easily build a task that can simulate on the CPU and be parallelized on the GPU without having to manage GPU memory and parallelization apart from some code that need to be written in batched mode (e.g. reward, success conditions)

For a minimal implementation of a simple task, check out mani_skill /envs/tasks/push_cube.py which is annotated with comments to explain how it is implemented

Classes#

CustomEnv

Task Description

Module Contents#

class mani_skill.envs.template.CustomEnv(*args, robot_uids='panda', robot_init_qpos_noise=0.02, **kwargs)[source]#

Bases: mani_skill.envs.sapien_env.BaseEnv

Task Description#

Add a task description here

Randomizations#

  • how is it randomized?

  • how is that randomized?

Success Conditions#

  • what is done to check if this task is solved?

Visualization: link to a video/gif of the task being solved

_get_obs_extra(info)[source]#

Get task-relevant extra observations. Usually defined on a task by task basis

Parameters:

info (dict) –

_initialize_episode(env_idx, options)[source]#

Initialize the episode, e.g., poses of actors and articulations, as well as task relevant data like randomizing goal positions

Parameters:
  • env_idx (torch.Tensor) –

  • options (dict) –

_load_agent(options)[source]#

loads the agent/controllable articulations into the environment. The default function provides a convenient way to setup the agent/robot by a robot_uid (stored in self.robot_uids) without requiring the user to have to write the robot building and controller code themselves. For more advanced use-cases you can override this function to have more control over the agent/robot building process.

Parameters:
  • options (dict) – The options for the environment.

  • initial_agent_poses (Optional[Union[sapien.Pose, Pose]]) – The initial poses of the agent/robot. Providing these poses and ensuring they are picked such that they do not collide with objects if spawned there is highly recommended to ensure more stable simulation (the agent pose can be changed later during episode initialization).

  • build_separate (bool) – Whether to build the agent/robot separately. If True, the agent/robot will be built separately for each parallel environment and then merged together to be accessible under one view/object. This is useful for randomizing physical and visual properties of the agent/robot which is only permitted for articulations built separately in each environment.

_load_lighting(options)[source]#

Loads lighting into the scene. Called by self._reconfigure. If not overriden will set some simple default lighting

Parameters:

options (dict) –

_load_scene(options)[source]#

Loads all objects like actors and articulations into the scene. Called by self._reconfigure. Given options argument is the same options dictionary passed to the self.reset function

Parameters:

options (dict) –

_setup_sensors(options)[source]#

Setup sensor configurations and the sensor objects in the scene. Called by self._reconfigure

Parameters:

options (dict) –

compute_dense_reward(obs, action, info)[source]#

Compute the dense reward.

Parameters:
  • obs (Any) – The observation data. By default the observation data will be in its most raw form, a dictionary (no flattening, wrappers etc.)

  • action (torch.Tensor) – The most recent action.

  • info (dict) – The info dictionary.

compute_normalized_dense_reward(obs, action, info)[source]#

Compute the normalized dense reward.

Parameters:
  • obs (Any) – The observation data. By default the observation data will be in its most raw form, a dictionary (no flattening, wrappers etc.)

  • action (torch.Tensor) – The most recent action.

  • info (dict) – The info dictionary.

evaluate(obs)[source]#

Evaluate whether the environment is currently in a success state by returning a dictionary with a “success” key or a failure state via a “fail” key

This function may also return additional data that has been computed (e.g. is the robot grasping some object) that may be reused when generating observations and rewards.

By default if not overriden this function returns an empty dictionary

Parameters:

obs (Any) –

get_state_dict()[source]#

Get environment state dictionary. Override to include task information (e.g., goal)

set_state_dict(state)[source]#

Set environment state with a state dictionary. Override to include task information (e.g., goal)

Note that it is recommended to keep around state dictionaries as opposed to state vectors. With state vectors we assume the order of data in the vector is the same exact order that would be returned by flattening the state dictionary you get from env.get_state_dict() or the result of env.get_state()

SUPPORTED_ROBOTS = ['panda', 'fetch'][source]#

Override this to enforce which robots or tuples of robots together are supported in the task. During env creation, setting robot_uids auto loads all desired robots into the scene, but not all tasks are designed to support some robot setups

property _default_human_render_camera_configs[source]#

Add default cameras for rendering when using render_mode=’rgb_array’. These can be overriden by the user at env creation time

property _default_sensor_configs[source]#

Add default (non-agent) sensors to the environment by returning sensor configurations. These can be overriden by the user at env creation time

property _default_sim_config[source]#
agent: mani_skill.agents.robots.panda.panda.Panda | mani_skill.agents.robots.fetch.fetch.Fetch[source]#
robot_init_qpos_noise = 0.02[source]#