mani_skill.envs.scenes.base_env#
Classes#
A base environment for simulating manipulation tasks in more complex scenes. Creating this base environment is only useful |
Module Contents#
- class mani_skill.envs.scenes.base_env.SceneManipulationEnv(*args, robot_uids='fetch', scene_builder_cls='ReplicaCAD', build_config_idxs=None, init_config_idxs=None, num_envs=1, reconfiguration_freq=None, **kwargs)[source]#
Bases:
mani_skill.envs.sapien_env.BaseEnvA base environment for simulating manipulation tasks in more complex scenes. Creating this base environment is only useful for explorations/visualization, there are no success/failure metrics or rewards.
- Parameters:
robot_uids – Which robot to place into the scene. Default is “fetch”
fixed_scene – When True, will never reconfigure the environment during resets unless you run env.reset(seed=seed, options=dict(reconfigure=True)) and explicitly reconfigure. If False, will reconfigure every reset.
scene_builder_cls (Union[str, mani_skill.utils.scene_builder.SceneBuilder]) – Scene builder class to build a scene with. Default is ReplicaCAD. Furthermore, any of the AI2THOR SceneBuilders are supported in this environment.
build_config_idxs (optional) – which build configs (static builds) to sample. Your scene_builder_cls may or may not require these.
init_config_idxs (optional) – which init configs (additional init options) to sample. Your scene_builder_cls may or may not require these.
- _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) –
- 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()[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
- Return type:
dict
- reset(seed=None, options=None)[source]#
Reset the ManiSkill environment with given seed(s) and options. Typically seed is either None (for unseeded reset) or an int (seeded reset). For GPU parallelized environments you can also pass a list of seeds for each parallel environment to seed each one separately.
If options[“env_idx”] is given, will only reset the selected parallel environments. If options[“reconfigure”] is True, will call self._reconfigure() which deletes the entire physx scene and reconstructs everything. Users building custom tasks generally do not need to override this function.
If options[“reset_to_env_states”] is given, we expect there to be options[“reset_to_env_states”][“env_states”] and optionally options[“reset_to_env_states”][“obs”], both with batch size equal to the number of environments being reset. “env_states” can be a dictionary or flat tensor and we skip calling the environment’s _initialize_episode function which generates the initial state on a normal reset. If “obs” is given we skip calling the environment’s get_obs function which can save some compute/time.
Returns the observations and an info dictionary. The info dictionary is of type
{ "reconfigure": bool # (True if the env reconfigured. False otherwise) }
Note that ManiSkill always holds two RNG states, a main RNG, and an episode RNG. The main RNG is used purely to sample an episode seed which helps with reproducibility of episodes and is for internal use only. The episode RNG is used by the environment/task itself to e.g. randomize object positions, randomize assets etc. Episode RNG is accessible by using self._batched_episode_rng which is numpy based and torch.rand which can be used to generate random data on the GPU directly and is seeded. Note that it is recommended to use self._batched_episode_rng if you need to ensure during reconfiguration the same objects are loaded. Reproducibility and seeding when there is GPU and CPU simulation can be tricky and we recommend reading the documentation for more recommendations and details on RNG https://maniskill.readthedocs.io/en/latest/user_guide/concepts/rng.html
Upon environment creation via gym.make, the main RNG is set with fixed seeds of 2022 to 2022 + num_envs - 1 (seed is just 2022 if there is only one environment) During each reset call, if seed is None, main RNG is unchanged and an episode seed is sampled from the main RNG to create the episode RNG. If seed is not None, main RNG is set to that seed and the episode seed is also set to that seed. This design means the main RNG determines the episode RNG deterministically.
- 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