Skip to content

Instantly share code, notes, and snippets.

@geyang
Last active September 14, 2020 19:52
Show Gist options
  • Save geyang/206a41c28e9a0c6953c9ca0f68a0210f to your computer and use it in GitHub Desktop.
Save geyang/206a41c28e9a0c6953c9ca0f68a0210f to your computer and use it in GitHub Desktop.

Bin Pick and Place Tasks (Debug)

We want to eventually learn two primitives: pick up a block and place it into a bin, and pick up a block from the bin and place it somewhere else. Not all of these tasks are learnable directly.

Update: The culprit was a missing reset in _reset_sim. because of this, the arm wonders around, drifting through a large configuration space.

Now, all environments are working.

Name Observation Spec Goal Init/Comment Status
Bin-no-bin-v0 achieved_goal: (3,)
desired_goal: (3,)
observation: (25,)
env uses bin_null.xml, other wise sam ✅ 99%
Bin-no-bin-v0 achieved_goal: (3,)
desired_goal: (3,)
observation: (25,)
env is the same as fetch:PickPlace-v0 ✅ 99%
Bin-no-init-v0 achieved_goal: (3,)
desired_goal: (3,)
observation: (25,)
same except bin in model xml ✅ 99%
Bin-aside-v0 achieved_goal: (3,)
desired_goal: (3,)
observation: (25,)
same except bin in model ✅ 99%
Bin-aside-pos-v0 achieved_goal: (3,)
desired_goal: (3,)
observation: (28,)
plus 3-dim position in obs ✅ 99%

Details of Each Task

Initial After Reset After Reset
206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-bin-v0_init.png?ts=058375 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-bin-v0_reset.png?ts=150123 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-bin-v0.gif?ts=553959
render_initial('fetch:Bin-no-bin-v0', row)
render_video('fetch:Bin-no-bin-v0', 15, row)
Initial After Reset After Reset
206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-pp-xml-v0_init.png?ts=740389 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-pp-xml-v0_reset.png?ts=837289 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-pp-xml-v0.gif?ts=719423
render_initial('fetch:Bin-pp-xml-v0', row)
render_video('fetch:Bin-pp-xml-v0', 15, row)
Initial After Reset After Reset
206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-init-v0_init.png?ts=847718 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-init-v0_reset.png?ts=927102 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-no-init-v0.gif?ts=767147
render_initial('fetch:Bin-no-init-v0', row)
render_video('fetch:Bin-no-init-v0', 15, row)
Initial After Reset After Reset
206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-v0_init.png?ts=854889 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-v0_reset.png?ts=937901 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-v0.gif?ts=506494
render_initial('fetch:Bin-aside-v0', row)
render_video('fetch:Bin-aside-v0', 15, row)
Initial After Reset After Reset
206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-pos-v0_init.png?ts=637211 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-pos-v0_reset.png?ts=751076 206a41c28e9a0c6953c9ca0f68a0210f/raw/Bin-aside-pos-v0.gif?ts=376275
render_initial('fetch:Bin-aside-pos-v0', row)
render_video('fetch:Bin-aside-pos-v0', 15, row)
import gym
import numpy as np
from cmx import doc
scale = 3
src_prefix = "206a41c28e9a0c6953c9ca0f68a0210f"
def get_obs_spec(env_id):
env = gym.make(env_id)
buffer = []
for k, v in env.observation_space.spaces.items():
buffer += [f"{k}: {v.shape}"]
return "<br>".join(buffer)
def render_initial(env_id, doc):
env = gym.make(env_id)
img = env.render('rgb_array', width=200 * scale, height=120 * scale)
doc.figure(img, src=f"{src_prefix}/{env_id}_init.png?ts={doc.now('%f')}", title="Initial")
frames = []
for i in range(10):
env.reset()
frames.append(env.render('rgb_array', width=100 * scale, height=120 * scale))
env_id = env_id.split(':')[-1]
doc.figure(np.array(frames).min(axis=0), src=f"{src_prefix}/{env_id}_reset.png?ts={doc.now('%f')}",
title="After Reset")
def render_video(env_id, n, doc):
env = gym.make(env_id)
frames = []
for ep in range(n):
env.reset()
for i in range(10):
act = env.action_space.sample()
ts = env.step(act)
frames.append(env.render('rgb_array', width=100 * scale, height=120 * scale))
env_id = env_id.split(':')[-1]
doc.video(np.array(frames), src=f"{src_prefix}/{env_id}.gif?ts={doc.now('%f')}",
title="After Reset")
if __name__ == '__main__':
doc.config("README.md")
doc @ f"""
# Bin Pick and Place Tasks (Debug)
We want to eventually learn two primitives: pick up a block and
place it into a bin, and pick up a block from the bin and place
it somewhere else. Not all of these tasks are learnable directly.
> **Update**: The culprit was a missing reset in `_reset_sim`.
> because of this, the arm wonders around, drifting through
> a large configuration space.
Name | Observation Spec | Goal Init/Comment | Status
----------------- | ---------------- | ------- | ------
**Bin-no-bin-v0** | {get_obs_spec('fetch:Bin-no-bin-v0')} | env uses `bin_null.xml`, other wise sam | ✅ 99%
**Bin-no-bin-v0** | {get_obs_spec('fetch:Bin-pp-xml-v0')} | env is the same as `fetch:PickPlace-v0` | ✅ 99%
**Bin-no-init-v0** | {get_obs_spec('fetch:Bin-no-init-v0')} | same except bin in model xml | ✅ 99%
**Bin-aside-v0** | {get_obs_spec('fetch:Bin-aside-v0')} | same except bin in model | ✅ 99%
**Bin-aside-pos-v0** | {get_obs_spec('fetch:Bin-aside-pos-v0')} | plus 3-dim position in obs | ✅ 99%
## Details of Each Task
"""
table = doc.table()
with doc, table.figure_row() as row:
render_initial('fetch:Bin-no-bin-v0', row)
render_video('fetch:Bin-no-bin-v0', 15, row)
table = doc.table()
with doc, table.figure_row() as row:
render_initial('fetch:Bin-pp-xml-v0', row)
render_video('fetch:Bin-pp-xml-v0', 15, row)
table = doc.table()
with doc, table.figure_row() as row:
render_initial('fetch:Bin-no-init-v0', row)
render_video('fetch:Bin-no-init-v0', 15, row)
table = doc.table()
with doc, table.figure_row() as row:
render_initial('fetch:Bin-aside-v0', row)
render_video('fetch:Bin-aside-v0', 15, row)
table = doc.table()
with doc, table.figure_row() as row:
render_initial('fetch:Bin-aside-pos-v0', row)
render_video('fetch:Bin-aside-pos-v0', 15, row)
doc.flush()
from rl import main, Args
from params_proto.neo_hyper import Sweep
from ml_logger import logger
if __name__ == '__main__':
import jaynes
from lp_analysis import instr
env_names = [
# Gym originals
'fetch:Slide-v0',
'fetch:PickPlace-v0',
# Bin debug task set
'fetch:Bin-no-bin-v0',
'fetch:Bin-pp-xml-v0',
'fetch:Bin-no-init-v0',
'fetch:Bin-aside-v0',
'fetch:Bin-aside-pos-v0',
# # Bin debug task sets
# 'fetch:Bin-fixed-v0',
# 'fetch:Bin-fixed-hide-v0',
# 'fetch:Bin-fixed-pos-v0',
]
with Sweep(Args) as sweep:
Args.gamma = 0.99
Args.clip_inputs = True
Args.normalize_inputs = True
Args.n_workers = 12
Args.n_epochs = 500
with sweep.product:
with sweep.zip:
Args.env_name = env_names
Args.seed = [100, 200, 300, 400, 500, 600]
# jaynes.config('local' if Args.debug else "gpu-vaughan", launch=dict(timeout=10000))
jaynes.config('local' if Args.debug else "cpu-mars")
# jaynes.config('local')
for i, deps in sweep.items():
thunk = instr(main, deps, _job_postfix=f"{Args.env_name.split(':')[-1]}")
logger.log_text("""
keys:
- run.status
- Args.env_name
- host.hostname
charts:
- yKey: test/success
xKey: epoch
- yKey: test/success
xKey: timesteps
- yKey: train/success/mean
xKey: time
""", ".charts.yml", dedent=True)
jaynes.run(thunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment