Esempio n. 1
0
  def test_can_create_two_rats(self):
    rat1 = rodent.Rat(name='rat1')
    rat2 = rodent.Rat(name='rat2')
    arena = corr_arenas.EmptyCorridor()
    arena.add_free_entity(rat1)
    arena.add_free_entity(rat2)
    mjcf.Physics.from_mjcf_model(arena.mjcf_model)  # Should not raise an error.

    rat1.mjcf_model.model = 'rat3'
    rat2.mjcf_model.model = 'rat4'
    mjcf.Physics.from_mjcf_model(arena.mjcf_model)  # Should not raise an error.
Esempio n. 2
0
def rodent_run_gaps(random_state=None):
    """Requires a rodent to run down a corridor with gaps."""

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

    # Build a corridor-shaped arena with gaps, where the sizes of the gaps and
    # platforms are uniformly randomized.
    arena = corr_arenas.GapsCorridor(platform_length=distributions.Uniform(
        .4, .8),
                                     gap_length=distributions.Uniform(.05, .2),
                                     corridor_width=2,
                                     corridor_length=40,
                                     aesthetic='outdoor_natural')

    # Build a task that rewards the agent for running down the corridor at a
    # specific velocity.
    task = corr_tasks.RunThroughCorridor(walker=walker,
                                         arena=arena,
                                         walker_spawn_position=(5, 0, 0),
                                         walker_spawn_rotation=0,
                                         target_velocity=1.0,
                                         contact_termination=False,
                                         terminate_at_height=-0.3,
                                         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)
Esempio n. 3
0
def rodent_two_touch(random_state=None):
    """Requires a rodent to tap an orb, wait an interval, and tap it again."""

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

    arena = floors.Floor(size=(10., 10.), aesthetic='outdoor_natural')

    task = reach.TwoTouch(
        walker=walker,
        arena=arena,
        target_builders=[
            functools.partial(target_sphere.TargetSphereTwoTouch,
                              radius=0.025),
        ],
        randomize_spawn_rotation=True,
        target_type_rewards=[25.],
        shuffle_target_builders=False,
        target_area=(1.5, 1.5),
        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_contact(self):
        walker = rodent.Rat()

        # Build a corridor-shaped arena that is obstructed by walls.
        arena = bowl.Bowl(size=(20., 20.), aesthetic='outdoor_natural')

        # Build a task that rewards the agent for running down the corridor at a
        # specific velocity.
        task = escape.Escape(walker=walker,
                             arena=arena,
                             physics_timestep=_PHYSICS_TIMESTEP,
                             control_timestep=_CONTROL_TIMESTEP)

        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)
Esempio n. 5
0
  def test_observables(self):
    walker = rodent.Rat()

    arena = floors.Floor(
        size=(10., 10.),
        aesthetic='outdoor_natural')

    task = reach.TwoTouch(
        walker=walker,
        arena=arena,
        target_builders=[
            functools.partial(target_sphere.TargetSphereTwoTouch, radius=0.025),
        ],
        randomize_spawn_rotation=True,
        target_type_rewards=[25.],
        shuffle_target_builders=False,
        target_area=(1.5, 1.5),
        physics_timestep=_PHYSICS_TIMESTEP,
        control_timestep=_CONTROL_TIMESTEP,
    )
    random_state = np.random.RandomState(12345)
    env = composer.Environment(task, random_state=random_state)
    timestep = env.reset()

    self.assertIn('walker/joints_pos', timestep.observation)
def _get_rat_corridor_physics():
    walker = rodent.Rat()
    arena = corr_arenas.EmptyCorridor()
    task = corr_tasks.RunThroughCorridor(walker=walker,
                                         arena=arena,
                                         walker_spawn_position=(5, 0, 0),
                                         walker_spawn_rotation=0,
                                         physics_timestep=_PHYSICS_TIMESTEP,
                                         control_timestep=_CONTROL_TIMESTEP)

    env = composer.Environment(time_limit=30,
                               task=task,
                               strip_singleton_obs_buffer_dim=True)

    return walker, env
    def test_observables(self):
        walker = rodent.Rat()

        # Build a corridor-shaped arena that is obstructed by walls.
        arena = bowl.Bowl(size=(20., 20.), aesthetic='outdoor_natural')

        # Build a task that rewards the agent for running down the corridor at a
        # specific velocity.
        task = escape.Escape(walker=walker,
                             arena=arena,
                             physics_timestep=_PHYSICS_TIMESTEP,
                             control_timestep=_CONTROL_TIMESTEP)

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

        self.assertIn('walker/joints_pos', timestep.observation)
def rodent_escape_bowl(random_state=None):
    """Requires a rodent to climb out of a bowl-shaped terrain."""

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

    # Build a bowl-shaped arena.
    arena = bowl.Bowl(size=(20., 20.), aesthetic='outdoor_natural')

    # Build a task that rewards the agent for being far from the origin.
    task = escape.Escape(walker=walker,
                         arena=arena,
                         physics_timestep=_PHYSICS_TIMESTEP,
                         control_timestep=_CONTROL_TIMESTEP)

    return composer.Environment(time_limit=20,
                                task=task,
                                random_state=random_state,
                                strip_singleton_obs_buffer_dim=True)
Esempio n. 9
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)
Esempio n. 10
0
 def test_set_name(self):
   name = 'fred'
   walker = rodent.Rat(name=name)
   self.assertEqual(walker.mjcf_model.model, name)
Esempio n. 11
0
 def test_get_element_tuple_property(self, name):
   attribute_value = getattr(rodent.Rat(), name)
   self.assertNotEmpty(attribute_value)
   for item in attribute_value:
     self.assertIsInstance(item, mjcf.Element)
Esempio n. 12
0
 def test_get_element_property(self, name):
   attribute_value = getattr(rodent.Rat(), name)
   self.assertIsInstance(attribute_value, mjcf.Element)
Esempio n. 13
0
 def test_proprioception(self):
   walker = rodent.Rat()
   for item in walker.observables.proprioception:
     self.assertIsInstance(item, observable_base.Observable)