Repository: stepjam/RLBench
Issue: Task PutUmbrellaInUmbrellaStand crashes with BoundaryError
Root cause: Algorithmic Error

I got the following terminal output when trying the PutUmbrellaInUmbrellaStand task, which instructed me to raise an issue:

```
Traceback (most recent call last):
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/task_environment.py", line 71, in reset
    randomly_place=not self._static_positions)
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/backend/scene.py", line 104, in init_episode
    raise e
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/backend/scene.py", line 97, in init_episode
    self._place_task()
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/backend/scene.py", line 386, in _place_task
    min_rotation=min_rot, max_rotation=max_rot)
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/backend/spawn_boundary.py", line 172, in sample
    raise BoundaryError('Could not place within boundary.'
rlbench.backend.exceptions.BoundaryError: Could not place within boundary.Perhaps the object is too big for it?

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "collect_rlbench_data.py", line 94, in <module>
    collect_demos(env, [task_class_name], h5_root, args.demos_per_task, len(args.task))
  File "collect_rlbench_data.py", line 37, in collect_demos
    demo = task.get_demos(1, live_demos=True)[0]
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/task_environment.py", line 239, in get_demos
    demos = self._get_live_demos(amount)
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/task_environment.py", line 248, in _get_live_demos
    self.reset()
  File "/home/adam/venv3/lib/python3.5/site-packages/rlbench/task_environment.py", line 76, in reset
    % self._task.get_name()) from e
rlbench.task_environment.TaskEnvironmentError: Could not place the task put_umbrella_in_umbrella_stand in the scene. This should not happen, please raise an issues on this task.
```
Here are the snippets from my code that are relevant:
```
obs_config = ObservationConfig()
obs_config.set_all(True)
action_mode = ActionMode(ArmActionMode.ABS_JOINT_VELOCITY)
env = Environment(action_mode, obs_config=obs_config, headless=args.headless)
env.launch()

task = env.get_task(PutUmbrellaInUmbrellaStand)
demo = task.get_demos(1, live_demos=True)[0]
```

My system:
* Ubuntu 16.04
* Python 3.5 (in virtual environment using `venv`)
* V-REP 3.6.2


Hi,
Thanks for raising. What happens if you run your script a few times? Does it always give this error?

Best,
Stephen

No it's not every time. The `demo = task.get_demos(1, live_demos=True)[0]` line is actually in a for loop that tries to get 100 demos in a row (note I only get 1 at a time because I'm rendering a progress bar on the terminal). I can sometimes collect 15-20 demos before I get the error. 

I can post my full code if that's helpful but I think I picked out the parts that are RLBench-specific.

I just got the same error for OpenBox as well after successfully getting 18 demos.

Hi Adam,
OK, so first let me explain why this is happening. When you get a demo, the task is placed randomly inside the workspace boundary. RLBench does this by sampling. Sometimes you can get unlucky and get bad samples and if it samples too many times, it assume the task has been badly designed. But I know that the 2 tasks you refer to are fine, so I either need to increase the sampling threshold, or I need to adjust the task so it doesn't reach the current threshold.
Regardless, for now I suggest wrapping the get_demos call in a try-catch clause. I'll take a look at the tasks after I get back from CoRL.

Thanks for your help, Stephen. I will note that I'm running data collection on all 100 tasks and I see this error come up occasionally in many of them. The try/except approach works fine though and it often recovers after one error. I put it in a while-loop to make 10 consecutive attempts just to be robust to consecutive errors.