Spaces:
Build error
Build error
Update gensim/sim_runner.py
Browse files- gensim/sim_runner.py +13 -54
gensim/sim_runner.py
CHANGED
|
@@ -86,59 +86,18 @@ class SimulationRunner:
|
|
| 86 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> ", None, None
|
| 87 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> ", None, None
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
self.lang_template = "Construct a wheel using blocks and a sphere. First, position eight blocks in a circular layout on the tabletop. Each block should be touching its two neighbors and colored in alternating red and blue. Then place a green sphere in the center of the circular layout, completing the wheel."
|
| 102 |
-
self.task_completed_desc = "done building wheel."
|
| 103 |
-
self.additional_reset()
|
| 104 |
-
|
| 105 |
-
def reset(self, env):
|
| 106 |
-
super().reset(env)
|
| 107 |
-
|
| 108 |
-
# Add blocks.
|
| 109 |
-
block_size = (0.04, 0.04, 0.04)
|
| 110 |
-
block_urdf = 'block/block.urdf'
|
| 111 |
-
block_colors = [utils.COLORS['red'], utils.COLORS['blue']]
|
| 112 |
-
blocks = []
|
| 113 |
-
for i in range(8):
|
| 114 |
-
block_pose = self.get_random_pose(env, block_size)
|
| 115 |
-
block_id = env.add_object(block_urdf, block_pose, color=block_colors[i % 2])
|
| 116 |
-
blocks.append(block_id)
|
| 117 |
-
|
| 118 |
-
# Add sphere.
|
| 119 |
-
sphere_size = (0.04, 0.04, 0.04)
|
| 120 |
-
sphere_urdf = 'sphere/sphere.urdf'
|
| 121 |
-
sphere_color = utils.COLORS['green']
|
| 122 |
-
sphere_pose = ((0.5, 0.0, 0.0), (0,0,0,1)) # fixed pose
|
| 123 |
-
sphere_id = env.add_object(sphere_urdf, sphere_pose, color=sphere_color)
|
| 124 |
-
|
| 125 |
-
# Goal: blocks are arranged in a circle and sphere is in the center.
|
| 126 |
-
circle_radius = 0.1
|
| 127 |
-
circle_center = (0, 0, block_size[2] / 2)
|
| 128 |
-
angles = np.linspace(0, 2 * np.pi, 8, endpoint=False)
|
| 129 |
-
block_poses = [(circle_center[0] + circle_radius * np.cos(angle),
|
| 130 |
-
circle_center[1] + circle_radius * np.sin(angle),
|
| 131 |
-
circle_center[2]) for angle in angles]
|
| 132 |
-
block_poses = [(utils.apply(sphere_pose, pos), sphere_pose[1]) for pos in block_poses]
|
| 133 |
-
self.add_goal(objs=blocks, matches=np.ones((8, 8)), targ_poses=block_poses, replace=False,
|
| 134 |
-
rotations=True, metric='pose', params=None, step_max_reward=8 / 9)
|
| 135 |
-
|
| 136 |
-
# Goal: sphere is in the center of the blocks.
|
| 137 |
-
self.add_goal(objs=[sphere_id], matches=np.ones((1, 1)), targ_poses=[sphere_pose], replace=False,
|
| 138 |
-
rotations=False, metric='pose', params=None, step_max_reward=1 / 9)
|
| 139 |
-
|
| 140 |
-
self.lang_goals.append(self.lang_template)
|
| 141 |
-
"""
|
| 142 |
print("generated_code\n", self.generated_code)
|
| 143 |
print("curr_task_name\n", self.curr_task_name)
|
| 144 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> ", self.generated_code, None
|
|
@@ -190,7 +149,7 @@ class BuildWheel(Task):
|
|
| 190 |
except:
|
| 191 |
to_print = highlight(f"{str(traceback.format_exc())}", PythonLexer(), TerminalFormatter())
|
| 192 |
print("Task Creation Exception:", to_print)
|
| 193 |
-
raise gradio.Error(f"Task
|
| 194 |
self.task_creation_pass = False
|
| 195 |
|
| 196 |
# self.curr_task_name = self.generated_task['task-name']
|
|
|
|
| 86 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> ", None, None
|
| 87 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> ", None, None
|
| 88 |
|
| 89 |
+
online_code_buffer = {}
|
| 90 |
+
for task_file in json.load(open(os.path.join(self.data_path, "generated_task_codes.json"))):
|
| 91 |
+
if os.path.exists("cliport/generated_tasks/" + task_file):
|
| 92 |
+
online_code_buffer[task_file] = open("cliport/generated_tasks/" + task_file).read()
|
| 93 |
+
|
| 94 |
+
random_task_file = random.sample(list(online_code_buffer.keys()), 1)
|
| 95 |
+
class_def = [line for line in online_code_buffer[task_file].split("\n") if line.startswith('class')]
|
| 96 |
+
task_name = class_def[0]
|
| 97 |
+
task_name = task_name[task_name.find("class "): task_name.rfind("(Task)")][6:]
|
| 98 |
+
self.curr_task_name = self.generated_task_name = task_name
|
| 99 |
+
|
| 100 |
+
self.generated_code = online_code_buffer[random_task_file]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
print("generated_code\n", self.generated_code)
|
| 102 |
print("curr_task_name\n", self.curr_task_name)
|
| 103 |
yield "Task Generated ==> Asset Generated ==> API Reviewed ==> Error Reviewed ==> Code Generated ==> ", self.generated_code, None
|
|
|
|
| 149 |
except:
|
| 150 |
to_print = highlight(f"{str(traceback.format_exc())}", PythonLexer(), TerminalFormatter())
|
| 151 |
print("Task Creation Exception:", to_print)
|
| 152 |
+
raise gradio.Error(f"Task Creati'BuildWheel'on Exception: {str(traceback.format_exc())}")
|
| 153 |
self.task_creation_pass = False
|
| 154 |
|
| 155 |
# self.curr_task_name = self.generated_task['task-name']
|