def test_single_ball_tier(self):
     action_simulator = phyre.action_simulator.ActionSimulator(
         self._tasks, phyre.action_mappers.SingleBallActionMapper())
     action_simulator.sample()
     self.assertEqual(
         action_simulator.simulate_action(self._task_id, [0, 0, 0]).status,
         SimulationStatus.INVALID_INPUT)
     self.assertEqual(
         action_simulator.simulate_action(self._task_id,
                                          [0.1, 0.2, 0.1]).status,
         SimulationStatus.INVALID_INPUT)
     self.assertEqual(
         action_simulator.simulate_action(self._task_id,
                                          [0.5, 0.5, 0.1]).status,
         SimulationStatus.NOT_SOLVED)
 def test_ramp_tier(self):
     action_simulator = phyre.action_simulator.ActionSimulator(
         self._tasks, phyre.action_mappers.RampActionMapper())
     action_simulator.sample()
     # x, y, width, left_height, right_height, angle
     # Outside of the scene (go on the left).
     self.assertEqual(
         action_simulator.simulate_action(
             self._task_id, [0.01, 0.01, 0.5, 0.5, 0.5, 0.]).status,
         phyre.SimulationStatus.INVALID_INPUT)
     # Occludes (rotated by 90 degrees).
     self.assertEqual(
         action_simulator.simulate_action(
             self._task_id, [0.01, 0.01, 0.5, 0.5, 0.5, 0.25]).status,
         phyre.SimulationStatus.INVALID_INPUT)
     # In the middle of the scene.
     self.assertEqual(
         action_simulator.simulate_action(
             self._task_id, [0.5, 0.5, 0.01, 0.3, 0.3, 0.0]).status,
         phyre.SimulationStatus.NOT_SOLVED)
 def test_simulate_single(self):
     action_simulator = phyre.action_simulator.ActionSimulator(
         self._tasks, phyre.action_mappers.SingleBallActionMapper())
     action = [0.5, 0.5, 0.1]
     simulation = action_simulator.simulate_action(self._task_id,
                                                   action,
                                                   need_images=True)
     status, images = action_simulator.simulate_single(self._task_id,
                                                       action,
                                                       need_images=True)
     self.assertEqual(status, simulation.status)
     np.testing.assert_equal(images, simulation.images)
def _eval_single_task(task_id, action_tier_name, attempts):
    tasks = phyre.loader.load_tasks_from_folder(
        task_id_list=[task_id]).values()
    action_simulator = phyre.action_simulator.ActionSimulator(
        tasks, action_tier_name)
    real_attempts = 0
    for _ in range(attempts):
        action = action_simulator.sample()
        status = action_simulator.simulate_action(0, action).status
        if status == phyre.SimulationStatus.SOLVED:
            return (task_id, action, real_attempts)
        if status != phyre.SimulationStatus.INVALID_INPUT:
            real_attempts += 1
    return (task_id, None, real_attempts)
Exemple #5
0
def _eval_single_task(task, action_tier_name, start, num_attempts):
    """Evalute the task on attmepts random action from tier."""
    task_id = task.taskId
    action_simulator = phyre.ActionSimulator([task], action_tier_name)
    actions = _get_actions(action_simulator, start, num_attempts)
    statuses = collections.defaultdict(int)
    stable_solutions, unstable_solutions = [], []
    for action in actions:
        status = action_simulator.simulate_action(0,
                                                  action,
                                                  need_images=False,
                                                  stable=True).status
        statuses[status] += 1
        if status == STABLY_SOLVED:
            stable_solutions.append(action.tolist())
        if status == UNSTABLY_SOLVED:
            unstable_solutions.append(action.tolist())
    return dict(task_id=task_id,
                tier=action_tier_name,
                stable_solutions=stable_solutions[:MAX_SOLUTIONS_TO_KEEP],
                unstable_solutions=unstable_solutions[:MAX_SOLUTIONS_TO_KEEP],
                statuses=statuses)
 def test_single_ball_tier_discrete(self):
     action_simulator = phyre.action_simulator.ActionSimulator(
         self._tasks, phyre.action_mappers.SingleBallActionMapper())
     discrete = action_simulator.build_discrete_action_space(10000)
     self.assertEqual(len(discrete), 10000)
     action_simulator.simulate_action(self._task_id, discrete[0])