Beispiel #1
0
 def test_render_with_input(self):
     scene = simulator.simulate_task_with_input(self._task,
                                                self._box_user_input,
                                                steps=1).sceneList[0]
     array = simulator.scene_to_raster(scene)
     self.assertEqual(len(array.shape), 2)
     self.assertEqual(array.shape[0], self._task.scene.height)
     self.assertEqual(array.shape[1], self._task.scene.width)
Beispiel #2
0
 def test_add_input_and_simulate_strided(self):
     steps = 10
     full_results = simulator.simulate_task_with_input(self._task,
                                                       self._box_user_input,
                                                       stride=1,
                                                       steps=steps)
     strided_results = simulator.simulate_task_with_input(
         self._task, self._box_user_input, stride=3, steps=steps)
     self.assertEqual(len(full_results.sceneList), steps)
     self.assertEqual(len(strided_results.sceneList), math.ceil(steps / 3))
     self.assertEqual(len(full_results.solvedStateList), steps)
     self.assertEqual(len(strided_results.solvedStateList),
                      math.ceil(steps / 3))
     for i in range(0, steps, 3):
         self.assertEqual(full_results.sceneList[i],
                          strided_results.sceneList[i // 3])
         self.assertEqual(full_results.solvedStateList[i],
                          strided_results.solvedStateList[i // 3])
Beispiel #3
0
    def test_add_input_and_simulate(self):
        steps = 10

        # Check simulate_task_with_input is identical to add_user_input_to_scene
        # followed by simulate_task.
        combined_results = simulator.simulate_task_with_input(
            self._task, self._box_user_input, steps=steps)

        task = copy.copy(self._task)
        task.scene = simulator.add_user_input_to_scene(task.scene,
                                                       self._box_user_input)
        bl_resuls = simulator.simulate_task(task, steps=steps)

        self.assertEqual(combined_results, bl_resuls)
    def test_add_input_and_ponies(self):
        steps = 10
        task_simulation = simulator.simulate_task_with_input(
            self._task, self._ball_user_input, steps=steps, stride=1)

        is_solved, had_occlusions, images, scenes = simulator.magic_ponies(
            self._task,
            self._ball_user_input,
            steps=steps,
            stride=1,
            need_images=True,
            need_featurized_objects=True)

        self.assertEqual(is_solved, task_simulation.isSolution)
        self.assertEqual(len(images), steps)
        self.assertEqual(len(task_simulation.sceneList), steps)
        self.assertEqual(
            had_occlusions, task_simulation.sceneList[0].user_input_status ==
            scene_if.UserInputStatus.HAD_OCCLUSIONS)

        # Check images match target scenes
        self.assertFalse(
            np.array_equal(
                images[0],
                simulator.scene_to_raster(task_simulation.sceneList[-1])))
        self.assertTrue((images[-1] == simulator.scene_to_raster(
            task_simulation.sceneList[-1])).all())

        # Test just images works
        _, _, only_images, _ = simulator.magic_ponies(
            self._task,
            self._ball_user_input,
            steps=steps,
            stride=1,
            need_images=True,
            need_featurized_objects=False)
        self.assertTrue(np.array_equal(images, only_images))
        # Test just scenes works
        _, _, _, only_scenes = simulator.magic_ponies(
            self._task,
            self._ball_user_input,
            steps=steps,
            stride=1,
            need_images=False,
            need_featurized_objects=True)
        self.assertTrue(np.array_equal(scenes, only_scenes))
Beispiel #5
0
    def test_add_input_and_ponies(self):
        raise unittest.SkipTest
        steps = 10

        task_simulation = simulator.simulate_task_with_input(
            self._task, self._box_user_input, steps=steps, stride=1)

        is_solved, had_occlusions, images = simulator.magic_ponies(
            self._task, self._box_compressed_user_input, steps=steps, stride=1)

        self.assertEqual(is_solved, task_simulation.isSolution)
        self.assertEqual(len(images), steps)
        self.assertEqual(len(task_simulation.sceneList), steps)
        self.assertEqual(
            had_occlusions, task_simulation.sceneList[0].user_input_status ==
            scene_if.UserInputStatus.HAD_OCCLUSIONS)
        self.assertFalse((images[0] == simulator.scene_to_raster(
            task_simulation.sceneList[-1])).all())
        self.assertTrue((images[-1] == simulator.scene_to_raster(
            task_simulation.sceneList[-1])).all())
Beispiel #6
0
# plt.imshow(phyre.vis.observations_to_float_rgb(initial_scene))
# plt.show()

from phyre import simulator as sim
actions = simulator.build_discrete_action_space(max_actions=1000)
action = actions[20]  # Successful action for 3:28
action, is_valid = simulator.get_user_input(
    action)  # Phyre representation of the action

# If you want to brute force every solution until you get a success
# from phyre import SimulationStatus
# for action in actions:
# 	status = simulator.simulate_single(task_index, action, need_images=False)
# 	if status == SimulationStatus.SOLVED:

# Simulates task with the action, returning Thrift representations of intermediate images every frame
# Increase stride to decrease simulation time
result = sim.simulate_task_with_input(simulator.get_task(0), action, stride=1)

# Convert Thrift scene to array of pixels
images = [sim.scene_to_raster(scene) for scene in result.sceneList]
ims = [phyre.vis.observations_to_float_rgb(image) for image in images]

# Displays the simulation
delay = 0.0005  # Delay between frames
img = plt.imshow(ims[0])
for image in ims[1:]:
    img.set_data(image)
    plt.pause(delay)
    plt.draw()
Beispiel #7
0
action_tier = phyre.eval_setup_to_action_tier(eval_setup)
simulator = phyre.initialize_simulator(tasks, action_tier)
task_index = 0
task_id = simulator.task_ids[task_index]

print("Task being simulated:", task_id)

# search for an action that solves this
actions = simulator.build_discrete_action_space(max_actions = 10000)
for action in actions:
    status, _ = simulator.simulate_single(task_index, action, need_images=False)
    if status == SimulationStatus.SOLVED:
        print("Solution found:", action)
        actual_action = action # for output later
        action, is_valid = simulator.get_user_input(action)
        result, user_input = sim.simulate_task_with_input(simulator.get_task(task_index), action, stride=1)
        
        # get the initial scene
        initial_scene = result.sceneList[0]
        initial_scene_objects = viz.create_list_of_objects(initial_scene)

        # add user input
        viz.add_user_ball(initial_scene_objects, user_input)

        # generate json format
        initial_json = viz.initial_json(task_id, actual_action, initial_scene_objects)
        initial_json = json.loads(initial_json.replace("'", '"'))

        # convert json to csv
        fp = OUTPUT_DIR + task_id.replace(':', '.') + ".csv"
        viz.initial_csv(initial_json, fp)