Skip to content

Commit

Permalink
ci: faster metadrive test (#33755)
Browse files Browse the repository at this point in the history
* fast

* fix

* same ratio

* output

* check old

* error

* fail

* better

* log

* test faster runner

* work?

* test

* ratio

* forward

* try without wait

* test old distance

* fxi

* test old runner

* test this

* assert distance

* cleanup

* better

* get distance

* cleanup

* choose runner

* very slow

* wait

* put this back
  • Loading branch information
maxime-desroches authored Oct 9, 2024
1 parent 48abdf8 commit d7c0906
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tools_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ env:
jobs:
simulator_driving:
name: simulator driving
runs-on: ubuntu-latest
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' }}
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
Expand Down
5 changes: 3 additions & 2 deletions tools/sim/bridge/metadrive/metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def create_map(track_size=60):
class MetaDriveBridge(SimulatorBridge):
TICKS_PER_FRAME = 5

def __init__(self, dual_camera, high_quality, test_duration=math.inf, test_run=False):
def __init__(self, dual_camera, high_quality, test_duration=math.inf, minimal_distance=0, 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 @@ -90,4 +91,4 @@ def spawn_world(self, queue: Queue):
anisotropic_filtering=False
)

return MetaDriveWorld(queue, config, self.test_duration, self.test_run, self.dual_camera)
return MetaDriveWorld(queue, config, self.test_duration, self.minimal_distance, self.test_run, self.dual_camera)
15 changes: 13 additions & 2 deletions tools/sim/bridge/metadrive/metadrive_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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 @@ -50,7 +51,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, test_run):
exit_event, op_engaged, test_duration, minimal_distance, test_run):
arrive_dest_done = config.pop("arrive_dest_done", True)
apply_metadrive_patches(arrive_dest_done)

Expand All @@ -70,6 +71,7 @@ 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 @@ -98,6 +100,9 @@ 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 @@ -107,6 +112,9 @@ 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 @@ -137,7 +145,10 @@ def get_cam_as_rgb(cam):
elif out_of_lane:
done_result = (True, {"out_of_lane" : True})
elif timeout:
done_result = (True, {"timeout" : True})
if total_distance < minimal_distance:
done_result = (True, {"minimal_distance" : True})
else:
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, test_run, dual_camera=False):
def __init__(self, status_q, config, test_duration, minimal_distance, 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, test_run, dual_camera=False)
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, self.test_run))
self.vehicle_state_send, self.exit_event, self.op_engaged, test_duration, minimal_distance, 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 = 30
time_check_threshold = 7.5
current_time = time.monotonic()
since_last_check = current_time - self.last_check_timestamp
if since_last_check >= time_check_threshold:
Expand Down
10 changes: 4 additions & 6 deletions tools/sim/tests/test_metadrive_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
@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, 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 setup_create_bridge(self):
self.test_duration = 15
self.minimal_distance = 10

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

0 comments on commit d7c0906

Please sign in to comment.