Upload PACE-Bench executable tasks (part 2)
Browse files- tasks/Category6_ExoticPhysics/E_06/agent.py +270 -0
- tasks/Category6_ExoticPhysics/E_06/environment.py +579 -0
- tasks/Category6_ExoticPhysics/E_06/evaluator.py +298 -0
- tasks/Category6_ExoticPhysics/E_06/feedback.py +309 -0
- tasks/Category6_ExoticPhysics/E_06/prompt.py +45 -0
- tasks/Category6_ExoticPhysics/E_06/renderer.py +133 -0
- tasks/Category6_ExoticPhysics/E_06/stages.py +355 -0
- tasks/Category6_ExoticPhysics/__init__.py +1 -0
- tasks/__init__.py +1 -0
- tasks/primitives_api.json +0 -0
tasks/Category6_ExoticPhysics/E_06/agent.py
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
chord_density = 5.0
|
| 5 |
+
chord_h = 0.10
|
| 6 |
+
web_density = 2.0
|
| 7 |
+
web_w = 0.1
|
| 8 |
+
bottom_y = 1.55
|
| 9 |
+
top_y = 6.25
|
| 10 |
+
FORBIDDEN_LO = 9.7
|
| 11 |
+
FORBIDDEN_HI = 10.3
|
| 12 |
+
xs = [5.75, 9.6, 13.5]
|
| 13 |
+
for xv in xs:
|
| 14 |
+
if FORBIDDEN_LO <= xv <= FORBIDDEN_HI:
|
| 15 |
+
raise ValueError("Grid point {} in forbidden zone".format(xv))
|
| 16 |
+
n = len(xs)
|
| 17 |
+
def seg_w(i):
|
| 18 |
+
if i < n - 1:
|
| 19 |
+
return xs[i + 1] - xs[i]
|
| 20 |
+
return 2.0
|
| 21 |
+
|
| 22 |
+
bottom_chord = []
|
| 23 |
+
for i in range(n):
|
| 24 |
+
w = seg_w(i)
|
| 25 |
+
bottom_chord.append(sandbox.add_beam(xs[i], bottom_y, w, chord_h, 0, chord_density))
|
| 26 |
+
for i in range(n - 1):
|
| 27 |
+
ax = (xs[i] + xs[i + 1]) / 2.0
|
| 28 |
+
sandbox.add_joint(bottom_chord[i], bottom_chord[i + 1], (ax, bottom_y), type="rigid")
|
| 29 |
+
|
| 30 |
+
top_chord = []
|
| 31 |
+
for i in range(n):
|
| 32 |
+
w = seg_w(i)
|
| 33 |
+
ty = top_y - (xs[i] - xs[0]) * 0.04
|
| 34 |
+
top_chord.append(sandbox.add_beam(xs[i], ty, w, chord_h, 0, chord_density))
|
| 35 |
+
for i in range(n - 1):
|
| 36 |
+
ax = (xs[i] + xs[i + 1]) / 2.0
|
| 37 |
+
ay = (top_chord[i].position.y + top_chord[i + 1].position.y) / 2.0
|
| 38 |
+
sandbox.add_joint(top_chord[i], top_chord[i + 1], (ax, ay), type="rigid")
|
| 39 |
+
|
| 40 |
+
for i in range(n):
|
| 41 |
+
by_i = bottom_chord[i].position.y
|
| 42 |
+
ty_i = top_chord[i].position.y
|
| 43 |
+
vy = (by_i + ty_i) / 2.0
|
| 44 |
+
vh = min(4.0, ty_i - by_i - chord_h - 0.02)
|
| 45 |
+
if vh > 0.06:
|
| 46 |
+
vert = sandbox.add_beam(xs[i], vy, web_w, vh, 0, web_density)
|
| 47 |
+
sandbox.add_joint(bottom_chord[i], vert, (xs[i], by_i + chord_h / 2.0), type="rigid")
|
| 48 |
+
sandbox.add_joint(top_chord[i], vert, (xs[i], ty_i - chord_h / 2.0), type="rigid")
|
| 49 |
+
|
| 50 |
+
for i in range(n - 1):
|
| 51 |
+
cx = (xs[i] + xs[i + 1]) / 2.0
|
| 52 |
+
if FORBIDDEN_LO <= cx <= FORBIDDEN_HI:
|
| 53 |
+
continue
|
| 54 |
+
dx = xs[i + 1] - xs[i]
|
| 55 |
+
by_i = bottom_chord[i].position.y
|
| 56 |
+
ty_ip1 = top_chord[i + 1].position.y
|
| 57 |
+
dy_up = ty_ip1 - by_i
|
| 58 |
+
d_up = min(4.0, math.sqrt(dx * dx + dy_up * dy_up) * 0.96)
|
| 59 |
+
ang_up = math.atan2(dy_up, dx)
|
| 60 |
+
cy_up = (by_i + ty_ip1) / 2.0
|
| 61 |
+
diag_up = sandbox.add_beam(cx, cy_up, web_w, d_up, ang_up, web_density)
|
| 62 |
+
sandbox.add_joint(bottom_chord[i], diag_up, (xs[i] + 0.05, by_i + 0.02), type="rigid")
|
| 63 |
+
sandbox.add_joint(top_chord[i + 1], diag_up, (xs[i + 1] - 0.05, ty_ip1 - 0.02), type="rigid")
|
| 64 |
+
ty_i = top_chord[i].position.y
|
| 65 |
+
by_ip1 = bottom_chord[i + 1].position.y
|
| 66 |
+
dy_dn = ty_i - by_ip1
|
| 67 |
+
d_dn = min(4.0, math.sqrt(dx * dx + dy_dn * dy_dn) * 0.96)
|
| 68 |
+
ang_dn = math.atan2(dy_dn, -dx)
|
| 69 |
+
cy_dn = (ty_i + by_ip1) / 2.0
|
| 70 |
+
diag_dn = sandbox.add_beam(cx, cy_dn, web_w, d_dn, math.pi - abs(ang_dn), web_density)
|
| 71 |
+
sandbox.add_joint(top_chord[i], diag_dn, (xs[i] + 0.05, ty_i - 0.02), type="rigid")
|
| 72 |
+
sandbox.add_joint(bottom_chord[i + 1], diag_dn, (xs[i + 1] - 0.05, by_ip1 + 0.02), type="rigid")
|
| 73 |
+
|
| 74 |
+
last_b = bottom_chord[-1]
|
| 75 |
+
last_t = top_chord[-1]
|
| 76 |
+
tip_x = xs[-1] + 0.20
|
| 77 |
+
tip_by = last_b.position.y
|
| 78 |
+
tip_ty = last_t.position.y
|
| 79 |
+
tip_mid_y = (tip_by + tip_ty) / 2.0
|
| 80 |
+
tip_h = min(4.0, abs(tip_ty - tip_by) - chord_h - 0.02)
|
| 81 |
+
if tip_h > 0.06:
|
| 82 |
+
tip_close = sandbox.add_beam(tip_x, tip_mid_y, web_w, tip_h, 0, web_density)
|
| 83 |
+
sandbox.add_joint(last_b, tip_close, (tip_x, tip_by + chord_h / 2.0), type="rigid")
|
| 84 |
+
sandbox.add_joint(last_t, tip_close, (tip_x, tip_ty - chord_h / 2.0), type="rigid")
|
| 85 |
+
|
| 86 |
+
sandbox.add_joint(bottom_chord[0], None, (5.75, 1.0), type="rigid")
|
| 87 |
+
total_mass = sandbox.get_structure_mass()
|
| 88 |
+
mass_limit = sandbox.get_structure_mass_limit()
|
| 89 |
+
if total_mass > mass_limit:
|
| 90 |
+
raise ValueError(f"Mass {total_mass} exceeds {mass_limit}")
|
| 91 |
+
return bottom_chord[0]
|
| 92 |
+
|
| 93 |
+
def agent_action_stage_4(sandbox, agent_body, step_count):
|
| 94 |
+
pass
|
| 95 |
+
|
| 96 |
+
def build_agent_stage_3(sandbox):
|
| 97 |
+
chord_density = 2.5
|
| 98 |
+
chord_h = 0.55
|
| 99 |
+
web_density = 1.1
|
| 100 |
+
web_w = 0.1
|
| 101 |
+
diag_w = 0.1
|
| 102 |
+
bottom_y = 1.55
|
| 103 |
+
top_y = 6.1
|
| 104 |
+
FORBIDDEN_LO = 9.7
|
| 105 |
+
FORBIDDEN_HI = 10.3
|
| 106 |
+
xs = [5.75, 6.5, 8.0, 10.5, 13.5]
|
| 107 |
+
for xv in xs:
|
| 108 |
+
if FORBIDDEN_LO <= xv <= FORBIDDEN_HI:
|
| 109 |
+
raise ValueError(f"Grid point {xv} in forbidden zone")
|
| 110 |
+
n = len(xs)
|
| 111 |
+
def seg_w(i):
|
| 112 |
+
if i < n - 1:
|
| 113 |
+
return xs[i + 1] - xs[i]
|
| 114 |
+
return 0.50
|
| 115 |
+
|
| 116 |
+
bottom_chord = []
|
| 117 |
+
for i in range(n):
|
| 118 |
+
w = seg_w(i)
|
| 119 |
+
bottom_chord.append(sandbox.add_beam(xs[i], bottom_y, w, chord_h, 0, chord_density))
|
| 120 |
+
for i in range(n - 1):
|
| 121 |
+
ax = (xs[i] + xs[i + 1]) / 2.0
|
| 122 |
+
sandbox.add_joint(bottom_chord[i], bottom_chord[i + 1], (ax, bottom_y), type="rigid")
|
| 123 |
+
|
| 124 |
+
top_chord = []
|
| 125 |
+
for i in range(n):
|
| 126 |
+
w = seg_w(i)
|
| 127 |
+
ty = top_y - (xs[i] - xs[0]) * 0.03
|
| 128 |
+
top_chord.append(sandbox.add_beam(xs[i], ty, w, chord_h, 0, chord_density))
|
| 129 |
+
for i in range(n - 1):
|
| 130 |
+
ax = (xs[i] + xs[i + 1]) / 2.0
|
| 131 |
+
ay = (top_chord[i].position.y + top_chord[i + 1].position.y) / 2.0
|
| 132 |
+
sandbox.add_joint(top_chord[i], top_chord[i + 1], (ax, ay), type="rigid")
|
| 133 |
+
|
| 134 |
+
for i in range(n):
|
| 135 |
+
by_i = bottom_chord[i].position.y
|
| 136 |
+
ty_i = top_chord[i].position.y
|
| 137 |
+
vy = (by_i + ty_i) / 2.0
|
| 138 |
+
vh = ty_i - by_i - chord_h - 0.03
|
| 139 |
+
if vh > 0.06:
|
| 140 |
+
vert = sandbox.add_beam(xs[i], vy, web_w, vh, 0, web_density)
|
| 141 |
+
sandbox.add_joint(bottom_chord[i], vert, (xs[i], by_i + chord_h / 2.0), type="rigid")
|
| 142 |
+
sandbox.add_joint(top_chord[i], vert, (xs[i], ty_i - chord_h / 2.0), type="rigid")
|
| 143 |
+
|
| 144 |
+
for i in range(n - 1):
|
| 145 |
+
cx = (xs[i] + xs[i + 1]) / 2.0
|
| 146 |
+
if FORBIDDEN_LO <= cx <= FORBIDDEN_HI:
|
| 147 |
+
continue
|
| 148 |
+
dx = xs[i + 1] - xs[i]
|
| 149 |
+
by_i = bottom_chord[i].position.y
|
| 150 |
+
ty_ip1 = top_chord[i + 1].position.y
|
| 151 |
+
dy_up = ty_ip1 - by_i
|
| 152 |
+
d_up = min(4.0, math.sqrt(dx * dx + dy_up * dy_up) * 0.96)
|
| 153 |
+
ang_up = math.atan2(dy_up, dx)
|
| 154 |
+
cy_up = (by_i + ty_ip1) / 2.0
|
| 155 |
+
diag_up = sandbox.add_beam(cx, cy_up, diag_w, d_up, ang_up, web_density)
|
| 156 |
+
sandbox.add_joint(bottom_chord[i], diag_up, (xs[i] + 0.06, by_i + 0.02), type="rigid")
|
| 157 |
+
sandbox.add_joint(top_chord[i + 1], diag_up, (xs[i + 1] - 0.06, ty_ip1 - 0.02), type="rigid")
|
| 158 |
+
ty_i = top_chord[i].position.y
|
| 159 |
+
by_ip1 = bottom_chord[i + 1].position.y
|
| 160 |
+
dy_dn = ty_i - by_ip1
|
| 161 |
+
d_dn = min(4.0, math.sqrt(dx * dx + dy_dn * dy_dn) * 0.96)
|
| 162 |
+
ang_dn = math.atan2(dy_dn, -dx)
|
| 163 |
+
cy_dn = (ty_i + by_ip1) / 2.0
|
| 164 |
+
diag_dn = sandbox.add_beam(cx, cy_dn, diag_w, d_dn, math.pi - abs(ang_dn), web_density)
|
| 165 |
+
sandbox.add_joint(top_chord[i], diag_dn, (xs[i] + 0.06, ty_i - 0.02), type="rigid")
|
| 166 |
+
sandbox.add_joint(bottom_chord[i + 1], diag_dn, (xs[i + 1] - 0.06, by_ip1 + 0.02), type="rigid")
|
| 167 |
+
|
| 168 |
+
last_b = bottom_chord[-1]
|
| 169 |
+
last_t = top_chord[-1]
|
| 170 |
+
tip_x = xs[-1] + 0.25
|
| 171 |
+
tip_by = last_b.position.y
|
| 172 |
+
tip_ty = last_t.position.y
|
| 173 |
+
tip_mid_y = (tip_by + tip_ty) / 2.0
|
| 174 |
+
tip_h = abs(tip_ty - tip_by) - chord_h - 0.03
|
| 175 |
+
if tip_h > 0.06:
|
| 176 |
+
tip_close = sandbox.add_beam(tip_x, tip_mid_y, web_w, tip_h, 0, web_density)
|
| 177 |
+
sandbox.add_joint(last_b, tip_close, (tip_x, tip_by + chord_h / 2.0), type="rigid")
|
| 178 |
+
sandbox.add_joint(last_t, tip_close, (tip_x, tip_ty - chord_h / 2.0), type="rigid")
|
| 179 |
+
|
| 180 |
+
ground_y = 1.0
|
| 181 |
+
sandbox.add_joint(bottom_chord[0], None, (5.75, ground_y), type="rigid")
|
| 182 |
+
total_mass = sandbox.get_structure_mass()
|
| 183 |
+
mass_limit = sandbox.get_structure_mass_limit()
|
| 184 |
+
if total_mass > mass_limit:
|
| 185 |
+
raise ValueError(f"Mass {total_mass} exceeds {mass_limit}")
|
| 186 |
+
return bottom_chord[0]
|
| 187 |
+
|
| 188 |
+
def agent_action_stage_3(sandbox, agent_body, step_count):
|
| 189 |
+
pass
|
| 190 |
+
|
| 191 |
+
def build_agent_stage_2(sandbox):
|
| 192 |
+
component_area = 3.0 * 4.0 * 4.0
|
| 193 |
+
density = 0.95 * sandbox.get_structure_mass_limit() / component_area
|
| 194 |
+
|
| 195 |
+
root_slab = sandbox.add_beam(6.5, 3.0, 4.0, 4.0, 0, density)
|
| 196 |
+
middle_slab = sandbox.add_beam(9.5, 3.0, 4.0, 4.0, 0, density)
|
| 197 |
+
tip_slab = sandbox.add_beam(13.0, 5.0, 4.0, 4.0, 0, density)
|
| 198 |
+
|
| 199 |
+
sandbox.add_joint(root_slab, middle_slab, (8.0, 3.0), type="rigid")
|
| 200 |
+
sandbox.add_joint(middle_slab, tip_slab, (11.25, 4.0), type="rigid")
|
| 201 |
+
sandbox.add_joint(root_slab, None, (6.5, 1.0), type="rigid")
|
| 202 |
+
|
| 203 |
+
if sandbox.get_structure_mass() > sandbox.get_structure_mass_limit():
|
| 204 |
+
raise ValueError("Structure exceeds the available mass budget")
|
| 205 |
+
return root_slab
|
| 206 |
+
|
| 207 |
+
def agent_action_stage_2(sandbox, agent_body, step_count):
|
| 208 |
+
pass
|
| 209 |
+
|
| 210 |
+
def build_agent_stage_1(sandbox):
|
| 211 |
+
component_area = 1.2 * 3.2 + 2.0 * 1.0 + 4.0 * 4.0 + 4.0 * 4.0
|
| 212 |
+
density = 0.95 * sandbox.get_structure_mass_limit() / component_area
|
| 213 |
+
mast = sandbox.add_beam(5.75, 3.2, 1.2, 3.2, 0, density)
|
| 214 |
+
root_plate = sandbox.add_beam(6.5, 5.0, 2.0, 1.0, 0, density)
|
| 215 |
+
middle_plate = sandbox.add_beam(9.5, 5.0, 4.0, 4.0, 0, density)
|
| 216 |
+
tip_plate = sandbox.add_beam(13.0, 5.0, 4.0, 4.0, 0, density)
|
| 217 |
+
|
| 218 |
+
sandbox.add_joint(mast, root_plate, (5.75, 4.7), type="rigid")
|
| 219 |
+
sandbox.add_joint(root_plate, middle_plate, (7.5, 5.0), type="rigid")
|
| 220 |
+
sandbox.add_joint(middle_plate, tip_plate, (11.25, 5.0), type="rigid")
|
| 221 |
+
sandbox.add_joint(mast, None, (5.75, 1.0), type="rigid")
|
| 222 |
+
|
| 223 |
+
if sandbox.get_structure_mass() > sandbox.get_structure_mass_limit():
|
| 224 |
+
raise ValueError("Structure exceeds the available mass budget")
|
| 225 |
+
return mast
|
| 226 |
+
|
| 227 |
+
def agent_action_stage_1(sandbox, agent_body, step_count):
|
| 228 |
+
pass
|
| 229 |
+
|
| 230 |
+
def build_agent(sandbox):
|
| 231 |
+
x_min, x_max, _, _ = sandbox.get_build_zone()
|
| 232 |
+
support_lo, support_hi = 5.0, 6.5
|
| 233 |
+
bw, bh = 0.35, 0.25
|
| 234 |
+
density = 1.2
|
| 235 |
+
bottom_y = 2.0
|
| 236 |
+
top_y = 5.8
|
| 237 |
+
xs = [5.75, 6.5, 8.0, 9.0, 10.35, 12.0, 14.0, 15.0]
|
| 238 |
+
xs = [min(x_max - bw / 2, max(x_min + bw / 2, x)) for x in xs]
|
| 239 |
+
def seg(i):
|
| 240 |
+
return (xs[i + 1] - xs[i]) if i < len(xs) - 1 else 0.8
|
| 241 |
+
bottom_beams = [sandbox.add_beam(xs[i], bottom_y, seg(i), bh, 0, density) for i in range(len(xs))]
|
| 242 |
+
for i in range(len(bottom_beams) - 1):
|
| 243 |
+
ax = (xs[i] + xs[i + 1]) / 2
|
| 244 |
+
sandbox.add_joint(bottom_beams[i], bottom_beams[i + 1], (ax, bottom_y), type="rigid")
|
| 245 |
+
top_beams = [sandbox.add_beam(xs[i], top_y, seg(i), bh, 0, density) for i in range(len(xs))]
|
| 246 |
+
for i in range(len(top_beams) - 1):
|
| 247 |
+
ax = (xs[i] + xs[i + 1]) / 2
|
| 248 |
+
sandbox.add_joint(top_beams[i], top_beams[i + 1], (ax, top_y), type="rigid")
|
| 249 |
+
vy = (bottom_y + top_y) / 2
|
| 250 |
+
vh = top_y - bottom_y - bh - 0.03
|
| 251 |
+
for i in range(len(xs)):
|
| 252 |
+
vert = sandbox.add_beam(xs[i], vy, 0.25, vh, 0, density)
|
| 253 |
+
sandbox.add_joint(bottom_beams[i], vert, (xs[i], bottom_y + bh / 2), type="rigid")
|
| 254 |
+
sandbox.add_joint(top_beams[i], vert, (xs[i], top_y - bh / 2), type="rigid")
|
| 255 |
+
for i in range(len(xs) - 1):
|
| 256 |
+
dx = xs[i + 1] - xs[i]
|
| 257 |
+
d = math.sqrt(dx**2 + (top_y - bottom_y)**2) * 0.92
|
| 258 |
+
ang = math.atan2(top_y - bottom_y, dx)
|
| 259 |
+
diag1 = sandbox.add_beam((xs[i] + xs[i + 1]) / 2, vy, 0.2, d, ang, density)
|
| 260 |
+
sandbox.add_joint(bottom_beams[i], diag1, (xs[i] + 0.06, bottom_y + 0.02), type="rigid")
|
| 261 |
+
sandbox.add_joint(top_beams[i + 1], diag1, (xs[i + 1] - 0.06, top_y - 0.02), type="rigid")
|
| 262 |
+
diag2 = sandbox.add_beam((xs[i] + xs[i + 1]) / 2, vy, 0.2, d, -ang, density)
|
| 263 |
+
sandbox.add_joint(bottom_beams[i + 1], diag2, (xs[i + 1] - 0.06, bottom_y + 0.02), type="rigid")
|
| 264 |
+
sandbox.add_joint(top_beams[i], diag2, (xs[i] + 0.06, top_y - 0.02), type="rigid")
|
| 265 |
+
ground_y = 1.0
|
| 266 |
+
sandbox.add_joint(bottom_beams[0], None, (5.75, ground_y), type="rigid")
|
| 267 |
+
return bottom_beams[0]
|
| 268 |
+
|
| 269 |
+
def agent_action(sandbox, agent_body, step_count):
|
| 270 |
+
pass
|
tasks/Category6_ExoticPhysics/E_06/environment.py
ADDED
|
@@ -0,0 +1,579 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 import polygonShape, world
|
| 8 |
+
|
| 9 |
+
TIME_STEP = 1.0 / 60.0
|
| 10 |
+
INV_TIME_STEP = 1.0 / TIME_STEP
|
| 11 |
+
|
| 12 |
+
class Sandbox:
|
| 13 |
+
MAX_STEPS = 500
|
| 14 |
+
BUILD_ZONE_X_MIN = 5.0
|
| 15 |
+
BUILD_ZONE_X_MAX = 15.0
|
| 16 |
+
BUILD_ZONE_Y_MIN = 1.5
|
| 17 |
+
BUILD_ZONE_Y_MAX = 8.0
|
| 18 |
+
MAX_STRUCTURE_MASS = 120.0
|
| 19 |
+
MAX_GROUND_ANCHORS = 1
|
| 20 |
+
MAX_BEAMS = 48
|
| 21 |
+
MAX_JOINTS = 75
|
| 22 |
+
MIN_ANCHOR_SPACING = 0.7
|
| 23 |
+
FORBIDDEN_ZONE_X_LO = 9.7
|
| 24 |
+
FORBIDDEN_ZONE_X_HI = 10.3
|
| 25 |
+
DAMAGE_HOTSPOT_X_LO = 8.5
|
| 26 |
+
DAMAGE_HOTSPOT_X_HI = 11.0
|
| 27 |
+
DAMAGE_HOTSPOT_MULT = 1.35
|
| 28 |
+
MIN_BEAM_SIZE = 0.1
|
| 29 |
+
MAX_BEAM_SIZE = 4.0
|
| 30 |
+
ALLOWED_ANCHOR_X_LO = 5.0
|
| 31 |
+
ALLOWED_ANCHOR_X_HI = 6.5
|
| 32 |
+
SUPPORT_CENTER_X = 5.75
|
| 33 |
+
DISTANCE_SCALE_FACTOR = 0.6
|
| 34 |
+
NOISE_STRENGTH = 42.0
|
| 35 |
+
JOINT_BREAK_FORCE = 280800.0
|
| 36 |
+
JOINT_BREAK_TORQUE = 414000.0
|
| 37 |
+
DAMAGE_FORCE_THRESH = 43200.0
|
| 38 |
+
DAMAGE_TORQUE_THRESH = 64800.0
|
| 39 |
+
DAMAGE_FORCE_RATE = 2.9 / 3750.0
|
| 40 |
+
DAMAGE_TORQUE_RATE = 2.1 / 3750.0
|
| 41 |
+
DAMAGE_LIMIT = 100.0
|
| 42 |
+
CASCADE_SHOCK_DAMAGE = 26.0
|
| 43 |
+
CASCADE_RADIUS = 2.2
|
| 44 |
+
GROUND_DAMAGE_FORCE_THRESH = 21600.0
|
| 45 |
+
GROUND_DAMAGE_TORQUE_THRESH = 36000.0
|
| 46 |
+
GROUND_DAMAGE_FORCE_RATE = 4.8 / 3750.0
|
| 47 |
+
GROUND_DAMAGE_TORQUE_RATE = 3.5 / 3750.0
|
| 48 |
+
BEAM_ANGVEL_THRESH = 2.2
|
| 49 |
+
BEAM_ANGVEL_TOLERANCE_STEPS = 10
|
| 50 |
+
PHASED_STORM_START = 100
|
| 51 |
+
PHASED_STORM_END = 450
|
| 52 |
+
PHASED_STORM_MULT = 1.9
|
| 53 |
+
COHERENT_PULSE_INTERVAL = 58
|
| 54 |
+
COHERENT_PULSE_FORCE = 36.0
|
| 55 |
+
COHERENT_MOMENT_BASE = 18.0
|
| 56 |
+
def __init__(self, *, terrain_config=None, physics_config=None):
|
| 57 |
+
terrain_config = terrain_config or {}
|
| 58 |
+
physics_config = physics_config or {}
|
| 59 |
+
self._terrain_config = dict(terrain_config)
|
| 60 |
+
self._physics_config = dict(physics_config)
|
| 61 |
+
self._rng = random.Random(int(physics_config.get("random_seed", 123)))
|
| 62 |
+
gravity = tuple(physics_config.get("gravity", (0, -10)))
|
| 63 |
+
self._linear_damping = float(physics_config.get("linear_damping", 0.0))
|
| 64 |
+
self._angular_damping = float(physics_config.get("angular_damping", 1.6))
|
| 65 |
+
self._noise_strength = float(physics_config.get("noise_strength", self.NOISE_STRENGTH))
|
| 66 |
+
_pc = physics_config
|
| 67 |
+
if "coherent_pulse_interval" in _pc:
|
| 68 |
+
self.COHERENT_PULSE_INTERVAL = int(_pc["coherent_pulse_interval"])
|
| 69 |
+
if "coherent_pulse_force" in _pc:
|
| 70 |
+
self.COHERENT_PULSE_FORCE = float(_pc["coherent_pulse_force"])
|
| 71 |
+
if "joint_break_force" in _pc:
|
| 72 |
+
self.JOINT_BREAK_FORCE = float(_pc["joint_break_force"])
|
| 73 |
+
if "joint_break_torque" in _pc:
|
| 74 |
+
self.JOINT_BREAK_TORQUE = float(_pc["joint_break_torque"])
|
| 75 |
+
if "damage_limit" in _pc:
|
| 76 |
+
self.DAMAGE_LIMIT = float(_pc["damage_limit"])
|
| 77 |
+
if "damage_force_thresh" in _pc:
|
| 78 |
+
self.DAMAGE_FORCE_THRESH = float(_pc["damage_force_thresh"])
|
| 79 |
+
if "damage_torque_thresh" in _pc:
|
| 80 |
+
self.DAMAGE_TORQUE_THRESH = float(_pc["damage_torque_thresh"])
|
| 81 |
+
if "cascade_shock_damage" in _pc:
|
| 82 |
+
self.CASCADE_SHOCK_DAMAGE = float(_pc["cascade_shock_damage"])
|
| 83 |
+
if "beam_angvel_thresh" in _pc:
|
| 84 |
+
self.BEAM_ANGVEL_THRESH = float(_pc["beam_angvel_thresh"])
|
| 85 |
+
if "beam_angvel_tolerance_steps" in _pc:
|
| 86 |
+
self.BEAM_ANGVEL_TOLERANCE_STEPS = int(_pc["beam_angvel_tolerance_steps"])
|
| 87 |
+
if "phased_storm_mult" in _pc:
|
| 88 |
+
self.PHASED_STORM_MULT = float(_pc["phased_storm_mult"])
|
| 89 |
+
if "phased_storm_start" in _pc:
|
| 90 |
+
self.PHASED_STORM_START = int(_pc["phased_storm_start"])
|
| 91 |
+
if "phased_storm_end" in _pc:
|
| 92 |
+
self.PHASED_STORM_END = int(_pc["phased_storm_end"])
|
| 93 |
+
if "burst_prob" in _pc:
|
| 94 |
+
self._burst_prob = float(_pc["burst_prob"])
|
| 95 |
+
else:
|
| 96 |
+
self._burst_prob = 0.026
|
| 97 |
+
self._max_structure_mass = float(terrain_config.get("max_structure_mass", self.MAX_STRUCTURE_MASS))
|
| 98 |
+
self._max_ground_anchors = int(terrain_config.get("max_ground_anchors", self.MAX_GROUND_ANCHORS))
|
| 99 |
+
self._forbidden_zone_x_lo = float(terrain_config.get("forbidden_zone_x_lo", self.FORBIDDEN_ZONE_X_LO))
|
| 100 |
+
self._forbidden_zone_x_hi = float(terrain_config.get("forbidden_zone_x_hi", self.FORBIDDEN_ZONE_X_HI))
|
| 101 |
+
self._allowed_anchor_x_lo = float(terrain_config.get("allowed_anchor_x_lo", self.ALLOWED_ANCHOR_X_LO))
|
| 102 |
+
self._allowed_anchor_x_hi = float(terrain_config.get("allowed_anchor_x_hi", self.ALLOWED_ANCHOR_X_HI))
|
| 103 |
+
self._world = world(gravity=gravity, doSleep=True)
|
| 104 |
+
self._bodies = []
|
| 105 |
+
self._joints = []
|
| 106 |
+
self._joint_is_ground = {}
|
| 107 |
+
self._joint_anchor = {}
|
| 108 |
+
self._terrain_bodies = {}
|
| 109 |
+
self._joint_peak_forces = {}
|
| 110 |
+
self._joint_peak_torques = {}
|
| 111 |
+
self._joint_damage = {}
|
| 112 |
+
self._beam_high_spin_steps = {}
|
| 113 |
+
self._joint_fail_step = {}
|
| 114 |
+
self._joint_fail_pos = {}
|
| 115 |
+
self._joint_fail_type = {}
|
| 116 |
+
self._joint_fail_force = {}
|
| 117 |
+
self._joint_fail_torque = {}
|
| 118 |
+
self._joint_fail_damage = {}
|
| 119 |
+
self._body_destroy_step = {}
|
| 120 |
+
self._body_destroy_pos = {}
|
| 121 |
+
self._body_destroy_reason = {}
|
| 122 |
+
self._beam_peak_angvel = {}
|
| 123 |
+
self._peak_body_angvel = 0.0
|
| 124 |
+
self._num_joints_removed_force_torque = 0
|
| 125 |
+
self._num_joints_removed_damage = 0
|
| 126 |
+
self._num_bodies_destroyed_spin = 0
|
| 127 |
+
self._num_bodies_destroyed_orphan = 0
|
| 128 |
+
self._current_phase = "STABILIZATION"
|
| 129 |
+
self._step_counter = 0
|
| 130 |
+
self._burst_remaining = 0
|
| 131 |
+
self._ground_anchor_count = 0
|
| 132 |
+
self._ground_anchor_x = []
|
| 133 |
+
self.world = self._world
|
| 134 |
+
self.bodies = self._bodies
|
| 135 |
+
self.joints = self._joints
|
| 136 |
+
self._create_terrain(terrain_config)
|
| 137 |
+
def _create_terrain(self, terrain_config: dict):
|
| 138 |
+
ground_length = 40.0
|
| 139 |
+
ground_height = 1.0
|
| 140 |
+
ground = self._world.CreateStaticBody(
|
| 141 |
+
position=(ground_length / 2, ground_height / 2),
|
| 142 |
+
fixtures=Box2D.b2FixtureDef(
|
| 143 |
+
shape=polygonShape(box=(ground_length / 2, ground_height / 2)),
|
| 144 |
+
friction=0.6,
|
| 145 |
+
),
|
| 146 |
+
)
|
| 147 |
+
self._terrain_bodies["ground"] = ground
|
| 148 |
+
self._ground_y = ground_height
|
| 149 |
+
def _get_noise_multiplier(self):
|
| 150 |
+
if self._burst_remaining > 0:
|
| 151 |
+
self._burst_remaining -= 1
|
| 152 |
+
return 3.8
|
| 153 |
+
if self._step_counter > 0 and self._rng.random() < getattr(self, "_burst_prob", 0.026):
|
| 154 |
+
self._burst_remaining = 12
|
| 155 |
+
mult = 1.0
|
| 156 |
+
if self.PHASED_STORM_START <= self._step_counter <= self.PHASED_STORM_END:
|
| 157 |
+
mult *= self.PHASED_STORM_MULT
|
| 158 |
+
return mult
|
| 159 |
+
def _apply_impulses(self, sigma_mult):
|
| 160 |
+
sigma = self._noise_strength * sigma_mult
|
| 161 |
+
total_mass = sum(b.mass for b in self._bodies) or 1.0
|
| 162 |
+
mass_factor = 1.0 + 0.25 * math.sqrt(total_mass / 60.0)
|
| 163 |
+
if self._step_counter > 0 and self._step_counter % self.COHERENT_PULSE_INTERVAL == 0:
|
| 164 |
+
sign = 1 if (self._step_counter // self.COHERENT_PULSE_INTERVAL) % 2 == 0 else -1
|
| 165 |
+
for body in self._bodies:
|
| 166 |
+
dx = body.position.x - self.SUPPORT_CENTER_X
|
| 167 |
+
tau = sign * self.COHERENT_MOMENT_BASE * mass_factor * max(0, dx) / 5.0
|
| 168 |
+
body.ApplyTorque(tau, wake=True)
|
| 169 |
+
fx = sign * self.COHERENT_PULSE_FORCE * mass_factor * (0.3 + 0.7 * max(0, dx) / 10.0)
|
| 170 |
+
body.ApplyForceToCenter((fx, 0), wake=True)
|
| 171 |
+
span = self.BUILD_ZONE_X_MAX - self.SUPPORT_CENTER_X
|
| 172 |
+
for i, body in enumerate(self._bodies):
|
| 173 |
+
dx = body.position.x - self.SUPPORT_CENTER_X
|
| 174 |
+
dist_mult = 1.0 + self.DISTANCE_SCALE_FACTOR * max(0, dx) / max(span, 0.1)
|
| 175 |
+
s = sigma * dist_mult
|
| 176 |
+
if self._rng.random() < 0.28:
|
| 177 |
+
if i % 2 == 0:
|
| 178 |
+
fx = self._rng.gauss(0, s) + 1.6 * s
|
| 179 |
+
fy = self._rng.gauss(0, s * 0.8)
|
| 180 |
+
else:
|
| 181 |
+
fx = self._rng.gauss(0, s) - 1.6 * s
|
| 182 |
+
fy = self._rng.gauss(0, s * 0.8)
|
| 183 |
+
else:
|
| 184 |
+
fx = self._rng.gauss(0, s)
|
| 185 |
+
fy = self._rng.gauss(0, s)
|
| 186 |
+
body.ApplyForceToCenter((fx * mass_factor, fy * mass_factor), wake=True)
|
| 187 |
+
def _get_joint_anchor_pos(self, joint):
|
| 188 |
+
return self._joint_anchor.get(joint, (0, 0))
|
| 189 |
+
def _record_and_destroy_joint(self, joint, fail_reason):
|
| 190 |
+
ax, ay = self._get_joint_anchor_pos(joint)
|
| 191 |
+
self._joint_fail_step[joint] = self._step_counter
|
| 192 |
+
self._joint_fail_pos[joint] = (ax, ay)
|
| 193 |
+
self._joint_fail_type[joint] = fail_reason
|
| 194 |
+
self._joint_fail_force[joint] = self._joint_peak_forces.get(joint, 0.0)
|
| 195 |
+
self._joint_fail_torque[joint] = self._joint_peak_torques.get(joint, 0.0)
|
| 196 |
+
self._joint_fail_damage[joint] = self._joint_damage.get(joint, 0.0)
|
| 197 |
+
self._world.DestroyJoint(joint)
|
| 198 |
+
self._joints.remove(joint)
|
| 199 |
+
self._joint_peak_forces.pop(joint, None)
|
| 200 |
+
self._joint_peak_torques.pop(joint, None)
|
| 201 |
+
self._joint_damage.pop(joint, None)
|
| 202 |
+
if self._joint_is_ground.get(joint):
|
| 203 |
+
self._ground_anchor_count = max(0, self._ground_anchor_count - 1)
|
| 204 |
+
anchor_x = self._joint_anchor.get(joint, (0, 0))[0]
|
| 205 |
+
if anchor_x in self._ground_anchor_x:
|
| 206 |
+
self._ground_anchor_x.remove(anchor_x)
|
| 207 |
+
self._joint_is_ground.pop(joint, None)
|
| 208 |
+
self._joint_anchor.pop(joint, None)
|
| 209 |
+
return ax, ay
|
| 210 |
+
def _destroy_body_and_joints(self, body, fail_reason="orphan"):
|
| 211 |
+
to_remove = [j for j in self._joints if j.bodyA == body or j.bodyB == body]
|
| 212 |
+
for joint in to_remove:
|
| 213 |
+
self._record_and_destroy_joint(joint, fail_reason)
|
| 214 |
+
bx, by = body.position.x, body.position.y
|
| 215 |
+
self._body_destroy_step[body] = self._step_counter
|
| 216 |
+
self._body_destroy_pos[body] = (bx, by)
|
| 217 |
+
self._body_destroy_reason[body] = fail_reason
|
| 218 |
+
if fail_reason == "spin":
|
| 219 |
+
self._num_bodies_destroyed_spin += 1
|
| 220 |
+
else:
|
| 221 |
+
self._num_bodies_destroyed_orphan += 1
|
| 222 |
+
self._world.DestroyBody(body)
|
| 223 |
+
self._bodies.remove(body)
|
| 224 |
+
self._beam_high_spin_steps.pop(body, None)
|
| 225 |
+
def step(self, time_step):
|
| 226 |
+
if not math.isclose(float(time_step), TIME_STEP, rel_tol=0.0, abs_tol=1e-12):
|
| 227 |
+
raise ValueError(f"E_06 requires a fixed time step of {TIME_STEP}")
|
| 228 |
+
self._step_counter += 1
|
| 229 |
+
sigma_mult = self._get_noise_multiplier()
|
| 230 |
+
self._apply_impulses(sigma_mult)
|
| 231 |
+
self._world.Step(time_step, 10, 10)
|
| 232 |
+
if self._step_counter == 0:
|
| 233 |
+
self._current_phase = "STABILIZATION"
|
| 234 |
+
elif self.PHASED_STORM_START <= self._step_counter <= self.PHASED_STORM_END:
|
| 235 |
+
self._current_phase = "STORM"
|
| 236 |
+
elif self._step_counter > self.PHASED_STORM_END:
|
| 237 |
+
self._current_phase = "POST_STORM"
|
| 238 |
+
else:
|
| 239 |
+
self._current_phase = "LOADING"
|
| 240 |
+
for body in list(self._bodies):
|
| 241 |
+
av = abs(body.angularVelocity)
|
| 242 |
+
self._beam_peak_angvel[body] = max(self._beam_peak_angvel.get(body, 0.0), av)
|
| 243 |
+
self._peak_body_angvel = max(self._peak_body_angvel, av)
|
| 244 |
+
if av > self.BEAM_ANGVEL_THRESH:
|
| 245 |
+
self._beam_high_spin_steps[body] = self._beam_high_spin_steps.get(body, 0) + 1
|
| 246 |
+
if self._beam_high_spin_steps[body] >= self.BEAM_ANGVEL_TOLERANCE_STEPS:
|
| 247 |
+
self._destroy_body_and_joints(body, fail_reason="spin")
|
| 248 |
+
else:
|
| 249 |
+
self._beam_high_spin_steps[body] = 0
|
| 250 |
+
joints_to_remove = []
|
| 251 |
+
for joint in list(self._joints):
|
| 252 |
+
force = joint.GetReactionForce(INV_TIME_STEP)
|
| 253 |
+
force_mag = math.hypot(force.x, force.y)
|
| 254 |
+
torque_mag = abs(joint.GetReactionTorque(INV_TIME_STEP))
|
| 255 |
+
self._joint_peak_forces[joint] = max(
|
| 256 |
+
self._joint_peak_forces.get(joint, 0.0), force_mag
|
| 257 |
+
)
|
| 258 |
+
self._joint_peak_torques[joint] = max(
|
| 259 |
+
self._joint_peak_torques.get(joint, 0.0), torque_mag
|
| 260 |
+
)
|
| 261 |
+
if force_mag > self.JOINT_BREAK_FORCE or torque_mag > self.JOINT_BREAK_TORQUE:
|
| 262 |
+
joints_to_remove.append((joint, "force_torque"))
|
| 263 |
+
continue
|
| 264 |
+
is_ground = self._joint_is_ground.get(joint, False)
|
| 265 |
+
f_thresh = self.GROUND_DAMAGE_FORCE_THRESH if is_ground else self.DAMAGE_FORCE_THRESH
|
| 266 |
+
t_thresh = self.GROUND_DAMAGE_TORQUE_THRESH if is_ground else self.DAMAGE_TORQUE_THRESH
|
| 267 |
+
f_rate = self.GROUND_DAMAGE_FORCE_RATE if is_ground else self.DAMAGE_FORCE_RATE
|
| 268 |
+
t_rate = self.GROUND_DAMAGE_TORQUE_RATE if is_ground else self.DAMAGE_TORQUE_RATE
|
| 269 |
+
joint_x, _ = self._get_joint_anchor_pos(joint)
|
| 270 |
+
hotspot_mult = (
|
| 271 |
+
self.DAMAGE_HOTSPOT_MULT
|
| 272 |
+
if self.DAMAGE_HOTSPOT_X_LO <= joint_x <= self.DAMAGE_HOTSPOT_X_HI
|
| 273 |
+
else 1.0
|
| 274 |
+
)
|
| 275 |
+
damage = self._joint_damage.get(joint, 0.0)
|
| 276 |
+
if force_mag > f_thresh:
|
| 277 |
+
damage += (force_mag - f_thresh) * f_rate * TIME_STEP * hotspot_mult
|
| 278 |
+
if torque_mag > t_thresh:
|
| 279 |
+
damage += (torque_mag - t_thresh) * t_rate * TIME_STEP * hotspot_mult
|
| 280 |
+
self._joint_damage[joint] = damage
|
| 281 |
+
if damage >= self.DAMAGE_LIMIT:
|
| 282 |
+
joints_to_remove.append((joint, "damage"))
|
| 283 |
+
for entry in joints_to_remove:
|
| 284 |
+
joint, fail_reason = entry
|
| 285 |
+
if fail_reason == "damage":
|
| 286 |
+
self._num_joints_removed_damage += 1
|
| 287 |
+
else:
|
| 288 |
+
self._num_joints_removed_force_torque += 1
|
| 289 |
+
anchor_x, anchor_y = self._record_and_destroy_joint(joint, fail_reason)
|
| 290 |
+
for neighbor in list(self._joints):
|
| 291 |
+
neighbor_x, neighbor_y = self._get_joint_anchor_pos(neighbor)
|
| 292 |
+
distance = math.hypot(
|
| 293 |
+
neighbor_x - anchor_x, neighbor_y - anchor_y
|
| 294 |
+
)
|
| 295 |
+
if 0.01 < distance <= self.CASCADE_RADIUS:
|
| 296 |
+
self._joint_damage[neighbor] = min(
|
| 297 |
+
self.DAMAGE_LIMIT,
|
| 298 |
+
self._joint_damage.get(neighbor, 0.0)
|
| 299 |
+
+ self.CASCADE_SHOCK_DAMAGE,
|
| 300 |
+
)
|
| 301 |
+
def add_beam(self, x, y, width, height, angle=0, density=1.0):
|
| 302 |
+
if len(self._bodies) >= self.MAX_BEAMS:
|
| 303 |
+
raise ValueError(f"Maximum {self.MAX_BEAMS} beams allowed")
|
| 304 |
+
if self._forbidden_zone_x_lo <= x <= self._forbidden_zone_x_hi:
|
| 305 |
+
raise ValueError(
|
| 306 |
+
f"Forbidden zone: beam center x={x:.2f} falls in [{self._forbidden_zone_x_lo}, {self._forbidden_zone_x_hi}]"
|
| 307 |
+
)
|
| 308 |
+
values = (x, y, width, height, angle, density)
|
| 309 |
+
if not all(math.isfinite(float(value)) for value in values):
|
| 310 |
+
raise ValueError("Beam parameters must all be finite")
|
| 311 |
+
if not self.MIN_BEAM_SIZE <= width <= self.MAX_BEAM_SIZE:
|
| 312 |
+
raise ValueError(
|
| 313 |
+
f"Beam width must be in [{self.MIN_BEAM_SIZE}, {self.MAX_BEAM_SIZE}]"
|
| 314 |
+
)
|
| 315 |
+
if not self.MIN_BEAM_SIZE <= height <= self.MAX_BEAM_SIZE:
|
| 316 |
+
raise ValueError(
|
| 317 |
+
f"Beam height must be in [{self.MIN_BEAM_SIZE}, {self.MAX_BEAM_SIZE}]"
|
| 318 |
+
)
|
| 319 |
+
if density <= 0.0:
|
| 320 |
+
raise ValueError("Beam density must be positive")
|
| 321 |
+
body = self._world.CreateDynamicBody(
|
| 322 |
+
position=(x, y),
|
| 323 |
+
angle=angle,
|
| 324 |
+
fixtures=Box2D.b2FixtureDef(
|
| 325 |
+
shape=polygonShape(box=(width / 2, height / 2)),
|
| 326 |
+
density=density,
|
| 327 |
+
friction=0.5,
|
| 328 |
+
),
|
| 329 |
+
)
|
| 330 |
+
body.linearDamping = self._linear_damping
|
| 331 |
+
body.angularDamping = self._angular_damping
|
| 332 |
+
body.userData = {"width": width, "height": height}
|
| 333 |
+
self._bodies.append(body)
|
| 334 |
+
return body
|
| 335 |
+
def add_joint(self, body_a, body_b, anchor_point, type="rigid"):
|
| 336 |
+
if len(self._joints) >= self.MAX_JOINTS:
|
| 337 |
+
raise ValueError(f"Maximum {self.MAX_JOINTS} joints allowed")
|
| 338 |
+
if body_a is None:
|
| 339 |
+
raise ValueError("add_joint: body_a cannot be None.")
|
| 340 |
+
anchor_x, anchor_y = anchor_point[0], anchor_point[1]
|
| 341 |
+
if not math.isfinite(float(anchor_x)) or not math.isfinite(float(anchor_y)):
|
| 342 |
+
raise ValueError("Joint anchor coordinates must be finite")
|
| 343 |
+
if body_a not in self._bodies:
|
| 344 |
+
raise ValueError("add_joint: body_a must be an active agent beam")
|
| 345 |
+
if body_b is not None and body_b not in self._bodies:
|
| 346 |
+
raise ValueError("add_joint: body_b must be an active agent beam or None")
|
| 347 |
+
is_ground = body_b is None
|
| 348 |
+
if is_ground:
|
| 349 |
+
if self._ground_anchor_count >= self._max_ground_anchors:
|
| 350 |
+
raise ValueError(f"Maximum {self._max_ground_anchors} ground anchors allowed")
|
| 351 |
+
if not (self._allowed_anchor_x_lo <= anchor_x <= self._allowed_anchor_x_hi):
|
| 352 |
+
raise ValueError(
|
| 353 |
+
f"Ground anchor x={anchor_x:.2f} outside allowed zone [{self._allowed_anchor_x_lo}, {self._allowed_anchor_x_hi}]"
|
| 354 |
+
)
|
| 355 |
+
if not math.isclose(
|
| 356 |
+
float(anchor_y), self._ground_y, rel_tol=0.0, abs_tol=1e-9
|
| 357 |
+
):
|
| 358 |
+
raise ValueError(
|
| 359 |
+
f"Ground-anchor y must equal the ground surface y={self._ground_y}"
|
| 360 |
+
)
|
| 361 |
+
for gx in self._ground_anchor_x:
|
| 362 |
+
if abs(anchor_x - gx) < self.MIN_ANCHOR_SPACING:
|
| 363 |
+
raise ValueError(f"Ground anchors must be at least {self.MIN_ANCHOR_SPACING} m apart")
|
| 364 |
+
if body_b is None:
|
| 365 |
+
body_b = self._terrain_bodies.get("ground")
|
| 366 |
+
if body_b is None:
|
| 367 |
+
raise ValueError("add_joint: Cannot anchor to ground.")
|
| 368 |
+
if type == "rigid":
|
| 369 |
+
joint = self._world.CreateWeldJoint(
|
| 370 |
+
bodyA=body_a, bodyB=body_b,
|
| 371 |
+
anchor=(anchor_x, anchor_y), collideConnected=False,
|
| 372 |
+
)
|
| 373 |
+
elif type == "pivot":
|
| 374 |
+
joint = self._world.CreateRevoluteJoint(
|
| 375 |
+
bodyA=body_a, bodyB=body_b,
|
| 376 |
+
anchor=(anchor_x, anchor_y), collideConnected=False,
|
| 377 |
+
)
|
| 378 |
+
else:
|
| 379 |
+
raise ValueError(f"Unknown joint type: {type}")
|
| 380 |
+
self._joints.append(joint)
|
| 381 |
+
self._joint_peak_forces[joint] = 0.0
|
| 382 |
+
self._joint_peak_torques[joint] = 0.0
|
| 383 |
+
self._joint_damage[joint] = 0.0
|
| 384 |
+
self._joint_is_ground[joint] = is_ground
|
| 385 |
+
self._joint_anchor[joint] = (anchor_x, anchor_y)
|
| 386 |
+
if is_ground:
|
| 387 |
+
self._ground_anchor_count += 1
|
| 388 |
+
self._ground_anchor_x.append(anchor_x)
|
| 389 |
+
return joint
|
| 390 |
+
def get_structure_mass(self):
|
| 391 |
+
return sum(b.mass for b in self._bodies)
|
| 392 |
+
def get_build_zone(self):
|
| 393 |
+
return (self.BUILD_ZONE_X_MIN, self.BUILD_ZONE_X_MAX, self.BUILD_ZONE_Y_MIN, self.BUILD_ZONE_Y_MAX)
|
| 394 |
+
def get_structure_mass_limit(self):
|
| 395 |
+
return self._max_structure_mass
|
| 396 |
+
def _get_per_body_angvel_data(self):
|
| 397 |
+
result = []
|
| 398 |
+
seen_body_ids = set()
|
| 399 |
+
for body in self._bodies:
|
| 400 |
+
body_id = id(body)
|
| 401 |
+
seen_body_ids.add(body_id)
|
| 402 |
+
dx = body.position.x - self.SUPPORT_CENTER_X
|
| 403 |
+
peak_av = self._beam_peak_angvel.get(body, 0.0)
|
| 404 |
+
consec = self._beam_high_spin_steps.get(body, 0)
|
| 405 |
+
w = 0.0
|
| 406 |
+
h = 0.0
|
| 407 |
+
if hasattr(body, "userData") and body.userData:
|
| 408 |
+
w = float(body.userData.get("width", 0.0))
|
| 409 |
+
h = float(body.userData.get("height", 0.0))
|
| 410 |
+
result.append({
|
| 411 |
+
"pos_x": body.position.x,
|
| 412 |
+
"pos_y": body.position.y,
|
| 413 |
+
"dist_from_support": dx,
|
| 414 |
+
"peak_angvel": peak_av,
|
| 415 |
+
"consec_high_steps": consec,
|
| 416 |
+
"beam_width": w,
|
| 417 |
+
"beam_height": h,
|
| 418 |
+
"mass": body.mass,
|
| 419 |
+
"status": "active",
|
| 420 |
+
})
|
| 421 |
+
for body, pav in self._beam_peak_angvel.items():
|
| 422 |
+
if id(body) in seen_body_ids:
|
| 423 |
+
continue
|
| 424 |
+
destroy_pos = self._body_destroy_pos.get(body)
|
| 425 |
+
destroy_reason = self._body_destroy_reason.get(body, "unknown")
|
| 426 |
+
px, py = destroy_pos if destroy_pos else (0.0, 0.0)
|
| 427 |
+
dx = px - self.SUPPORT_CENTER_X
|
| 428 |
+
result.append({
|
| 429 |
+
"pos_x": px,
|
| 430 |
+
"pos_y": py,
|
| 431 |
+
"dist_from_support": dx,
|
| 432 |
+
"peak_angvel": pav,
|
| 433 |
+
"consec_high_steps": 0,
|
| 434 |
+
"beam_width": 0.0,
|
| 435 |
+
"beam_height": 0.0,
|
| 436 |
+
"mass": 0.0,
|
| 437 |
+
"status": "destroyed",
|
| 438 |
+
"destroy_reason": destroy_reason,
|
| 439 |
+
})
|
| 440 |
+
result.sort(key=lambda d: d["peak_angvel"], reverse=True)
|
| 441 |
+
return result
|
| 442 |
+
def _get_per_joint_stress_data(self):
|
| 443 |
+
result = []
|
| 444 |
+
for joint in self._joints:
|
| 445 |
+
anchor = self._joint_anchor.get(joint, (0.0, 0.0))
|
| 446 |
+
dx = anchor[0] - self.SUPPORT_CENTER_X
|
| 447 |
+
result.append({
|
| 448 |
+
"anchor_x": anchor[0],
|
| 449 |
+
"anchor_y": anchor[1],
|
| 450 |
+
"dist_from_support": dx,
|
| 451 |
+
"peak_force": self._joint_peak_forces.get(joint, 0.0),
|
| 452 |
+
"peak_torque": self._joint_peak_torques.get(joint, 0.0),
|
| 453 |
+
"damage": self._joint_damage.get(joint, 0.0),
|
| 454 |
+
"is_ground": self._joint_is_ground.get(joint, False),
|
| 455 |
+
"status": "active",
|
| 456 |
+
})
|
| 457 |
+
for joint, step in self._joint_fail_step.items():
|
| 458 |
+
pos = self._joint_fail_pos.get(joint, (0.0, 0.0))
|
| 459 |
+
ftype = self._joint_fail_type.get(joint, "unknown")
|
| 460 |
+
dx = pos[0] - self.SUPPORT_CENTER_X
|
| 461 |
+
result.append({
|
| 462 |
+
"anchor_x": pos[0],
|
| 463 |
+
"anchor_y": pos[1],
|
| 464 |
+
"dist_from_support": dx,
|
| 465 |
+
"fail_step": step,
|
| 466 |
+
"fail_type": ftype,
|
| 467 |
+
"peak_force": self._joint_fail_force.get(joint, 0.0),
|
| 468 |
+
"peak_torque": self._joint_fail_torque.get(joint, 0.0),
|
| 469 |
+
"damage": self._joint_fail_damage.get(joint, 0.0),
|
| 470 |
+
"status": "failed",
|
| 471 |
+
})
|
| 472 |
+
return result
|
| 473 |
+
def _get_failure_event_timeline(self):
|
| 474 |
+
events = []
|
| 475 |
+
for j, step in self._joint_fail_step.items():
|
| 476 |
+
pos = self._joint_fail_pos.get(j, (0.0, 0.0))
|
| 477 |
+
ftype = self._joint_fail_type.get(j, "unknown")
|
| 478 |
+
dx = pos[0] - self.SUPPORT_CENTER_X
|
| 479 |
+
events.append({
|
| 480 |
+
"step": step,
|
| 481 |
+
"event_type": "joint_failure",
|
| 482 |
+
"pos_x": pos[0],
|
| 483 |
+
"pos_y": pos[1],
|
| 484 |
+
"dist_from_support": dx,
|
| 485 |
+
"fail_type": ftype,
|
| 486 |
+
"peak_force": self._joint_fail_force.get(j, 0.0),
|
| 487 |
+
"peak_torque": self._joint_fail_torque.get(j, 0.0),
|
| 488 |
+
"damage": self._joint_fail_damage.get(j, 0.0),
|
| 489 |
+
})
|
| 490 |
+
for b, step in self._body_destroy_step.items():
|
| 491 |
+
pos = self._body_destroy_pos.get(b, (0.0, 0.0))
|
| 492 |
+
reason = self._body_destroy_reason.get(b, "unknown")
|
| 493 |
+
dx = pos[0] - self.SUPPORT_CENTER_X
|
| 494 |
+
events.append({
|
| 495 |
+
"step": step,
|
| 496 |
+
"event_type": "body_destroy",
|
| 497 |
+
"pos_x": pos[0],
|
| 498 |
+
"pos_y": pos[1],
|
| 499 |
+
"dist_from_support": dx,
|
| 500 |
+
"fail_reason": reason,
|
| 501 |
+
})
|
| 502 |
+
events.sort(key=lambda e: e["step"])
|
| 503 |
+
return events
|
| 504 |
+
def _get_forensic_summary(self):
|
| 505 |
+
first_joint_fail_step = None
|
| 506 |
+
first_joint_fail_pos = None
|
| 507 |
+
first_joint_fail_type = None
|
| 508 |
+
first_body_fail_step = None
|
| 509 |
+
first_body_fail_pos = None
|
| 510 |
+
first_body_fail_reason = None
|
| 511 |
+
for j, step in self._joint_fail_step.items():
|
| 512 |
+
if step is not None and (first_joint_fail_step is None or step < first_joint_fail_step):
|
| 513 |
+
first_joint_fail_step = step
|
| 514 |
+
first_joint_fail_pos = self._joint_fail_pos.get(j)
|
| 515 |
+
first_joint_fail_type = self._joint_fail_type.get(j)
|
| 516 |
+
for b, step in self._body_destroy_step.items():
|
| 517 |
+
if step is not None and (first_body_fail_step is None or step < first_body_fail_step):
|
| 518 |
+
first_body_fail_step = step
|
| 519 |
+
first_body_fail_pos = self._body_destroy_pos.get(b)
|
| 520 |
+
first_body_fail_reason = self._body_destroy_reason.get(b)
|
| 521 |
+
peak_angvel = self._peak_body_angvel
|
| 522 |
+
worst_spin_body = None
|
| 523 |
+
worst_spin_pos = None
|
| 524 |
+
worst_spin_peak = 0.0
|
| 525 |
+
worst_spin_consec = 0
|
| 526 |
+
for body, pav in self._beam_peak_angvel.items():
|
| 527 |
+
if pav > worst_spin_peak:
|
| 528 |
+
worst_spin_peak = pav
|
| 529 |
+
worst_spin_body = body
|
| 530 |
+
worst_spin_consec = self._beam_high_spin_steps.get(body, 0)
|
| 531 |
+
if worst_spin_body is not None:
|
| 532 |
+
if worst_spin_body in self._bodies:
|
| 533 |
+
worst_spin_pos = (
|
| 534 |
+
worst_spin_body.position.x,
|
| 535 |
+
worst_spin_body.position.y,
|
| 536 |
+
)
|
| 537 |
+
else:
|
| 538 |
+
worst_spin_pos = self._body_destroy_pos.get(worst_spin_body)
|
| 539 |
+
beam_angvel_thresh = self.BEAM_ANGVEL_THRESH
|
| 540 |
+
beam_angvel_tol = self.BEAM_ANGVEL_TOLERANCE_STEPS
|
| 541 |
+
return {
|
| 542 |
+
"first_joint_fail_step": first_joint_fail_step,
|
| 543 |
+
"first_joint_fail_pos": first_joint_fail_pos,
|
| 544 |
+
"first_joint_fail_type": first_joint_fail_type,
|
| 545 |
+
"first_body_fail_step": first_body_fail_step,
|
| 546 |
+
"first_body_fail_pos": first_body_fail_pos,
|
| 547 |
+
"first_body_fail_reason": first_body_fail_reason,
|
| 548 |
+
"num_joints_removed_force_torque": self._num_joints_removed_force_torque,
|
| 549 |
+
"num_joints_removed_damage": self._num_joints_removed_damage,
|
| 550 |
+
"num_bodies_destroyed_spin": self._num_bodies_destroyed_spin,
|
| 551 |
+
"num_bodies_destroyed_orphan": self._num_bodies_destroyed_orphan,
|
| 552 |
+
"total_joints_removed": len(self._joint_fail_step),
|
| 553 |
+
"total_bodies_destroyed": (
|
| 554 |
+
self._num_bodies_destroyed_spin + self._num_bodies_destroyed_orphan
|
| 555 |
+
),
|
| 556 |
+
"peak_body_angvel": peak_angvel,
|
| 557 |
+
"beam_angvel_thresh": beam_angvel_thresh,
|
| 558 |
+
"beam_angvel_tolerance_steps": beam_angvel_tol,
|
| 559 |
+
"worst_spin_body_pos": worst_spin_pos,
|
| 560 |
+
"worst_spin_body_peak": worst_spin_peak,
|
| 561 |
+
"worst_spin_consec_steps": worst_spin_consec,
|
| 562 |
+
"current_phase": self._current_phase,
|
| 563 |
+
"step_counter": self._step_counter,
|
| 564 |
+
"failure_event_timeline": self._get_failure_event_timeline(),
|
| 565 |
+
"per_body_angvel_data": self._get_per_body_angvel_data(),
|
| 566 |
+
"per_joint_stress_data": self._get_per_joint_stress_data(),
|
| 567 |
+
}
|
| 568 |
+
def get_terrain_bounds(self):
|
| 569 |
+
return {
|
| 570 |
+
"ground_y": self._ground_y,
|
| 571 |
+
"build_zone": {
|
| 572 |
+
"x": [self.BUILD_ZONE_X_MIN, self.BUILD_ZONE_X_MAX],
|
| 573 |
+
"y": [self.BUILD_ZONE_Y_MIN, self.BUILD_ZONE_Y_MAX],
|
| 574 |
+
},
|
| 575 |
+
"max_structure_mass": self._max_structure_mass,
|
| 576 |
+
"forbidden_zone": [self._forbidden_zone_x_lo, self._forbidden_zone_x_hi],
|
| 577 |
+
"allowed_anchor_zone": [self._allowed_anchor_x_lo, self._allowed_anchor_x_hi],
|
| 578 |
+
"max_ground_anchors": self._max_ground_anchors,
|
| 579 |
+
}
|
tasks/Category6_ExoticPhysics/E_06/evaluator.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Evaluator for E-06 cantilever endurance."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Any, Dict, List, Optional, Tuple
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class Evaluator:
|
| 9 |
+
SPAN_X_LEFT = 7.0
|
| 10 |
+
SPAN_X_RIGHT = 13.0
|
| 11 |
+
MIN_HEIGHT_Y = 5.0
|
| 12 |
+
def __init__(self, terrain_bounds, environment=None):
|
| 13 |
+
if environment is None:
|
| 14 |
+
raise ValueError("Evaluator requires environment instance")
|
| 15 |
+
self.terrain_bounds = terrain_bounds
|
| 16 |
+
self.environment = environment
|
| 17 |
+
self.initial_joint_count: Optional[int] = None
|
| 18 |
+
self.initial_body_count: Optional[int] = None
|
| 19 |
+
self.initial_structure_mass: Optional[float] = None
|
| 20 |
+
self.initial_ground_anchor_count: Optional[int] = None
|
| 21 |
+
self.initial_min_x: Optional[float] = None
|
| 22 |
+
self.initial_max_x: Optional[float] = None
|
| 23 |
+
self.initial_max_y: Optional[float] = None
|
| 24 |
+
self.initial_span_check_passed: Optional[bool] = None
|
| 25 |
+
self.structure_broken = False
|
| 26 |
+
self.design_constraints_checked = False
|
| 27 |
+
self.max_structure_mass = float(
|
| 28 |
+
terrain_bounds.get(
|
| 29 |
+
"max_structure_mass", environment.MAX_STRUCTURE_MASS
|
| 30 |
+
)
|
| 31 |
+
)
|
| 32 |
+
build_zone = terrain_bounds.get("build_zone", {})
|
| 33 |
+
build_x = build_zone.get(
|
| 34 |
+
"x", [environment.BUILD_ZONE_X_MIN, environment.BUILD_ZONE_X_MAX]
|
| 35 |
+
)
|
| 36 |
+
build_y = build_zone.get(
|
| 37 |
+
"y", [environment.BUILD_ZONE_Y_MIN, environment.BUILD_ZONE_Y_MAX]
|
| 38 |
+
)
|
| 39 |
+
self.build_x_min, self.build_x_max = map(float, build_x)
|
| 40 |
+
self.build_y_min, self.build_y_max = map(float, build_y)
|
| 41 |
+
self.forbidden_zone = list(
|
| 42 |
+
terrain_bounds.get("forbidden_zone", [9.7, 10.3])
|
| 43 |
+
)
|
| 44 |
+
self.allowed_anchor_zone = list(
|
| 45 |
+
terrain_bounds.get("allowed_anchor_zone", [5.0, 6.5])
|
| 46 |
+
)
|
| 47 |
+
self.max_ground_anchors = int(
|
| 48 |
+
terrain_bounds.get("max_ground_anchors", 1)
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
def evaluate(self, agent_body, step_count, max_steps):
|
| 52 |
+
del agent_body
|
| 53 |
+
if not self.design_constraints_checked:
|
| 54 |
+
self.initial_joint_count = len(self.environment._joints)
|
| 55 |
+
self.initial_body_count = len(self.environment._bodies)
|
| 56 |
+
self.initial_structure_mass = self.environment.get_structure_mass()
|
| 57 |
+
self.initial_ground_anchor_count = self.environment._ground_anchor_count
|
| 58 |
+
self.initial_min_x = min(
|
| 59 |
+
(float(body.position.x) for body in self.environment._bodies),
|
| 60 |
+
default=None,
|
| 61 |
+
)
|
| 62 |
+
self.initial_max_x = max(
|
| 63 |
+
(float(body.position.x) for body in self.environment._bodies),
|
| 64 |
+
default=None,
|
| 65 |
+
)
|
| 66 |
+
self.initial_max_y = max(
|
| 67 |
+
(float(body.position.y) for body in self.environment._bodies),
|
| 68 |
+
default=None,
|
| 69 |
+
)
|
| 70 |
+
self.initial_span_check_passed = self._check_span()[0]
|
| 71 |
+
violations = self._check_design_constraints()
|
| 72 |
+
self.design_constraints_checked = True
|
| 73 |
+
if violations:
|
| 74 |
+
metrics = self._metrics(
|
| 75 |
+
step_count,
|
| 76 |
+
max_steps,
|
| 77 |
+
success=False,
|
| 78 |
+
failed=True,
|
| 79 |
+
failure_reason=(
|
| 80 |
+
"Design constraint violation: one or more build-time "
|
| 81 |
+
"requirements were not met"
|
| 82 |
+
),
|
| 83 |
+
)
|
| 84 |
+
metrics["constraint_violations"] = violations
|
| 85 |
+
return True, 0.0, metrics
|
| 86 |
+
|
| 87 |
+
current_joint_count = len(self.environment._joints)
|
| 88 |
+
current_body_count = len(self.environment._bodies)
|
| 89 |
+
if (
|
| 90 |
+
current_joint_count < (self.initial_joint_count or 0)
|
| 91 |
+
or current_body_count < (self.initial_body_count or 0)
|
| 92 |
+
):
|
| 93 |
+
self.structure_broken = True
|
| 94 |
+
|
| 95 |
+
span_ok, span_message = self._check_span()
|
| 96 |
+
step_limit = min(int(max_steps), int(self.environment.MAX_STEPS))
|
| 97 |
+
run_complete = step_count >= step_limit
|
| 98 |
+
failed = self.structure_broken
|
| 99 |
+
success = run_complete and not failed
|
| 100 |
+
if self.structure_broken:
|
| 101 |
+
failure_reason = (
|
| 102 |
+
"Structure lost one or more joints or beams during the endurance run"
|
| 103 |
+
)
|
| 104 |
+
else:
|
| 105 |
+
failure_reason = None
|
| 106 |
+
|
| 107 |
+
if success:
|
| 108 |
+
score = 100.0
|
| 109 |
+
elif failed:
|
| 110 |
+
score = 0.0
|
| 111 |
+
else:
|
| 112 |
+
score = 80.0 * step_count / max(step_limit, 1)
|
| 113 |
+
metrics = self._metrics(
|
| 114 |
+
step_count,
|
| 115 |
+
step_limit,
|
| 116 |
+
success=success,
|
| 117 |
+
failed=failed,
|
| 118 |
+
failure_reason=failure_reason,
|
| 119 |
+
)
|
| 120 |
+
return success or failed, score, metrics
|
| 121 |
+
|
| 122 |
+
def _metrics(
|
| 123 |
+
self,
|
| 124 |
+
step_count: int,
|
| 125 |
+
max_steps: int,
|
| 126 |
+
*,
|
| 127 |
+
success: bool,
|
| 128 |
+
failed: bool,
|
| 129 |
+
failure_reason: Optional[str],
|
| 130 |
+
) -> Dict[str, Any]:
|
| 131 |
+
current_joint_count = len(self.environment._joints)
|
| 132 |
+
current_body_count = len(self.environment._bodies)
|
| 133 |
+
span_ok, span_message = self._check_span()
|
| 134 |
+
forensic = self.environment._get_forensic_summary()
|
| 135 |
+
per_joint = forensic.get("per_joint_stress_data", [])
|
| 136 |
+
force_values = [
|
| 137 |
+
float(item.get("peak_force", 0.0))
|
| 138 |
+
for item in per_joint
|
| 139 |
+
if isinstance(item, dict)
|
| 140 |
+
]
|
| 141 |
+
torque_values = [
|
| 142 |
+
float(item.get("peak_torque", 0.0))
|
| 143 |
+
for item in per_joint
|
| 144 |
+
if isinstance(item, dict)
|
| 145 |
+
]
|
| 146 |
+
damage_values = [
|
| 147 |
+
float(item.get("damage", 0.0))
|
| 148 |
+
for item in per_joint
|
| 149 |
+
if isinstance(item, dict)
|
| 150 |
+
]
|
| 151 |
+
return {
|
| 152 |
+
"step_count": int(step_count),
|
| 153 |
+
"max_steps": min(int(max_steps), int(self.environment.MAX_STEPS)),
|
| 154 |
+
"success": bool(success),
|
| 155 |
+
"failed": bool(failed),
|
| 156 |
+
"failure_reason": failure_reason,
|
| 157 |
+
"structure_broken": self.structure_broken,
|
| 158 |
+
"joint_count": current_joint_count,
|
| 159 |
+
"initial_joint_count": self.initial_joint_count,
|
| 160 |
+
"body_count": current_body_count,
|
| 161 |
+
"initial_body_count": self.initial_body_count,
|
| 162 |
+
"structure_mass": self.environment.get_structure_mass(),
|
| 163 |
+
"initial_structure_mass": self.initial_structure_mass,
|
| 164 |
+
"max_structure_mass": self.max_structure_mass,
|
| 165 |
+
"ground_anchor_count": self.environment._ground_anchor_count,
|
| 166 |
+
"initial_ground_anchor_count": self.initial_ground_anchor_count,
|
| 167 |
+
"required_ground_anchor_count": 1,
|
| 168 |
+
"allowed_anchor_x_min": float(self.allowed_anchor_zone[0]),
|
| 169 |
+
"allowed_anchor_x_max": float(self.allowed_anchor_zone[1]),
|
| 170 |
+
"initial_min_x": self.initial_min_x,
|
| 171 |
+
"initial_max_x": self.initial_max_x,
|
| 172 |
+
"initial_max_y": self.initial_max_y,
|
| 173 |
+
"max_joint_force": max(force_values, default=0.0),
|
| 174 |
+
"max_joint_torque": max(torque_values, default=0.0),
|
| 175 |
+
"joint_break_force": float(self.environment.JOINT_BREAK_FORCE),
|
| 176 |
+
"joint_break_torque": float(self.environment.JOINT_BREAK_TORQUE),
|
| 177 |
+
"max_joint_damage": max(damage_values, default=0.0),
|
| 178 |
+
"damage_limit": float(self.environment.DAMAGE_LIMIT),
|
| 179 |
+
"span_check_passed": span_ok,
|
| 180 |
+
"initial_span_check_passed": self.initial_span_check_passed,
|
| 181 |
+
"span_check_message": span_message,
|
| 182 |
+
"span_x_left_required": self.SPAN_X_LEFT,
|
| 183 |
+
"span_x_right_required": self.SPAN_X_RIGHT,
|
| 184 |
+
"minimum_height_required": self.MIN_HEIGHT_Y,
|
| 185 |
+
"current_min_x": min(
|
| 186 |
+
(float(body.position.x) for body in self.environment._bodies),
|
| 187 |
+
default=None,
|
| 188 |
+
),
|
| 189 |
+
"current_max_x": max(
|
| 190 |
+
(float(body.position.x) for body in self.environment._bodies),
|
| 191 |
+
default=None,
|
| 192 |
+
),
|
| 193 |
+
"current_max_y": max(
|
| 194 |
+
(float(body.position.y) for body in self.environment._bodies),
|
| 195 |
+
default=None,
|
| 196 |
+
),
|
| 197 |
+
"first_joint_fail_step": forensic.get("first_joint_fail_step"),
|
| 198 |
+
"first_joint_fail_pos": forensic.get("first_joint_fail_pos"),
|
| 199 |
+
"first_joint_fail_type": forensic.get("first_joint_fail_type"),
|
| 200 |
+
"first_body_fail_step": forensic.get("first_body_fail_step"),
|
| 201 |
+
"first_body_fail_pos": forensic.get("first_body_fail_pos"),
|
| 202 |
+
"first_body_fail_reason": forensic.get("first_body_fail_reason"),
|
| 203 |
+
"num_joints_removed_force_torque": forensic.get(
|
| 204 |
+
"num_joints_removed_force_torque", 0
|
| 205 |
+
),
|
| 206 |
+
"num_joints_removed_damage": forensic.get(
|
| 207 |
+
"num_joints_removed_damage", 0
|
| 208 |
+
),
|
| 209 |
+
"total_joints_removed": forensic.get("total_joints_removed", 0),
|
| 210 |
+
"num_bodies_destroyed_spin": forensic.get(
|
| 211 |
+
"num_bodies_destroyed_spin", 0
|
| 212 |
+
),
|
| 213 |
+
"num_bodies_destroyed_orphan": forensic.get(
|
| 214 |
+
"num_bodies_destroyed_orphan", 0
|
| 215 |
+
),
|
| 216 |
+
"total_bodies_destroyed": forensic.get("total_bodies_destroyed", 0),
|
| 217 |
+
"peak_body_angvel": forensic.get("peak_body_angvel", 0.0),
|
| 218 |
+
"beam_angvel_thresh": float(self.environment.BEAM_ANGVEL_THRESH),
|
| 219 |
+
"beam_angvel_tolerance_steps": int(
|
| 220 |
+
self.environment.BEAM_ANGVEL_TOLERANCE_STEPS
|
| 221 |
+
),
|
| 222 |
+
"worst_spin_body_pos": forensic.get("worst_spin_body_pos"),
|
| 223 |
+
"worst_spin_body_peak": forensic.get("worst_spin_body_peak", 0.0),
|
| 224 |
+
"worst_spin_consec_steps": forensic.get(
|
| 225 |
+
"worst_spin_consec_steps", 0
|
| 226 |
+
),
|
| 227 |
+
"forensic_step_counter": forensic.get("step_counter", step_count),
|
| 228 |
+
"failure_event_timeline": forensic.get(
|
| 229 |
+
"failure_event_timeline", []
|
| 230 |
+
),
|
| 231 |
+
"per_body_angvel_data": forensic.get("per_body_angvel_data", []),
|
| 232 |
+
"per_joint_stress_data": per_joint,
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
def _check_span(self) -> Tuple[bool, str]:
|
| 236 |
+
if not self.environment._bodies:
|
| 237 |
+
return False, "Structure has no active beams"
|
| 238 |
+
xs = [float(body.position.x) for body in self.environment._bodies]
|
| 239 |
+
ys = [float(body.position.y) for body in self.environment._bodies]
|
| 240 |
+
if not any(x <= self.SPAN_X_LEFT for x in xs):
|
| 241 |
+
return False, f"Structure does not reach x <= {self.SPAN_X_LEFT}"
|
| 242 |
+
if not any(x >= self.SPAN_X_RIGHT for x in xs):
|
| 243 |
+
return False, f"Structure does not reach x >= {self.SPAN_X_RIGHT}"
|
| 244 |
+
if not any(y >= self.MIN_HEIGHT_Y for y in ys):
|
| 245 |
+
return False, f"Structure does not reach y >= {self.MIN_HEIGHT_Y}"
|
| 246 |
+
return True, "All span and height requirements are met"
|
| 247 |
+
|
| 248 |
+
def _check_design_constraints(self) -> List[str]:
|
| 249 |
+
violations = []
|
| 250 |
+
mass = self.environment.get_structure_mass()
|
| 251 |
+
if mass > self.max_structure_mass:
|
| 252 |
+
violations.append(
|
| 253 |
+
f"Structure mass {mass:.6g} kg exceeds maximum "
|
| 254 |
+
f"{self.max_structure_mass:.6g} kg"
|
| 255 |
+
)
|
| 256 |
+
if self.environment._ground_anchor_count != 1:
|
| 257 |
+
violations.append(
|
| 258 |
+
f"Structure has {self.environment._ground_anchor_count} ground "
|
| 259 |
+
"anchors; exactly 1 is required"
|
| 260 |
+
)
|
| 261 |
+
for body in self.environment._bodies:
|
| 262 |
+
x, y = float(body.position.x), float(body.position.y)
|
| 263 |
+
if not (
|
| 264 |
+
self.build_x_min <= x <= self.build_x_max
|
| 265 |
+
and self.build_y_min <= y <= self.build_y_max
|
| 266 |
+
):
|
| 267 |
+
violations.append(
|
| 268 |
+
f"Beam center ({x:.2f}, {y:.2f}) is outside build zone"
|
| 269 |
+
)
|
| 270 |
+
span_ok, span_message = self._check_span()
|
| 271 |
+
if not span_ok:
|
| 272 |
+
violations.append(span_message)
|
| 273 |
+
return violations
|
| 274 |
+
|
| 275 |
+
def get_task_description(self):
|
| 276 |
+
return {
|
| 277 |
+
"task": "E-06: Cantilever Endurance",
|
| 278 |
+
"description": (
|
| 279 |
+
"Build a one-anchor cantilever that retains every beam and joint "
|
| 280 |
+
"through the endurance interval."
|
| 281 |
+
),
|
| 282 |
+
"terrain": self.terrain_bounds,
|
| 283 |
+
"success_criteria": {
|
| 284 |
+
"primary": "No joint or beam is lost",
|
| 285 |
+
"span": (
|
| 286 |
+
f"Beam centers reach x<={self.SPAN_X_LEFT} and "
|
| 287 |
+
f"x>={self.SPAN_X_RIGHT}"
|
| 288 |
+
),
|
| 289 |
+
"height": f"At least one beam center reaches y>={self.MIN_HEIGHT_Y}",
|
| 290 |
+
"mass": f"Initial total mass <= {self.max_structure_mass} kg",
|
| 291 |
+
"anchors": "Exactly one ground anchor",
|
| 292 |
+
},
|
| 293 |
+
"evaluation": {
|
| 294 |
+
"score_range": "0-100",
|
| 295 |
+
"success_score": 100,
|
| 296 |
+
"failure_score": 0,
|
| 297 |
+
},
|
| 298 |
+
}
|
tasks/Category6_ExoticPhysics/E_06/feedback.py
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Compact, deterministic, non-privileged feedback for E-06."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import math
|
| 6 |
+
from typing import Any, Dict, List, Optional
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _number(value: Any) -> Optional[float]:
|
| 10 |
+
if isinstance(value, bool):
|
| 11 |
+
return None
|
| 12 |
+
try:
|
| 13 |
+
result = float(value)
|
| 14 |
+
except (TypeError, ValueError, OverflowError):
|
| 15 |
+
return None
|
| 16 |
+
return result if math.isfinite(result) else None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _fmt(value: Any, digits: int = 3) -> str:
|
| 20 |
+
number = _number(value)
|
| 21 |
+
return "unavailable" if number is None else f"{number:.{digits}f}"
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _integer(value: Any) -> str:
|
| 25 |
+
number = _number(value)
|
| 26 |
+
return "unavailable" if number is None else str(int(number))
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _outcome(metrics: Dict[str, Any]) -> str:
|
| 30 |
+
step = _integer(metrics.get("step_count"))
|
| 31 |
+
maximum = _integer(metrics.get("max_steps"))
|
| 32 |
+
if metrics.get("success"):
|
| 33 |
+
return f"- Outcome: SUCCESS at step {step}/{maximum}."
|
| 34 |
+
if metrics.get("failed"):
|
| 35 |
+
reason = metrics.get("failure_reason") or "failure reason unavailable"
|
| 36 |
+
return f"- Outcome: FAILURE at step {step}/{maximum} — {reason}."
|
| 37 |
+
return f"- Outcome: IN PROGRESS at step {step}/{maximum}."
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _ratio_line(
|
| 41 |
+
label: str,
|
| 42 |
+
value: Any,
|
| 43 |
+
limit: Any,
|
| 44 |
+
unit: str,
|
| 45 |
+
) -> str:
|
| 46 |
+
measured = _number(value)
|
| 47 |
+
threshold = _number(limit)
|
| 48 |
+
if measured is None or threshold is None:
|
| 49 |
+
return f"- {label}: unavailable."
|
| 50 |
+
status = "PASS" if measured <= threshold else "FAIL"
|
| 51 |
+
return (
|
| 52 |
+
f"- {label}: {measured:.3f}/{threshold:.3f} {unit} ({status}); "
|
| 53 |
+
f"margin {threshold - measured:+.3f} {unit}."
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _event_timeline(metrics: Dict[str, Any]) -> List[str]:
|
| 58 |
+
events = metrics.get("failure_event_timeline")
|
| 59 |
+
if not isinstance(events, list) or not events:
|
| 60 |
+
return ["- Failure events: none recorded."]
|
| 61 |
+
entries = []
|
| 62 |
+
for event in events[:6]:
|
| 63 |
+
if not isinstance(event, dict):
|
| 64 |
+
continue
|
| 65 |
+
step = _integer(event.get("step"))
|
| 66 |
+
position = (
|
| 67 |
+
f"({_fmt(event.get('pos_x'))}, {_fmt(event.get('pos_y'))}) m"
|
| 68 |
+
)
|
| 69 |
+
if event.get("event_type") == "joint_failure":
|
| 70 |
+
entries.append(
|
| 71 |
+
f"step {step}: joint {event.get('fail_type', 'failure')} at "
|
| 72 |
+
f"{position}, measured peak "
|
| 73 |
+
f"{_fmt(event.get('peak_force'))} N/"
|
| 74 |
+
f"{_fmt(event.get('peak_torque'))} N·m and damage "
|
| 75 |
+
f"{_fmt(event.get('damage'))} pts"
|
| 76 |
+
)
|
| 77 |
+
else:
|
| 78 |
+
entries.append(
|
| 79 |
+
f"step {step}: beam destruction "
|
| 80 |
+
f"({event.get('fail_reason', 'unknown')}) at {position}"
|
| 81 |
+
)
|
| 82 |
+
return [
|
| 83 |
+
"- Failure chronology: "
|
| 84 |
+
+ ("; ".join(entries) if entries else "unavailable")
|
| 85 |
+
+ (f"; {len(events) - 6} later event(s) omitted" if len(events) > 6 else "")
|
| 86 |
+
+ "."
|
| 87 |
+
]
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _hotspots(metrics: Dict[str, Any]) -> str:
|
| 91 |
+
records = metrics.get("per_joint_stress_data")
|
| 92 |
+
if not isinstance(records, list) or not records:
|
| 93 |
+
return "- Joint-stress locations: unavailable."
|
| 94 |
+
force_limit = _number(metrics.get("joint_break_force"))
|
| 95 |
+
torque_limit = _number(metrics.get("joint_break_torque"))
|
| 96 |
+
damage_limit = _number(metrics.get("damage_limit"))
|
| 97 |
+
ranked = []
|
| 98 |
+
for record in records:
|
| 99 |
+
if not isinstance(record, dict):
|
| 100 |
+
continue
|
| 101 |
+
ratios = []
|
| 102 |
+
for value, limit in (
|
| 103 |
+
(_number(record.get("peak_force")), force_limit),
|
| 104 |
+
(_number(record.get("peak_torque")), torque_limit),
|
| 105 |
+
(_number(record.get("damage")), damage_limit),
|
| 106 |
+
):
|
| 107 |
+
if value is not None and limit is not None and limit > 0.0:
|
| 108 |
+
ratios.append(value / limit)
|
| 109 |
+
ranked.append((max(ratios, default=0.0), record))
|
| 110 |
+
ranked.sort(key=lambda item: item[0], reverse=True)
|
| 111 |
+
entries = []
|
| 112 |
+
for ratio, record in ranked[:3]:
|
| 113 |
+
entries.append(
|
| 114 |
+
f"({_fmt(record.get('anchor_x'))}, {_fmt(record.get('anchor_y'))}) m: "
|
| 115 |
+
f"F={_fmt(record.get('peak_force'))} N, "
|
| 116 |
+
f"T={_fmt(record.get('peak_torque'))} N·m, "
|
| 117 |
+
f"damage={_fmt(record.get('damage'))} pts, "
|
| 118 |
+
f"worst utilization={ratio * 100.0:.1f}%"
|
| 119 |
+
)
|
| 120 |
+
return "- Highest measured joint utilizations: " + "; ".join(entries) + "."
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def format_task_metrics(
|
| 124 |
+
metrics: Dict[str, Any],
|
| 125 |
+
previous_metrics: Optional[Dict[str, Any]] = None,
|
| 126 |
+
) -> List[str]:
|
| 127 |
+
del previous_metrics
|
| 128 |
+
if not isinstance(metrics, dict) or not metrics:
|
| 129 |
+
return ["## E-06 Endurance Feedback", "- Outcome: unavailable — no metrics provided."]
|
| 130 |
+
if metrics.get("error"):
|
| 131 |
+
return [
|
| 132 |
+
"## E-06 Endurance Feedback",
|
| 133 |
+
f"- Outcome: evaluation error — {metrics.get('error')}.",
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
+
initial_mass = _number(metrics.get("initial_structure_mass"))
|
| 137 |
+
mass_limit = _number(metrics.get("max_structure_mass"))
|
| 138 |
+
initial_anchors = _number(metrics.get("initial_ground_anchor_count"))
|
| 139 |
+
required_anchors = _number(metrics.get("required_ground_anchor_count"))
|
| 140 |
+
initial_min_x = _number(metrics.get("initial_min_x"))
|
| 141 |
+
initial_max_x = _number(metrics.get("initial_max_x"))
|
| 142 |
+
initial_max_y = _number(metrics.get("initial_max_y"))
|
| 143 |
+
left_required = _number(metrics.get("span_x_left_required"))
|
| 144 |
+
right_required = _number(metrics.get("span_x_right_required"))
|
| 145 |
+
height_required = _number(metrics.get("minimum_height_required"))
|
| 146 |
+
|
| 147 |
+
lines = [
|
| 148 |
+
"## E-06 Endurance Feedback",
|
| 149 |
+
_outcome(metrics),
|
| 150 |
+
"### Failure chronology",
|
| 151 |
+
(
|
| 152 |
+
f"- First joint loss: step "
|
| 153 |
+
f"{_integer(metrics.get('first_joint_fail_step'))} at "
|
| 154 |
+
f"{metrics.get('first_joint_fail_pos') or 'unavailable'}, type "
|
| 155 |
+
f"{metrics.get('first_joint_fail_type') or 'unavailable'}."
|
| 156 |
+
),
|
| 157 |
+
(
|
| 158 |
+
f"- First beam loss: step "
|
| 159 |
+
f"{_integer(metrics.get('first_body_fail_step'))} at "
|
| 160 |
+
f"{metrics.get('first_body_fail_pos') or 'unavailable'}, reason "
|
| 161 |
+
f"{metrics.get('first_body_fail_reason') or 'unavailable'}."
|
| 162 |
+
),
|
| 163 |
+
*_event_timeline(metrics),
|
| 164 |
+
(
|
| 165 |
+
f"- Loss totals: {_integer(metrics.get('total_joints_removed'))} "
|
| 166 |
+
f"joint(s), {_integer(metrics.get('total_bodies_destroyed'))} "
|
| 167 |
+
f"beam(s)."
|
| 168 |
+
),
|
| 169 |
+
"### Spatial and build margins",
|
| 170 |
+
]
|
| 171 |
+
|
| 172 |
+
if None not in (initial_min_x, initial_max_x, initial_max_y):
|
| 173 |
+
left_margin = left_required - initial_min_x if left_required is not None else None
|
| 174 |
+
right_margin = initial_max_x - right_required if right_required is not None else None
|
| 175 |
+
height_margin = initial_max_y - height_required if height_required is not None else None
|
| 176 |
+
lines.append(
|
| 177 |
+
f"- Initial beam-center extent: x=[{initial_min_x:.3f}, "
|
| 178 |
+
f"{initial_max_x:.3f}] m, max y={initial_max_y:.3f} m; "
|
| 179 |
+
f"left/right/height margins "
|
| 180 |
+
f"{_fmt(left_margin)}/{_fmt(right_margin)}/{_fmt(height_margin)} m."
|
| 181 |
+
)
|
| 182 |
+
else:
|
| 183 |
+
lines.append("- Initial beam-center extent and span margins: unavailable.")
|
| 184 |
+
lines.append(
|
| 185 |
+
f"- Current active-beam extent: x=[{_fmt(metrics.get('current_min_x'))}, "
|
| 186 |
+
f"{_fmt(metrics.get('current_max_x'))}] m, max y="
|
| 187 |
+
f"{_fmt(metrics.get('current_max_y'))} m; runtime span diagnostic "
|
| 188 |
+
f"{'PASS' if metrics.get('span_check_passed') else 'OUTSIDE INITIAL TARGET'}."
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
lines.extend(
|
| 192 |
+
[
|
| 193 |
+
"### Load, damage, and rotation",
|
| 194 |
+
_ratio_line(
|
| 195 |
+
"Peak measured joint reaction force",
|
| 196 |
+
metrics.get("max_joint_force"),
|
| 197 |
+
metrics.get("joint_break_force"),
|
| 198 |
+
"N",
|
| 199 |
+
),
|
| 200 |
+
_ratio_line(
|
| 201 |
+
"Peak measured joint reaction torque",
|
| 202 |
+
metrics.get("max_joint_torque"),
|
| 203 |
+
metrics.get("joint_break_torque"),
|
| 204 |
+
"N·m",
|
| 205 |
+
),
|
| 206 |
+
_ratio_line(
|
| 207 |
+
"Maximum accumulated joint damage",
|
| 208 |
+
metrics.get("max_joint_damage"),
|
| 209 |
+
metrics.get("damage_limit"),
|
| 210 |
+
"pts",
|
| 211 |
+
),
|
| 212 |
+
_hotspots(metrics),
|
| 213 |
+
_ratio_line(
|
| 214 |
+
"Peak measured beam angular speed",
|
| 215 |
+
metrics.get("peak_body_angvel"),
|
| 216 |
+
metrics.get("beam_angvel_thresh"),
|
| 217 |
+
"rad/s",
|
| 218 |
+
),
|
| 219 |
+
(
|
| 220 |
+
f"- Worst current consecutive high-spin count: "
|
| 221 |
+
f"{_integer(metrics.get('worst_spin_consec_steps'))}/"
|
| 222 |
+
f"{_integer(metrics.get('beam_angvel_tolerance_steps'))} "
|
| 223 |
+
f"simulation step(s), at "
|
| 224 |
+
f"{metrics.get('worst_spin_body_pos') or 'unavailable'}."
|
| 225 |
+
),
|
| 226 |
+
"### Constraint profile",
|
| 227 |
+
]
|
| 228 |
+
)
|
| 229 |
+
if initial_mass is not None and mass_limit is not None:
|
| 230 |
+
lines.append(
|
| 231 |
+
f"- Initial mass: {initial_mass:.6f}/{mass_limit:.6f} kg "
|
| 232 |
+
f"({'PASS' if initial_mass <= mass_limit else 'FAIL'}); margin "
|
| 233 |
+
f"{mass_limit - initial_mass:+.6f} kg."
|
| 234 |
+
)
|
| 235 |
+
else:
|
| 236 |
+
lines.append("- Initial mass constraint: unavailable.")
|
| 237 |
+
if initial_anchors is not None and required_anchors is not None:
|
| 238 |
+
lines.append(
|
| 239 |
+
f"- Initial ground-anchor count: {int(initial_anchors)}/"
|
| 240 |
+
f"{int(required_anchors)} "
|
| 241 |
+
f"({'PASS' if initial_anchors == required_anchors else 'FAIL'}); "
|
| 242 |
+
f"allowed x=[{_fmt(metrics.get('allowed_anchor_x_min'))}, "
|
| 243 |
+
f"{_fmt(metrics.get('allowed_anchor_x_max'))}] m."
|
| 244 |
+
)
|
| 245 |
+
else:
|
| 246 |
+
lines.append("- Ground-anchor constraint: unavailable.")
|
| 247 |
+
lines.append(
|
| 248 |
+
f"- Initial span/height design check: "
|
| 249 |
+
f"{'PASS' if metrics.get('initial_span_check_passed') else 'FAIL'}; "
|
| 250 |
+
f"integrity: {'FAIL' if metrics.get('structure_broken') else 'PASS'}; "
|
| 251 |
+
f"intact joints/beams {_integer(metrics.get('joint_count'))}/"
|
| 252 |
+
f"{_integer(metrics.get('body_count'))} from "
|
| 253 |
+
f"{_integer(metrics.get('initial_joint_count'))}/"
|
| 254 |
+
f"{_integer(metrics.get('initial_body_count'))}."
|
| 255 |
+
)
|
| 256 |
+
violations = metrics.get("constraint_violations")
|
| 257 |
+
if isinstance(violations, list) and violations:
|
| 258 |
+
lines.append(
|
| 259 |
+
"- Build-time violations: "
|
| 260 |
+
+ "; ".join(str(item) for item in violations[:6])
|
| 261 |
+
+ "."
|
| 262 |
+
)
|
| 263 |
+
lines.extend(
|
| 264 |
+
[
|
| 265 |
+
"### Energy applicability",
|
| 266 |
+
(
|
| 267 |
+
"- No energy budget is part of E-06 grading; measured joint "
|
| 268 |
+
"loads, accumulated damage, and beam rotation are the applicable "
|
| 269 |
+
"endurance diagnostics."
|
| 270 |
+
),
|
| 271 |
+
"### Numerical health",
|
| 272 |
+
]
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
+
invalid = []
|
| 276 |
+
for key in (
|
| 277 |
+
"step_count",
|
| 278 |
+
"initial_structure_mass",
|
| 279 |
+
"structure_mass",
|
| 280 |
+
"max_joint_force",
|
| 281 |
+
"max_joint_torque",
|
| 282 |
+
"max_joint_damage",
|
| 283 |
+
"peak_body_angvel",
|
| 284 |
+
"current_min_x",
|
| 285 |
+
"current_max_x",
|
| 286 |
+
"current_max_y",
|
| 287 |
+
):
|
| 288 |
+
if key in metrics and metrics.get(key) is not None and _number(metrics.get(key)) is None:
|
| 289 |
+
invalid.append(key)
|
| 290 |
+
lines.append(
|
| 291 |
+
"- Invalid or non-finite observations: " + ", ".join(invalid) + "."
|
| 292 |
+
if invalid
|
| 293 |
+
else "- All reported scalar observations are finite."
|
| 294 |
+
)
|
| 295 |
+
return lines
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def get_improvement_suggestions(
|
| 299 |
+
metrics: Dict[str, Any],
|
| 300 |
+
score: float,
|
| 301 |
+
success: bool,
|
| 302 |
+
failed: bool,
|
| 303 |
+
failure_reason: Optional[str] = None,
|
| 304 |
+
error: Optional[str] = None,
|
| 305 |
+
) -> List[str]:
|
| 306 |
+
del metrics, score, success, failed, failure_reason
|
| 307 |
+
if error:
|
| 308 |
+
return [f"- Resolve the reported execution error: {error}"]
|
| 309 |
+
return []
|
tasks/Category6_ExoticPhysics/E_06/prompt.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
from pace_bench.tasks.primitives_api import API_INTRO
|
| 6 |
+
|
| 7 |
+
with open(os.path.join(os.path.dirname(__file__), '..', '..', 'primitives_api.json'), 'r') as f:
|
| 8 |
+
_api_data = json.load(f)
|
| 9 |
+
|
| 10 |
+
if 'E_06' in _api_data and 'API_INTRO' in _api_data['E_06']:
|
| 11 |
+
del _api_data['E_06']['API_INTRO']
|
| 12 |
+
|
| 13 |
+
TASK_PROMPT = {
|
| 14 |
+
"task_description": """
|
| 15 |
+
Design a robust cantilever structure that remains intact under distance-scaled stochastic and moment-dominant impulsive loads.
|
| 16 |
+
|
| 17 |
+
- **Support**: Ground anchors are allowed ONLY in the left support zone (x in [5.0, 6.5]m). Exactly one ground anchor is required, and its y-coordinate must be the ground surface y=1.0 m.
|
| 18 |
+
- **Cantilever**: The structure must extend from the support zone to the right.
|
| 19 |
+
- **Loads**: The structure is subject to continuous noise and periodic "storms". Excitation intensity increases with distance from the support.
|
| 20 |
+
- **Momentum**: Periodic coherent pulses create significant overturning moments, especially at the structure's tip.
|
| 21 |
+
- **Build Zone**: Every beam center must be placed in x=[5.0, 15.0] m, y=[1.5, 8.0] m. Beam centers in the **forbidden zone** x in [9.7, 10.3] m are rejected. Maximum 48 beams and 75 joints. Beam width and height must each be in [0.1, 4.0] m; density must be positive.
|
| 22 |
+
- **Structural limits**: Joints fail above 280800 N reaction force or 414000 N·m reaction torque; cumulative damage fails at 100 pts. A beam is destroyed if angular velocity exceeds 2.2 rad/s for 10 consecutive steps.
|
| 23 |
+
- **Goal**: Maintain structural integrity (avoid joint failure or beam destruction) for the duration of the test while spanning the required horizontal distance.
|
| 24 |
+
|
| 25 |
+
Design a cantilever that:
|
| 26 |
+
1. Anchors to the ground at exactly one point within x=[5.0, 6.5].
|
| 27 |
+
2. Spans from the support to at least x=13.0m and reaches a height of y=5.0m.
|
| 28 |
+
3. Withstands distance-scaled vibration and impulsive moments without any part of the structure breaking or being destroyed.
|
| 29 |
+
""",
|
| 30 |
+
"success_criteria": """
|
| 31 |
+
|
| 32 |
+
1. **Integrity**: The structure remains entirely intact; no joints break and no beams are destroyed.
|
| 33 |
+
2. **Span**: Structure reaches at least x <= 7.0m (near support) and x >= 13.0m (tip), and a height of y >= 5.0m.
|
| 34 |
+
3. **Mass**: Initial structure mass does not exceed the live mass limit (120 kg).
|
| 35 |
+
|
| 36 |
+
- **Anchor Limit**: Exactly 1 ground anchor, with x in [5.0, 6.5] m and y=1.0 m.
|
| 37 |
+
- **Mass Budget**: Total structure mass <= 120 kg.
|
| 38 |
+
- **Beams**: At most 48 beams; each beam width and height in [0.1, 4.0] m.
|
| 39 |
+
- **Joints**: At most 75 joints; joint failure at force > 280800 N or torque > 414000 N·m; damage failure at 100 pts. A beam is destroyed if angular velocity exceeds 2.2 rad/s for 10 consecutive steps.
|
| 40 |
+
- **Forbidden zone**: No beam centers in x in [9.7, 10.3] m.
|
| 41 |
+
- **APIs**: Use only the primitives documented below.
|
| 42 |
+
""",
|
| 43 |
+
'primitives_api': API_INTRO + '\n' + '\n\n'.join(_api_data['E_06'].values()),
|
| 44 |
+
|
| 45 |
+
}
|
tasks/Category6_ExoticPhysics/E_06/renderer.py
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pygame
|
| 2 |
+
|
| 3 |
+
from pace_bench.core.renderer import Renderer
|
| 4 |
+
from Box2D.b2 import dynamicBody, staticBody
|
| 5 |
+
|
| 6 |
+
# ── Academic palette ──────────────────────────────────────────────
|
| 7 |
+
COLOR_BG = (254, 252, 248) # near-white background
|
| 8 |
+
COLOR_ENV = ( 34, 80, 129) # muted teal-gray — environment
|
| 9 |
+
COLOR_AGENT = (234, 98, 85) # dark slate blue — agent structures
|
| 10 |
+
COLOR_OUTLINE = (109, 188, 208) # dark blue-gray — unified outlines
|
| 11 |
+
COLOR_TARGET = (237, 141, 73) # muted red — goal marker
|
| 12 |
+
COLOR_BOUNDARY = (207, 207, 207) # medium gray — build-zone boundary
|
| 13 |
+
COLOR_ANNOTATION = ( 34, 80, 129) # darker gray — text / labels (more readable)
|
| 14 |
+
COLOR_FORBIDDEN = (234, 98, 85) # forbidden zone = target red
|
| 15 |
+
COLOR_ANCHOR = (237, 141, 73) # muted green for anchor zone
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
class E06Renderer(Renderer):
|
| 19 |
+
def __init__(self, simulator):
|
| 20 |
+
super().__init__(simulator)
|
| 21 |
+
self._font_body = None
|
| 22 |
+
self._font_label = None
|
| 23 |
+
|
| 24 |
+
def _init_fonts(self):
|
| 25 |
+
if self._font_label is not None:
|
| 26 |
+
return
|
| 27 |
+
try:
|
| 28 |
+
self._font_body = pygame.font.SysFont("DejaVu Sans", 28)
|
| 29 |
+
self._font_label = pygame.font.SysFont("DejaVu Sans", 40)
|
| 30 |
+
except Exception:
|
| 31 |
+
self._font_body = pygame.font.Font(None, 28)
|
| 32 |
+
self._font_label = pygame.font.Font(None, 40)
|
| 33 |
+
|
| 34 |
+
def render(self, sandbox, agent_body, target_x, camera_offset_x):
|
| 35 |
+
# ── Square aspect ratio (600×600) ──────────────────────────
|
| 36 |
+
if self.simulator.screen_width != 600 or self.simulator.screen_height != 600:
|
| 37 |
+
self.simulator.screen_width = 600
|
| 38 |
+
self.simulator.screen_height = 600
|
| 39 |
+
if self.simulator.can_display:
|
| 40 |
+
self.simulator.screen = pygame.Surface((600, 600))
|
| 41 |
+
|
| 42 |
+
self.simulator.ppm = 25.0
|
| 43 |
+
center_x_world = 10.0
|
| 44 |
+
center_y_world = 5.0
|
| 45 |
+
cam_x = center_x_world * self.simulator.ppm - self.simulator.screen_width / 2
|
| 46 |
+
cam_y = self.simulator.screen_height / 2 - center_y_world * self.simulator.ppm
|
| 47 |
+
self.set_camera_offset(cam_x, cam_y)
|
| 48 |
+
|
| 49 |
+
# ── Background ─────────────────────────────────────────────
|
| 50 |
+
self.clear(COLOR_BG)
|
| 51 |
+
|
| 52 |
+
# ── Draw static bodies (environment) ──────────────────────
|
| 53 |
+
for body in sandbox.world.bodies:
|
| 54 |
+
if body.type == staticBody:
|
| 55 |
+
self.draw_body(body,
|
| 56 |
+
dynamic_color=COLOR_ENV,
|
| 57 |
+
static_color=COLOR_ENV,
|
| 58 |
+
outline_color=COLOR_OUTLINE,
|
| 59 |
+
outline_width=1)
|
| 60 |
+
|
| 61 |
+
# ── Draw dynamic bodies ────────────────────────────────────
|
| 62 |
+
for body in sandbox.world.bodies:
|
| 63 |
+
if body.type == dynamicBody:
|
| 64 |
+
if hasattr(sandbox, "bodies") and body in sandbox.bodies:
|
| 65 |
+
self.draw_body(body,
|
| 66 |
+
dynamic_color=COLOR_AGENT,
|
| 67 |
+
static_color=COLOR_AGENT,
|
| 68 |
+
outline_color=COLOR_OUTLINE,
|
| 69 |
+
outline_width=1)
|
| 70 |
+
else:
|
| 71 |
+
self.draw_body(body,
|
| 72 |
+
dynamic_color=COLOR_ENV,
|
| 73 |
+
static_color=COLOR_ENV,
|
| 74 |
+
outline_color=COLOR_OUTLINE,
|
| 75 |
+
outline_width=1)
|
| 76 |
+
|
| 77 |
+
# ── Terrain zone boundaries ────────────────────────────────
|
| 78 |
+
bounds = sandbox.get_terrain_bounds()
|
| 79 |
+
bz = bounds.get("build_zone", {})
|
| 80 |
+
if bz:
|
| 81 |
+
x_min = bz["x"][0]
|
| 82 |
+
x_max = bz["x"][1]
|
| 83 |
+
y_min = bz["y"][0]
|
| 84 |
+
y_max = bz["y"][1]
|
| 85 |
+
self.draw_line(x_min, y_min, x_max, y_min, COLOR_BOUNDARY, 1)
|
| 86 |
+
self.draw_line(x_max, y_min, x_max, y_max, COLOR_BOUNDARY, 1)
|
| 87 |
+
self.draw_line(x_max, y_max, x_min, y_max, COLOR_BOUNDARY, 1)
|
| 88 |
+
self.draw_line(x_min, y_max, x_min, y_min, COLOR_BOUNDARY, 1)
|
| 89 |
+
|
| 90 |
+
# ── Forbidden zone ─────────────────────────────────────────
|
| 91 |
+
fz = bounds.get("forbidden_zone")
|
| 92 |
+
if bz and fz:
|
| 93 |
+
fz_lo = fz[0]
|
| 94 |
+
fz_hi = fz[1]
|
| 95 |
+
y_min = bz["y"][0]
|
| 96 |
+
y_max = bz["y"][1]
|
| 97 |
+
self.draw_line(fz_lo, y_min, fz_lo, y_max, COLOR_FORBIDDEN, 1)
|
| 98 |
+
self.draw_line(fz_hi, y_min, fz_hi, y_max, COLOR_FORBIDDEN, 1)
|
| 99 |
+
self.draw_line(fz_lo, y_max, fz_hi, y_max, COLOR_FORBIDDEN, 1)
|
| 100 |
+
|
| 101 |
+
# ── Allowed anchor zone line ───────────────────────────────
|
| 102 |
+
az = bounds.get("allowed_anchor_zone")
|
| 103 |
+
if az:
|
| 104 |
+
az_lo = az[0]
|
| 105 |
+
az_hi = az[1]
|
| 106 |
+
ground_y = bounds.get("ground_y", 1.0)
|
| 107 |
+
self.draw_line(az_lo, ground_y, az_hi, ground_y, COLOR_ANCHOR, 3)
|
| 108 |
+
|
| 109 |
+
# ── Annotations ────────────────────────────────────────────
|
| 110 |
+
if self.simulator.can_display:
|
| 111 |
+
self._init_fonts()
|
| 112 |
+
_sh = self.simulator.screen_height
|
| 113 |
+
|
| 114 |
+
# Top-left: task label
|
| 115 |
+
if self._font_label:
|
| 116 |
+
label = self._font_label.render("E-06 | Cantilever Endurance",
|
| 117 |
+
True, COLOR_ANNOTATION)
|
| 118 |
+
self.simulator.screen.blit(label, (18, 14))
|
| 119 |
+
|
| 120 |
+
# Bottom-left: scale bar (1 m)
|
| 121 |
+
if self.simulator.ppm > 0:
|
| 122 |
+
scale_px = int(1.0 * self.simulator.ppm)
|
| 123 |
+
bar_x, bar_y = 20, _sh - 28
|
| 124 |
+
pygame.draw.line(self.simulator.screen, COLOR_ANNOTATION,
|
| 125 |
+
(bar_x, bar_y), (bar_x + scale_px, bar_y), 4)
|
| 126 |
+
pygame.draw.line(self.simulator.screen, COLOR_ANNOTATION,
|
| 127 |
+
(bar_x, bar_y - 5), (bar_x, bar_y + 5), 2)
|
| 128 |
+
pygame.draw.line(self.simulator.screen, COLOR_ANNOTATION,
|
| 129 |
+
(bar_x + scale_px, bar_y - 5),
|
| 130 |
+
(bar_x + scale_px, bar_y + 5), 2)
|
| 131 |
+
if self._font_body:
|
| 132 |
+
label_m = self._font_body.render("1 m", True, COLOR_ANNOTATION)
|
| 133 |
+
self.simulator.screen.blit(label_m, (bar_x + scale_px + 8, bar_y - 14))
|
tasks/Category6_ExoticPhysics/E_06/stages.py
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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7 |
+
import re
|
| 8 |
+
from typing import Any, Dict, List
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
DEFAULT_JOINT_BREAK_FORCE = 280800.0
|
| 12 |
+
DEFAULT_JOINT_BREAK_TORQUE = 414000.0
|
| 13 |
+
DEFAULT_DAMAGE_LIMIT = 100.0
|
| 14 |
+
DEFAULT_BEAM_ANGVEL_THRESH = 2.2
|
| 15 |
+
DEFAULT_BEAM_ANGVEL_TOLERANCE_STEPS = 10
|
| 16 |
+
DEFAULT_MASS = 120.0
|
| 17 |
+
DEFAULT_ANCHOR_LO = 5.0
|
| 18 |
+
DEFAULT_ANCHOR_HI = 6.5
|
| 19 |
+
|
| 20 |
+
TASK_DESCRIPTION_SUFFIX = uniform_suffix_for_task("E_06")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def _visible(current: float, source: float, unit: str = "") -> str:
|
| 24 |
+
text = f"{current:g}{unit}"
|
| 25 |
+
if current != source:
|
| 26 |
+
text += f" (source {source:g}{unit})"
|
| 27 |
+
return text
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _replace_once(text: str, pattern: str, replacement: str, label: str) -> str:
|
| 31 |
+
updated, count = re.subn(pattern, replacement, text, count=1, flags=re.MULTILINE)
|
| 32 |
+
if count != 1:
|
| 33 |
+
raise ValueError(f"E_06 visible prompt update failed for {label}: {count} matches")
|
| 34 |
+
return updated
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _values(
|
| 38 |
+
target_terrain_config: Dict[str, Any],
|
| 39 |
+
base_terrain_config: Dict[str, Any],
|
| 40 |
+
target_physics_config: Dict[str, Any],
|
| 41 |
+
base_physics_config: Dict[str, Any],
|
| 42 |
+
) -> Dict[str, float]:
|
| 43 |
+
return {
|
| 44 |
+
"force": float(
|
| 45 |
+
target_physics_config.get(
|
| 46 |
+
"joint_break_force", DEFAULT_JOINT_BREAK_FORCE
|
| 47 |
+
)
|
| 48 |
+
),
|
| 49 |
+
"base_force": float(
|
| 50 |
+
base_physics_config.get(
|
| 51 |
+
"joint_break_force", DEFAULT_JOINT_BREAK_FORCE
|
| 52 |
+
)
|
| 53 |
+
),
|
| 54 |
+
"torque": float(
|
| 55 |
+
target_physics_config.get(
|
| 56 |
+
"joint_break_torque", DEFAULT_JOINT_BREAK_TORQUE
|
| 57 |
+
)
|
| 58 |
+
),
|
| 59 |
+
"base_torque": float(
|
| 60 |
+
base_physics_config.get(
|
| 61 |
+
"joint_break_torque", DEFAULT_JOINT_BREAK_TORQUE
|
| 62 |
+
)
|
| 63 |
+
),
|
| 64 |
+
"damage": float(
|
| 65 |
+
target_physics_config.get("damage_limit", DEFAULT_DAMAGE_LIMIT)
|
| 66 |
+
),
|
| 67 |
+
"base_damage": float(
|
| 68 |
+
base_physics_config.get("damage_limit", DEFAULT_DAMAGE_LIMIT)
|
| 69 |
+
),
|
| 70 |
+
"spin": float(
|
| 71 |
+
target_physics_config.get(
|
| 72 |
+
"beam_angvel_thresh", DEFAULT_BEAM_ANGVEL_THRESH
|
| 73 |
+
)
|
| 74 |
+
),
|
| 75 |
+
"base_spin": float(
|
| 76 |
+
base_physics_config.get(
|
| 77 |
+
"beam_angvel_thresh", DEFAULT_BEAM_ANGVEL_THRESH
|
| 78 |
+
)
|
| 79 |
+
),
|
| 80 |
+
"spin_steps": int(
|
| 81 |
+
target_physics_config.get(
|
| 82 |
+
"beam_angvel_tolerance_steps",
|
| 83 |
+
DEFAULT_BEAM_ANGVEL_TOLERANCE_STEPS,
|
| 84 |
+
)
|
| 85 |
+
),
|
| 86 |
+
"base_spin_steps": int(
|
| 87 |
+
base_physics_config.get(
|
| 88 |
+
"beam_angvel_tolerance_steps",
|
| 89 |
+
DEFAULT_BEAM_ANGVEL_TOLERANCE_STEPS,
|
| 90 |
+
)
|
| 91 |
+
),
|
| 92 |
+
"mass": float(
|
| 93 |
+
target_terrain_config.get("max_structure_mass", DEFAULT_MASS)
|
| 94 |
+
),
|
| 95 |
+
"base_mass": float(
|
| 96 |
+
base_terrain_config.get("max_structure_mass", DEFAULT_MASS)
|
| 97 |
+
),
|
| 98 |
+
"anchor_lo": float(
|
| 99 |
+
target_terrain_config.get("allowed_anchor_x_lo", DEFAULT_ANCHOR_LO)
|
| 100 |
+
),
|
| 101 |
+
"base_anchor_lo": float(
|
| 102 |
+
base_terrain_config.get("allowed_anchor_x_lo", DEFAULT_ANCHOR_LO)
|
| 103 |
+
),
|
| 104 |
+
"anchor_hi": float(
|
| 105 |
+
target_terrain_config.get("allowed_anchor_x_hi", DEFAULT_ANCHOR_HI)
|
| 106 |
+
),
|
| 107 |
+
"base_anchor_hi": float(
|
| 108 |
+
base_terrain_config.get("allowed_anchor_x_hi", DEFAULT_ANCHOR_HI)
|
| 109 |
+
),
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _anchor_text(values: Dict[str, float]) -> str:
|
| 114 |
+
current = f"x=[{values['anchor_lo']:g}, {values['anchor_hi']:g}] m"
|
| 115 |
+
if (
|
| 116 |
+
values["anchor_lo"] != values["base_anchor_lo"]
|
| 117 |
+
or values["anchor_hi"] != values["base_anchor_hi"]
|
| 118 |
+
):
|
| 119 |
+
current += (
|
| 120 |
+
f" (source x=[{values['base_anchor_lo']:g}, "
|
| 121 |
+
f"{values['base_anchor_hi']:g}] m)"
|
| 122 |
+
)
|
| 123 |
+
return current
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def _structural_text(values: Dict[str, float]) -> str:
|
| 127 |
+
steps = int(values["spin_steps"])
|
| 128 |
+
base_steps = int(values["base_spin_steps"])
|
| 129 |
+
step_text = str(steps)
|
| 130 |
+
if steps != base_steps:
|
| 131 |
+
step_text += f" (source {base_steps})"
|
| 132 |
+
return (
|
| 133 |
+
"- **Structural limits**: Joints fail above "
|
| 134 |
+
f"{_visible(values['force'], values['base_force'], ' N')} reaction force "
|
| 135 |
+
f"or {_visible(values['torque'], values['base_torque'], ' N·m')} reaction "
|
| 136 |
+
f"torque; cumulative damage fails at "
|
| 137 |
+
f"{_visible(values['damage'], values['base_damage'], ' pts')}. A beam is "
|
| 138 |
+
f"destroyed if angular velocity exceeds "
|
| 139 |
+
f"{_visible(values['spin'], values['base_spin'], ' rad/s')} for "
|
| 140 |
+
f"{step_text} consecutive simulation step(s)."
|
| 141 |
+
)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def update_task_description_for_visible_changes(
|
| 145 |
+
base_description: str,
|
| 146 |
+
target_terrain_config: Dict[str, Any],
|
| 147 |
+
base_terrain_config: Dict[str, Any],
|
| 148 |
+
target_physics_config: Dict[str, Any] = None,
|
| 149 |
+
base_physics_config: Dict[str, Any] = None,
|
| 150 |
+
**kwargs,
|
| 151 |
+
) -> str:
|
| 152 |
+
del kwargs
|
| 153 |
+
values = _values(
|
| 154 |
+
target_terrain_config or {},
|
| 155 |
+
base_terrain_config or {},
|
| 156 |
+
target_physics_config or {},
|
| 157 |
+
base_physics_config or {},
|
| 158 |
+
)
|
| 159 |
+
description = _replace_once(
|
| 160 |
+
base_description,
|
| 161 |
+
r"^- \*\*Support\*\*:.*$",
|
| 162 |
+
(
|
| 163 |
+
"- **Support**: Exactly one ground anchor is required within "
|
| 164 |
+
f"{_anchor_text(values)}, at the ground surface y=1.0 m."
|
| 165 |
+
),
|
| 166 |
+
"task support",
|
| 167 |
+
)
|
| 168 |
+
description = _replace_once(
|
| 169 |
+
description,
|
| 170 |
+
r"^- \*\*Structural limits\*\*:.*$",
|
| 171 |
+
_structural_text(values),
|
| 172 |
+
"task structural limits",
|
| 173 |
+
)
|
| 174 |
+
description = _replace_once(
|
| 175 |
+
description,
|
| 176 |
+
r"^1\. Anchors to the ground.*$",
|
| 177 |
+
(
|
| 178 |
+
"1. Anchors to the ground at exactly one point within "
|
| 179 |
+
f"{_anchor_text(values)}."
|
| 180 |
+
),
|
| 181 |
+
"task anchor objective",
|
| 182 |
+
)
|
| 183 |
+
return description
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def update_success_criteria_for_visible_changes(
|
| 187 |
+
base_success_criteria: str,
|
| 188 |
+
target_terrain_config: Dict[str, Any],
|
| 189 |
+
base_terrain_config: Dict[str, Any],
|
| 190 |
+
target_physics_config: Dict[str, Any] = None,
|
| 191 |
+
base_physics_config: Dict[str, Any] = None,
|
| 192 |
+
**kwargs,
|
| 193 |
+
) -> str:
|
| 194 |
+
del kwargs
|
| 195 |
+
values = _values(
|
| 196 |
+
target_terrain_config or {},
|
| 197 |
+
base_terrain_config or {},
|
| 198 |
+
target_physics_config or {},
|
| 199 |
+
base_physics_config or {},
|
| 200 |
+
)
|
| 201 |
+
criteria = _replace_once(
|
| 202 |
+
base_success_criteria,
|
| 203 |
+
r"^3\. \*\*Mass\*\*:.*$",
|
| 204 |
+
(
|
| 205 |
+
"3. **Mass**: Initial structure mass does not exceed "
|
| 206 |
+
f"{_visible(values['mass'], values['base_mass'], ' kg')}."
|
| 207 |
+
),
|
| 208 |
+
"criteria mass objective",
|
| 209 |
+
)
|
| 210 |
+
criteria = _replace_once(
|
| 211 |
+
criteria,
|
| 212 |
+
r"^- \*\*Anchor Limit\*\*:.*$",
|
| 213 |
+
(
|
| 214 |
+
"- **Anchor Limit**: Exactly 1 ground anchor within "
|
| 215 |
+
f"{_anchor_text(values)}, at y=1.0 m."
|
| 216 |
+
),
|
| 217 |
+
"criteria anchor",
|
| 218 |
+
)
|
| 219 |
+
criteria = _replace_once(
|
| 220 |
+
criteria,
|
| 221 |
+
r"^- \*\*Mass Budget\*\*:.*$",
|
| 222 |
+
(
|
| 223 |
+
"- **Mass Budget**: Initial structure mass <= "
|
| 224 |
+
f"{_visible(values['mass'], values['base_mass'], ' kg')}."
|
| 225 |
+
),
|
| 226 |
+
"criteria mass budget",
|
| 227 |
+
)
|
| 228 |
+
criteria = _replace_once(
|
| 229 |
+
criteria,
|
| 230 |
+
r"^- \*\*Joints\*\*:.*$",
|
| 231 |
+
_structural_text(values).replace(
|
| 232 |
+
"- **Structural limits**:",
|
| 233 |
+
"- **Joints**: At most 75 joints;",
|
| 234 |
+
1,
|
| 235 |
+
),
|
| 236 |
+
"criteria structural limits",
|
| 237 |
+
)
|
| 238 |
+
return criteria
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def get_e06_curriculum_stages() -> List[Dict[str, Any]]:
|
| 242 |
+
return [
|
| 243 |
+
{
|
| 244 |
+
"stage_id": "Stage-1",
|
| 245 |
+
"title": "Endurance Variant I",
|
| 246 |
+
"mutation_description": (
|
| 247 |
+
"Published structural constraints accompany undisclosed "
|
| 248 |
+
"non-standard loading and dissipation conditions."
|
| 249 |
+
),
|
| 250 |
+
"task_description_suffix": uniform_suffix_for_task("E_06"),
|
| 251 |
+
"terrain_config": {"max_structure_mass": 12.0},
|
| 252 |
+
"physics_config": {
|
| 253 |
+
"gravity": (0, 16),
|
| 254 |
+
"angular_damping": 0.0,
|
| 255 |
+
"joint_break_force": 10800.0,
|
| 256 |
+
"joint_break_torque": 14400.0,
|
| 257 |
+
"beam_angvel_thresh": 2.1,
|
| 258 |
+
"beam_angvel_tolerance_steps": 1,
|
| 259 |
+
},
|
| 260 |
+
},
|
| 261 |
+
{
|
| 262 |
+
"stage_id": "Stage-2",
|
| 263 |
+
"title": "Endurance Variant II",
|
| 264 |
+
"mutation_description": (
|
| 265 |
+
"Published structural constraints accompany undisclosed "
|
| 266 |
+
"non-standard loading, fatigue, and dissipation conditions."
|
| 267 |
+
),
|
| 268 |
+
"task_description_suffix": uniform_suffix_for_task("E_06"),
|
| 269 |
+
"terrain_config": {"max_structure_mass": 1.0},
|
| 270 |
+
"physics_config": {
|
| 271 |
+
"gravity": (1500, 0),
|
| 272 |
+
"linear_damping": 0.0,
|
| 273 |
+
"angular_damping": 8.0,
|
| 274 |
+
"noise_strength": 0.0,
|
| 275 |
+
"coherent_pulse_interval": 501,
|
| 276 |
+
"coherent_pulse_force": 0.0,
|
| 277 |
+
"joint_break_force": 7200.0,
|
| 278 |
+
"joint_break_torque": 4320.0,
|
| 279 |
+
"damage_limit": 12.0,
|
| 280 |
+
"damage_force_thresh": 3600.0,
|
| 281 |
+
"damage_torque_thresh": 7200.0,
|
| 282 |
+
"cascade_shock_damage": 40.0,
|
| 283 |
+
"beam_angvel_thresh": 6.0,
|
| 284 |
+
"beam_angvel_tolerance_steps": 3,
|
| 285 |
+
"phased_storm_mult": 1.0,
|
| 286 |
+
"phased_storm_start": 501,
|
| 287 |
+
"phased_storm_end": 501,
|
| 288 |
+
"burst_prob": 0.0,
|
| 289 |
+
},
|
| 290 |
+
},
|
| 291 |
+
{
|
| 292 |
+
"stage_id": "Stage-3",
|
| 293 |
+
"title": "Endurance Variant III",
|
| 294 |
+
"mutation_description": (
|
| 295 |
+
"Published structural constraints accompany undisclosed "
|
| 296 |
+
"non-standard loading, fatigue, cascade, and storm conditions."
|
| 297 |
+
),
|
| 298 |
+
"task_description_suffix": uniform_suffix_for_task("E_06"),
|
| 299 |
+
"terrain_config": {"max_structure_mass": 30.0},
|
| 300 |
+
"physics_config": {
|
| 301 |
+
"gravity": (0, -19),
|
| 302 |
+
"joint_break_force": 6500.0,
|
| 303 |
+
"joint_break_torque": 11000.0,
|
| 304 |
+
"coherent_pulse_interval": 1,
|
| 305 |
+
"coherent_pulse_force": 160.0,
|
| 306 |
+
"angular_damping": 0.0,
|
| 307 |
+
"linear_damping": 0.0,
|
| 308 |
+
"noise_strength": 18.0,
|
| 309 |
+
"damage_limit": 1.0,
|
| 310 |
+
"damage_force_thresh": 1260.0,
|
| 311 |
+
"damage_torque_thresh": 2880.0,
|
| 312 |
+
"cascade_shock_damage": 500.0,
|
| 313 |
+
"beam_angvel_thresh": 1.5,
|
| 314 |
+
"beam_angvel_tolerance_steps": 2,
|
| 315 |
+
"phased_storm_mult": 4.5,
|
| 316 |
+
"phased_storm_start": 15,
|
| 317 |
+
"burst_prob": 0.15,
|
| 318 |
+
},
|
| 319 |
+
},
|
| 320 |
+
{
|
| 321 |
+
"stage_id": "Stage-4",
|
| 322 |
+
"title": "Endurance Variant IV",
|
| 323 |
+
"mutation_description": (
|
| 324 |
+
"Published structural and anchor constraints accompany "
|
| 325 |
+
"undisclosed non-standard loading, fatigue, cascade, and storm "
|
| 326 |
+
"conditions."
|
| 327 |
+
),
|
| 328 |
+
"task_description_suffix": uniform_suffix_for_task("E_06"),
|
| 329 |
+
"terrain_config": {
|
| 330 |
+
"max_structure_mass": 20.0,
|
| 331 |
+
"allowed_anchor_x_lo": 5.72,
|
| 332 |
+
"allowed_anchor_x_hi": 5.78,
|
| 333 |
+
},
|
| 334 |
+
"physics_config": {
|
| 335 |
+
"gravity": (0, -30),
|
| 336 |
+
"noise_strength": 2.0,
|
| 337 |
+
"coherent_pulse_interval": 1,
|
| 338 |
+
"coherent_pulse_force": 550.0,
|
| 339 |
+
"angular_damping": 0.20,
|
| 340 |
+
"linear_damping": 0.0,
|
| 341 |
+
"joint_break_force": 7200.0,
|
| 342 |
+
"joint_break_torque": 12600.0,
|
| 343 |
+
"damage_limit": 0.9,
|
| 344 |
+
"damage_force_thresh": 792.0,
|
| 345 |
+
"damage_torque_thresh": 1368.0,
|
| 346 |
+
"cascade_shock_damage": 5000.0,
|
| 347 |
+
"beam_angvel_thresh": 1.0,
|
| 348 |
+
"beam_angvel_tolerance_steps": 2,
|
| 349 |
+
"phased_storm_mult": 4.5,
|
| 350 |
+
"burst_prob": 0.4,
|
| 351 |
+
"phased_storm_start": 0,
|
| 352 |
+
"phased_storm_end": 500,
|
| 353 |
+
},
|
| 354 |
+
},
|
| 355 |
+
]
|
tasks/Category6_ExoticPhysics/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
|
tasks/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""The six benchmark task categories."""
|
tasks/primitives_api.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|