コード例 #1
0
 def _setup_basic_gtt_task(self, num_targets=1, reward_scale=1.0):
   walker = walkers.Ant()
   text_maze = arenas.padded_room.PaddedRoom(
       room_size=8, num_objects=2, pad_with_walls=True)
   maze_arena = arenas.MazeWithTargets(maze=text_maze)
   targets = []
   for _ in range(num_targets):
     targets.append(
         props.PositionDetector(
             pos=[0, 0, 0.5],
             size=[0.5, 0.5, 0.5],
             inverted=False,
             visible=True))
   test_predicates = [predicates.MoveWalkerToRandomTarget(walker, targets)]
   self._task = predicate_task.PredicateTask(
       walker=walker,
       maze_arena=maze_arena,
       predicates=test_predicates,
       targets=targets,
       randomize_num_predicates=False,
       reward_scale=reward_scale,
       terminating_reward_bonus=2.0,
       )
   random_state = np.random.RandomState(12345)
   self._env = composer.Environment(self._task, random_state=random_state)
   self._walker = walker
   self._targets = targets
コード例 #2
0
 def test_error_too_few_targets(self):
   walker = walkers.Ant()
   num_targets = 5
   text_maze = arenas.padded_room.PaddedRoom(
       room_size=8, num_objects=2, pad_with_walls=True)
   maze_arena = arenas.MazeWithTargets(maze=text_maze)
   targets = []
   for _ in range(num_targets):
     targets.append(
         props.PositionDetector(
             pos=[0, 0, 0.5],
             size=[0.5, 0.5, 0.5],
             inverted=False,
             visible=True))
   test_predicates = [predicates.MoveWalkerToRandomTarget(walker, targets)]
   task = predicate_task.PredicateTask(
       walker=walker,
       maze_arena=maze_arena,
       predicates=test_predicates,
       targets=targets,
       randomize_num_predicates=False,
       reward_scale=1.0,
       terminating_reward_bonus=2.0,
   )
   random_state = np.random.RandomState(12345)
   env = composer.Environment(task, random_state=random_state)
   with self.assertRaisesWithLiteralMatch(
       RuntimeError, "The generated maze does not contain enough target "
       "positions for the requested number of props (0) and targets (5): "
       "got 2."
   ):
     env.reset()
コード例 #3
0
 def test_too_few_predicates_raises_exception(self):
   walker = walkers.Ant()
   num_targets = 1
   text_maze = arenas.padded_room.PaddedRoom(
       room_size=8, num_objects=2, pad_with_walls=True)
   maze_arena = arenas.MazeWithTargets(maze=text_maze)
   targets = []
   for _ in range(num_targets):
     targets.append(
         props.PositionDetector(
             pos=[0, 0, 0.5],
             size=[0.5, 0.5, 0.5],
             inverted=False,
             visible=True))
   test_predicates = []
   with self.assertRaisesWithLiteralMatch(
       ValueError, "Not enough predicates for task."
       " The maximum number of "
       "predicates can be "
       "1 but only 0 predicates provided."):
     predicate_task.PredicateTask(
         walker=walker,
         maze_arena=maze_arena,
         predicates=test_predicates,
         targets=targets,
         randomize_num_predicates=False,
         reward_scale=1.0,
         terminating_reward_bonus=2.0,
         )
コード例 #4
0
def _make_predicate_task(n_boxes, n_targets,
                         include_gtt_predicates, include_move_box_predicates,
                         max_num_predicates, control_timestep, time_limit):
  """Auxiliary function to construct different predicates tasks."""
  walker = walkers.Ant()
  skybox = dmlab_assets.SkyBox(style='sky_03')
  wall = dmlab_assets.WallTextures(style='style_03')
  floor = dmlab_assets.FloorTextures(style='style_03')

  # Make room size become bigger once the number of objects become larger.
  num_objects = n_boxes + n_targets
  room_size = max(MIN_ROOM_SIZE, num_objects)
  text_maze = locomotion_arenas.padded_room.PaddedRoom(
      room_size=room_size, num_objects=num_objects, pad_with_walls=True)
  arena = locomotion_arenas.MazeWithTargets(
      maze=text_maze,
      skybox_texture=skybox,
      wall_textures=wall,
      floor_textures=floor)

  boxes = []
  for _ in range(n_boxes):
    boxes.append(
        manipulation_props.BoxWithSites(mass=1.5, half_lengths=[0.5, 0.5, 0.5]))

  targets = []
  for _ in range(n_targets):
    targets.append(
        props.PositionDetector(
            pos=[0, 0, 0.5], size=[0.5, 0.5, 0.5], inverted=False,
            visible=True))

  predicates = []
  if include_gtt_predicates:
    predicates.append(
        predicates_module.MoveWalkerToRandomTarget(
            walker=walker, targets=targets))
  if include_move_box_predicates:
    for box_idx in range(len(boxes)):
      predicates.append(
          predicates_module.MoveBoxToRandomTarget(
              walker=walker,
              box=boxes[box_idx],
              box_index=box_idx,
              targets=targets))

  task = PredicateTask(
      walker=walker,
      maze_arena=arena,
      predicates=predicates,
      props=boxes,
      targets=targets,
      max_num_predicates=max_num_predicates,
      randomize_num_predicates=False,
      reward_scale=10.,
      regenerate_predicates=False,
      physics_timestep=0.005,
      control_timestep=control_timestep)
  env = composer.Environment(task=task, time_limit=time_limit)

  return env
コード例 #5
0
  def test_error_if_no_predicates_found(self):
    walker = walkers.Ant()
    num_targets = 2
    text_maze = arenas.padded_room.PaddedRoom(
        room_size=8, num_objects=6, pad_with_walls=True)
    maze_arena = arenas.MazeWithTargets(maze=text_maze)
    targets = []
    for _ in range(num_targets):
      targets.append(
          props.PositionDetector(
              pos=[0, 0, 0.5],
              size=[0.5, 0.5, 0.5],
              inverted=False,
              visible=True))
    # Moving the walker to two targets is not possible since the walker is a
    # shared object in use.
    test_predicates = [predicates.MoveWalkerToTarget(walker, targets[0]),
                       predicates.MoveWalkerToTarget(walker, targets[1])]
    task = predicate_task.PredicateTask(
        walker=walker,
        maze_arena=maze_arena,
        predicates=test_predicates,
        targets=targets[1:],
        randomize_num_predicates=False,
        max_num_predicates=2,
        reward_scale=1.0,
        terminating_reward_bonus=2.0,
    )
    random_state = np.random.RandomState(12345)
    env = composer.Environment(task, random_state=random_state)
    with self.assertRaisesWithLiteralMatch(
        ValueError, "Could not find set of active predicates"
        " with unique objects are after 1000 iterations."):
      env.reset()

    # However moving to one of the two targets is fine.
    walker = walkers.Ant()
    num_targets = 2
    text_maze = arenas.padded_room.PaddedRoom(
        room_size=8, num_objects=6, pad_with_walls=True)
    maze_arena = arenas.MazeWithTargets(maze=text_maze)
    targets = []
    for _ in range(num_targets):
      targets.append(
          props.PositionDetector(
              pos=[0, 0, 0.5],
              size=[0.5, 0.5, 0.5],
              inverted=False,
              visible=True))
    test_predicates = [predicates.MoveWalkerToTarget(walker, targets[0]),
                       predicates.MoveWalkerToTarget(walker, targets[1])]
    task = predicate_task.PredicateTask(
        walker=walker,
        maze_arena=maze_arena,
        predicates=test_predicates,
        targets=targets[1:],
        randomize_num_predicates=False,
        max_num_predicates=1,
        reward_scale=1.0,
        terminating_reward_bonus=2.0,
    )
    random_state = np.random.RandomState(12345)
    env = composer.Environment(task, random_state=random_state)
    env.reset()