def test_termination_and_discount(self):
        walker = cmu_humanoid.CMUHumanoid()

        # Build a maze with rooms and targets.
        skybox_texture = labmaze_textures.SkyBox(style='sky_03')
        wall_textures = labmaze_textures.WallTextures(style='style_01')
        floor_textures = labmaze_textures.FloorTextures(style='style_01')
        arena = mazes.RandomMazeWithTargets(
            x_cells=11,
            y_cells=11,
            xy_scale=3,
            max_rooms=4,
            room_min_size=4,
            room_max_size=5,
            spawns_per_room=1,
            targets_per_room=3,
            skybox_texture=skybox_texture,
            wall_textures=wall_textures,
            floor_textures=floor_textures,
        )

        task = random_goal_maze.ManyGoalsMaze(
            walker=walker,
            maze_arena=arena,
            target_builder=functools.partial(target_sphere.TargetSphere,
                                             radius=0.4,
                                             rgb1=(0, 0, 0.4),
                                             rgb2=(0, 0, 0.7)),
            control_timestep=.03,
            physics_timestep=.005,
        )

        random_state = np.random.RandomState(12345)
        env = composer.Environment(task, random_state=random_state)
        env.reset()

        zero_action = np.zeros_like(env.physics.data.ctrl)

        # Walker starts in upright position.
        # Should not trigger failure termination in the first few steps.
        for _ in range(5):
            env.step(zero_action)
            self.assertFalse(task.should_terminate_episode(env.physics))
            np.testing.assert_array_equal(task.get_discount(env.physics), 1)

        # Rotate the walker upside down and run the physics until it makes contact.
        current_time = env.physics.data.time
        walker.shift_pose(env.physics,
                          position=(0, 0, 10),
                          quaternion=(0, 1, 0, 0))
        env.physics.forward()
        while env.physics.data.ncon == 0:
            env.physics.step()
        env.physics.data.time = current_time

        # Should now trigger a failure termination.
        env.step(zero_action)
        self.assertTrue(task.should_terminate_episode(env.physics))
def cmu_humanoid_maze_forage(random_state=None):
  """Requires a CMU humanoid to find all items in a maze."""

  # Build a position-controlled CMU humanoid walker.
  walker = cmu_humanoid.CMUHumanoidPositionControlled(
      observable_options={'egocentric_camera': dict(enabled=True)})

  # Build a maze with rooms and targets.
  skybox_texture = labmaze_textures.SkyBox(style='sky_03')
  wall_textures = labmaze_textures.WallTextures(style='style_01')
  floor_textures = labmaze_textures.FloorTextures(style='style_01')
  arena = mazes.RandomMazeWithTargets(
      x_cells=11,
      y_cells=11,
      xy_scale=3,
      max_rooms=4,
      room_min_size=4,
      room_max_size=5,
      spawns_per_room=1,
      targets_per_room=3,
      skybox_texture=skybox_texture,
      wall_textures=wall_textures,
      floor_textures=floor_textures,
  )

  # Build a task that rewards the agent for obtaining targets.
  task = random_goal_maze.ManyGoalsMaze(
      walker=walker,
      maze_arena=arena,
      target_builder=functools.partial(
          target_sphere.TargetSphere,
          radius=0.4,
          rgb1=(0, 0, 0.4),
          rgb2=(0, 0, 0.7)),
      target_reward_scale=50.,
      physics_timestep=0.005,
      control_timestep=0.03,
  )

  return composer.Environment(time_limit=30,
                              task=task,
                              random_state=random_state,
                              strip_singleton_obs_buffer_dim=True)
Ejemplo n.º 3
0
    def test_can_compile_mjcf(self):

        # Set the wall and floor textures to match DMLab and set the skybox.
        skybox_texture = labmaze_textures.SkyBox(style='sky_03')
        wall_textures = labmaze_textures.WallTextures(style='style_01')
        floor_textures = labmaze_textures.FloorTextures(style='style_01')

        arena = mazes.RandomMazeWithTargets(x_cells=11,
                                            y_cells=11,
                                            xy_scale=3,
                                            max_rooms=4,
                                            room_min_size=4,
                                            room_max_size=5,
                                            spawns_per_room=1,
                                            targets_per_room=3,
                                            skybox_texture=skybox_texture,
                                            wall_textures=wall_textures,
                                            floor_textures=floor_textures)
        mjcf.Physics.from_mjcf_model(arena.mjcf_model)
Ejemplo n.º 4
0
def rodent_maze_forage(random_state=None):
    """Requires a rodent to find all items in a maze."""

    # Build a position-controlled rodent walker.
    walker = rodent.Rat(
        observable_options={'egocentric_camera': dict(enabled=True)})

    # Build a maze with rooms and targets.
    wall_textures = labmaze_textures.WallTextures(style='style_01')
    arena = mazes.RandomMazeWithTargets(x_cells=11,
                                        y_cells=11,
                                        xy_scale=.5,
                                        z_height=.3,
                                        max_rooms=4,
                                        room_min_size=4,
                                        room_max_size=5,
                                        spawns_per_room=1,
                                        targets_per_room=3,
                                        wall_textures=wall_textures,
                                        aesthetic='outdoor_natural')

    # Build a task that rewards the agent for obtaining targets.
    task = random_goal_maze.ManyGoalsMaze(walker=walker,
                                          maze_arena=arena,
                                          target_builder=functools.partial(
                                              target_sphere.TargetSphere,
                                              radius=0.05,
                                              height_above_ground=.125,
                                              rgb1=(0, 0, 0.4),
                                              rgb2=(0, 0, 0.7)),
                                          target_reward_scale=50.,
                                          contact_termination=False,
                                          physics_timestep=_PHYSICS_TIMESTEP,
                                          control_timestep=_CONTROL_TIMESTEP)

    return composer.Environment(time_limit=30,
                                task=task,
                                random_state=random_state,
                                strip_singleton_obs_buffer_dim=True)
    def test_observables(self):
        walker = cmu_humanoid.CMUHumanoid()

        # Build a maze with rooms and targets.
        skybox_texture = labmaze_textures.SkyBox(style='sky_03')
        wall_textures = labmaze_textures.WallTextures(style='style_01')
        floor_textures = labmaze_textures.FloorTextures(style='style_01')
        arena = mazes.RandomMazeWithTargets(
            x_cells=11,
            y_cells=11,
            xy_scale=3,
            max_rooms=4,
            room_min_size=4,
            room_max_size=5,
            spawns_per_room=1,
            targets_per_room=3,
            skybox_texture=skybox_texture,
            wall_textures=wall_textures,
            floor_textures=floor_textures,
        )

        task = random_goal_maze.ManyGoalsMaze(
            walker=walker,
            maze_arena=arena,
            target_builder=functools.partial(target_sphere.TargetSphere,
                                             radius=0.4,
                                             rgb1=(0, 0, 0.4),
                                             rgb2=(0, 0, 0.7)),
            control_timestep=.03,
            physics_timestep=.005,
        )
        random_state = np.random.RandomState(12345)
        env = composer.Environment(task, random_state=random_state)
        timestep = env.reset()

        self.assertIn('walker/joints_pos', timestep.observation)