Skip to content

Commit

Permalink
Revert "ci: faster metadrive test (#33755)"
Browse files Browse the repository at this point in the history
This reverts commit d7c0906.
  • Loading branch information
adeebshihadeh committed Oct 14, 2024
1 parent 8bf34d0 commit dc09479
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ env:
jobs:
simulator_driving:
name: simulator driving
runs-on: ${{ ((github.repository == 'commaai/openpilot') &&
((github.event_name != 'pull_request') ||
(github.event.pull_request.head.repo.full_name == 'commaai/openpilot'))) && 'namespace-profile-amd64-8x16' || 'ubuntu-latest' }}
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions tools/sim/bridge/metadrive/metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ def create_map(track_size=60):
class MetaDriveBridge(SimulatorBridge):
TICKS_PER_FRAME = 5

def __init__(self, dual_camera, high_quality, test_duration=math.inf, minimal_distance=0, test_run=False):
def __init__(self, dual_camera, high_quality, test_duration=math.inf, test_run=False):
super().__init__(dual_camera, high_quality)

self.should_render = False
self.test_run = test_run
self.test_duration = test_duration if self.test_run else math.inf
self.minimal_distance = minimal_distance if self.test_run else 0

def spawn_world(self, queue: Queue):
sensors = {
Expand Down Expand Up @@ -91,4 +90,4 @@ def spawn_world(self, queue: Queue):
anisotropic_filtering=False
)

return MetaDriveWorld(queue, config, self.test_duration, self.minimal_distance, self.test_run, self.dual_camera)
return MetaDriveWorld(queue, config, self.test_duration, self.test_run, self.dual_camera)
15 changes: 2 additions & 13 deletions tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
C3_POSITION = Vec3(0.0, 0, 1.22)
C3_HPR = Vec3(0, 0,0)

VEHICLE_STARTING_POS = [110, 4.5]

metadrive_simulation_state = namedtuple("metadrive_simulation_state", ["running", "done", "done_info"])
metadrive_vehicle_state = namedtuple("metadrive_vehicle_state", ["velocity", "position", "bearing", "steering_angle"])
Expand Down Expand Up @@ -51,7 +50,7 @@ def arrive_destination_patch(self, *args, **kwargs):

def metadrive_process(dual_camera: bool, config: dict, camera_array, wide_camera_array, image_lock,
controls_recv: Connection, simulation_state_send: Connection, vehicle_state_send: Connection,
exit_event, op_engaged, test_duration, minimal_distance, test_run):
exit_event, op_engaged, test_duration, test_run):
arrive_dest_done = config.pop("arrive_dest_done", True)
apply_metadrive_patches(arrive_dest_done)

Expand All @@ -71,7 +70,6 @@ def reset():
env.reset()
env.vehicle.config["max_speed_km_h"] = 1000
lane_idx_prev, _ = get_current_lane_info(env.vehicle)
env.vehicle.set_position(VEHICLE_STARTING_POS)

simulation_state = metadrive_simulation_state(
running=True,
Expand Down Expand Up @@ -100,9 +98,6 @@ def get_cam_as_rgb(cam):
steer_ratio = 8
vc = [0,0]

total_distance = 0
prev_x_pos = VEHICLE_STARTING_POS[0]

while not exit_event.is_set():
vehicle_state = metadrive_vehicle_state(
velocity=vec3(x=float(env.vehicle.velocity[0]), y=float(env.vehicle.velocity[1]), z=0),
Expand All @@ -112,9 +107,6 @@ def get_cam_as_rgb(cam):
)
vehicle_state_send.send(vehicle_state)

total_distance += abs(env.vehicle.position[0] - prev_x_pos)
prev_x_pos = env.vehicle.position[0]

if controls_recv.poll(0):
while controls_recv.poll(0):
steer_angle, gas, should_reset = controls_recv.recv()
Expand Down Expand Up @@ -145,10 +137,7 @@ def get_cam_as_rgb(cam):
elif out_of_lane:
done_result = (True, {"out_of_lane" : True})
elif timeout:
if total_distance < minimal_distance:
done_result = (True, {"minimal_distance" : True})
else:
done_result = (True, {"timeout" : True})
done_result = (True, {"timeout" : True})

simulation_state = metadrive_simulation_state(
running=False,
Expand Down
6 changes: 3 additions & 3 deletions tools/sim/bridge/metadrive/metadrive_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class MetaDriveWorld(World):
def __init__(self, status_q, config, test_duration, minimal_distance, test_run, dual_camera=False):
def __init__(self, status_q, config, test_duration, test_run, dual_camera=False):
super().__init__(dual_camera)
self.status_q = status_q
self.camera_array = Array(ctypes.c_uint8, W*H*3)
Expand All @@ -41,7 +41,7 @@ def __init__(self, status_q, config, test_duration, minimal_distance, test_run,
functools.partial(metadrive_process, dual_camera, config,
self.camera_array, self.wide_camera_array, self.image_lock,
self.controls_recv, self.simulation_state_send,
self.vehicle_state_send, self.exit_event, self.op_engaged, test_duration, minimal_distance, self.test_run))
self.vehicle_state_send, self.exit_event, self.op_engaged, test_duration, self.test_run))

self.metadrive_process.start()
self.status_q.put(QueueMessage(QueueMessageType.START_STATUS, "starting"))
Expand Down Expand Up @@ -105,7 +105,7 @@ def read_sensors(self, state: SimulatorState):
if x_dist >= dist_threshold or y_dist >= dist_threshold: # position not the same during staying still, > threshold is considered moving
self.distance_moved += x_dist + y_dist

time_check_threshold = 7.5
time_check_threshold = 30
current_time = time.monotonic()
since_last_check = current_time - self.last_check_timestamp
if since_last_check >= time_check_threshold:
Expand Down
10 changes: 6 additions & 4 deletions tools/sim/tests/test_metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
@pytest.mark.filterwarnings("ignore::pyopencl.CompilerWarning") # Unimportant warning of non-empty compile log
class TestMetaDriveBridge(TestSimBridgeBase):
@pytest.fixture(autouse=True)
def setup_create_bridge(self):
self.test_duration = 15
self.minimal_distance = 10
def setup_create_bridge(self, test_duration):
# run bridge test for at least 60s, since not-moving check runs every 30s
if test_duration < 60:
test_duration = 60
self.test_duration = test_duration

def create_bridge(self):
return MetaDriveBridge(False, False, self.test_duration, self.minimal_distance, True)
return MetaDriveBridge(False, False, self.test_duration, True)

0 comments on commit dc09479

Please sign in to comment.