-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DOCS: Adding a tutorial on how to access the observation, proprio and…
… extero information
- Loading branch information
1 parent
8894dd5
commit a7821f8
Showing
2 changed files
with
225 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# How to get details from RoboHive Environments \n", | ||
"RoboHive supports three ways to query the environment based on the nature of inforamtion required. Following information can be queried from an active environment\n", | ||
"1. Get observations (configured using `obs_keys`)\n", | ||
"2. Get proprioception (configured via `proprio_keys`)\n", | ||
"3. Get exteroception (configured via `visual_keys`)\n", | ||
"\n", | ||
"Lets go through them in details one at a time. First we laod an environment, preconfigured with respective keys, and step it a few times - \n", | ||
"(we will go through the key configuration details in another tutorial)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import gym \n", | ||
"import robohive\n", | ||
"\n", | ||
"# create an env and reset\n", | ||
"env = gym.make('door_v2d-v1')\n", | ||
"env.reset()\n", | ||
"\n", | ||
"# Lets step is few times\n", | ||
"for _ in range(5):\n", | ||
" allinfo_tdt = env.step(env.action_space.sample())" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 1. get observations\n", | ||
"This is the most commonly used method to get the current (state based) observation from the environment. Observation are customized using `env.obs_keys` and can contain any details that the environment has access to. RoboHive's doesn't put any restrictions on the information that can be provided by the environment.\n", | ||
"\n", | ||
"RoboHive env provides an `env.get_obs()` method to query observations. It triggers following sequence of events -\n", | ||
"1. Uses robot (sim/hardware) to get sensors\n", | ||
"2. Reconstructs (partially) observed-sim `env.sim_obsd` using (noisy) sensor data\n", | ||
"3. Build the full observation dictionary `env.obs_dict` using the observed-sim\n", | ||
"4. Build obs vector from the obs_dict (using the `env.obs_keys`)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# get current observation vector (internally updates env.sim_obsd & env.obs_dict)\n", | ||
"obs = env.get_obs()" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 2. get proprioception\n", | ||
"This method is used to get *only proprioceptive signals* from the robohive environments. Proprioceptive signals are customized using `env.proprio_keys` and typically consists of proprioceptive sensors that are available to the agent/robots. Proprioception can be acquired in two ways \n", | ||
"1. Recover from *existing* observation dictionary\n", | ||
"2. Update observation and get proprioception alongside (default behavior)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Recover from existing observaton dictionary \n", | ||
"time, proprio_vec, proprio_dict = env.get_proprioception(env.obs_dict)\n", | ||
"\n", | ||
"# Update observation and get proprioception alongside\n", | ||
"obs = env.get_obs(update_proprioception=True)\n", | ||
"# you can get access proprioception dictionary now\n", | ||
"print(env.proprio_dict)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 3. get exteroception\n", | ||
"This method is used to get *only exteroceptive signals* from the robohive environments. exteroceptive signals typically consists of exteroceptive sensors that are available to the agent/robots. Currently we are fosuing primarily on cameras as exteroceptive inputs. It can be customized using `env.visual_keys`. Expanding to other exteroceptive modalities while possible and within scope, is not a tested functionality yet.\n", | ||
"\n", | ||
"Note that exteroceptive sensors are expensive (compute + bandwidth), therefore its requires users to make explicit calls for an update. It can be acquired in two ways -\n", | ||
"\n", | ||
"1. Make an explicit call to `env.get_exteroception()`\n", | ||
"2. Update observation and get proprioception alongside (False by default)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Make an explicit call to update\n", | ||
"extero_dict = env.get_exteroception()\n", | ||
"\n", | ||
"# Update obdervation and get exteroception alongside\n", | ||
"obs = env.get_obs(update_exteroception=True)\n", | ||
"print(env.visual_dict.keys())" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### 4. get everything\n", | ||
"If it's of interest to get all the information at once, `env_get_obs()` can be asked to make all the updates.\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"obs = env.get_obs(update_proprioception=True, update_exteroception=True)\n", | ||
"print(f\"time = {env.obs_dict['time']}\")\n", | ||
"print(f\"obs vector = {obs}\")\n", | ||
"print(f\"obs_dict = {env.obs_dict.keys()}\")\n", | ||
"print(f\"proprio_dict = {env.proprio_dict.keys()}\")\n", | ||
"print(f\"visual_dict = {env.visual_dict.keys()}\")" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Practical tips\n", | ||
"\n", | ||
"### 1. Why ['time', 'time'] as observation?\n", | ||
"Note the observation vector - it looks too simple for such an environment of this complexity. This seems a little weird!\n", | ||
"It is a common practice in *RoboHive* to use ['time', 'time'] as observation for envs designed for visual diversity. This is for two reasons \n", | ||
"1. To avoid leaking oracle information via obs to the agents studying visual generalization \n", | ||
"2. Single ['time'] key leads to silent singleton exansion when inputs of higher dimenstions are required. Replcicating the `time` keys twice helps to catch/expose this bug.\n", | ||
"\n", | ||
"### 2. Ways to ask for obs, proprioception, exteroception?\n", | ||
"The flexibility of RoboHive allows multiple ways to ask for information from the env. We outline a of options below - " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Recover all info at current timestep: obs(t), rwd(t), done(t), info(t)\n", | ||
"obs_t, rwd_t, done_t, info_t = env.env.forward(update_proprioception=True, update_exteroception=True)\n", | ||
"print(f\"time = {env.obs_dict['time']}\")\n", | ||
"print(f\"obs vector = {obs_t}\")\n", | ||
"print(f\"obs_dict = {env.obs_dict.keys()}\")\n", | ||
"print(f\"proprio_dict = {env.proprio_dict.keys()}\")\n", | ||
"print(f\"visual_dict = {env.visual_dict.keys()}\")\n", | ||
"\n", | ||
"# Recover info at the next timestep: obs(t+dt), rwd(t+dt), done(t+dt), info(t+dt)\n", | ||
"obs_tdt, rwd_tdt, done_tdt, info_tdt = env.env.step(env.action_space.sample(), update_proprioception=True, update_exteroception=True)\n", | ||
"print(f\"time = {env.obs_dict['time']}\")\n", | ||
"print(f\"obs vector = {obs_tdt}\")\n", | ||
"print(f\"obs_dict = {env.obs_dict.keys()}\")\n", | ||
"print(f\"proprio_dict = {env.proprio_dict.keys()}\")\n", | ||
"print(f\"visual_dict = {env.visual_dict.keys()}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# close the env\n", | ||
"env.close()" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "robohive", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.8.16" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |