コード例 #1
0
def cmu_humanoid_heterogeneous_forage(random_state=None):
  """Requires a CMU humanoid to find all items of a particular type in a maze."""
  level = ('*******\n'
           '*     *\n'
           '*  P  *\n'
           '*     *\n'
           '*  G  *\n'
           '*     *\n'
           '*******\n')

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

  skybox_texture = labmaze_textures.SkyBox(style='sky_03')
  wall_textures = labmaze_textures.WallTextures(style='style_01')
  floor_textures = labmaze_textures.FloorTextures(style='style_01')
  maze = fixed_maze.FixedMazeWithRandomGoals(
      entity_layer=level,
      variations_layer=None,
      num_spawns=1,
      num_objects=6,
  )
  arena = mazes.MazeWithTargets(
      maze=maze,
      xy_scale=3.0,
      z_height=2.0,
      skybox_texture=skybox_texture,
      wall_textures=wall_textures,
      floor_textures=floor_textures,
  )
  task = random_goal_maze.ManyHeterogeneousGoalsMaze(
      walker=walker,
      maze_arena=arena,
      target_builders=[
          functools.partial(
              target_sphere.TargetSphere,
              radius=0.4,
              rgb1=(0, 0.4, 0),
              rgb2=(0, 0.7, 0)),
          functools.partial(
              target_sphere.TargetSphere,
              radius=0.4,
              rgb1=(0.4, 0, 0),
              rgb2=(0.7, 0, 0)),
      ],
      randomize_spawn_rotation=False,
      target_type_rewards=[30., -10.],
      target_type_proportions=[1, 1],
      shuffle_target_builders=True,
      aliveness_reward=0.01,
      control_timestep=.03,
  )

  return composer.Environment(
      time_limit=25,
      task=task,
      random_state=random_state,
      strip_singleton_obs_buffer_dim=True)
コード例 #2
0
    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))
コード例 #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')

    maze = padded_room.PaddedRoom(room_size=4, num_objects=2)
    arena = mazes.MazeWithTargets(
        maze=maze,
        skybox_texture=skybox_texture,
        wall_textures=wall_textures,
        floor_textures=floor_textures)
    mjcf.Physics.from_mjcf_model(arena.mjcf_model)
コード例 #4
0
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)
コード例 #5
0
ファイル: mazes_test.py プロジェクト: yangyi0318/dm_control
    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)
コード例 #6
0
    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)