Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI/Simulator: Drive a loop in metadrive #32308

Merged
merged 55 commits into from
May 22, 2024

Conversation

bongbui321
Copy link
Contributor

@bongbui321 bongbui321 commented Apr 28, 2024

Resolve #30694

Currently, the simulator will fail when it tries to cross lane , and can change the track_size for CI testing. can test by ./test_metadrive_bridge.py 30, which would be a fail case on the curve

Try and run test locally with this cmd: pytest tools/sim/tests/test_metadrive_bridge.py --time_done=<seconds>

Depends on: metadriverse/metadrive#710

  • deterministic test
    - [ ] update poetry Metadrive maintainer is a while to review, detect out of lane locally for now
    - [ ] maybe more test cases (lead car, etc) traffic is extremely expensive even running locally with decent gpu

Copy link
Contributor

github-actions bot commented Apr 28, 2024

Thanks for contributing to openpilot! In order for us to review your PR as quickly as possible, check the following:

  • Convert your PR to a draft unless it's ready to review
  • Read the contributing docs
  • Before marking as "ready for review", ensure:
    • the goal is clearly stated in the description
    • all the tests are passing
    • the change is something we merge
    • include a route or your device' dongle ID if relevant

@github-actions github-actions bot added simulation running openpilot in environments like CARLA tools labels Apr 28, 2024
@bongbui321 bongbui321 marked this pull request as draft April 28, 2024 09:07
@bongbui321
Copy link
Contributor Author

bongbui321 commented May 20, 2024

Tried running locally with pytest tools/sim/tests/test_metadrive_bridge.py --time_done=600 (10mins). can modify to run the loop as long as you want it to be

Copy link
Contributor

@adeebshihadeh adeebshihadeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took me a few attempts to get this running locally. Seems like there were two main issues:

UserWarning: PyOpenCL compiler caching failed with an exception:
[begin exception]
Traceback (most recent call last):
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pyopencl/cache.py", line 495, in create_built_program_from_source_cached
    _create_built_program_from_source_cached(
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pyopencl/cache.py", line 417, in _create_built_program_from_source_cached
    prg.build(options_bytes, [devices[i] for i in to_be_built_indices])
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pyopencl/__init__.py", line 772, in program_build
    compiler_output("%s succeeded, but resulted in non-empty logs:\n%s"
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/site-packages/pyopencl/__init__.py", line 273, in compiler_output
    warn("Non-empty compiler output encountered. Set the "
pyopencl.CompilerWarning: Non-empty compiler output encountered. Set the environment variable PYOPENCL_COMPILER_OUTPUT=1 to see more.
[end exception]

and

State:
Ignition: True Engaged: False


State:
Ignition: True Engaged: False
    Waiting for CAN messages...
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd
Process bridge:
Traceback (most recent call last):
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/home/batman/.pyenv/versions/3.11.4/lib/python3.11/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/dev/shm/openpilot/threepilot/openpilot/tools/sim/bridge/common.py", line 71, in bridge_keep_alive
    self._run(q)
  File "/dev/shm/openpilot/threepilot/openpilot/tools/sim/bridge/common.py", line 197, in _run
    self.print_status()
  File "/dev/shm/openpilot/threepilot/openpilot/tools/sim/bridge/common.py", line 88, in print_status
    print(
BlockingIOError: [Errno 11] write could not complete without blocking

modeld init
setting up CL context
CL context ready; loading model
Onnx available providers:  ['TensorrtExecutionProvider', 'CUDAExecutionProvider', 'AzureExecutionProvider', 'CPUExecutionProvider']
Onnx selected provider:  [('CUDAExecutionProvider', {'cudnn_conv_algo_search': 'DEFAULT'})]
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd
Onnx using  ['CUDAExecutionProvider', 'CPUExecutionProvider']
ready to run onnx model {'input_imgs': [1, 12, 128, 256], 'big_input_imgs': [1, 12, 128, 256], 'desire': [1, 100, 8], 'traffic_convention': [1, 2], 'lateral_control_params': [1, 2], 'prev_desired_curv': [1, 100, 1], 'features_buffer': [1, 99, 512]}
models loaded, modeld starting
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd
logcatd proclogd modeld ui soundd locationd calibrationd torqued controlsd deleter navd paramsd plannerd radard thermald statsd

tools/sim/tests/test_script.sh Outdated Show resolved Hide resolved
.github/workflows/tools_tests.yaml Outdated Show resolved Hide resolved
tools/sim/tests/conftest.py Outdated Show resolved Hide resolved
tools/sim/tests/test_metadrive_bridge.py Show resolved Hide resolved
tools/sim/bridge/metadrive/metadrive_process.py Outdated Show resolved Hide resolved
@bongbui321 bongbui321 marked this pull request as draft May 20, 2024 13:32
@bongbui321
Copy link
Contributor Author

bongbui321 commented May 20, 2024

BlockingIOError: [Errno 11] write could not complete without blocking

Never encounter this issue, through all my run and just tried 100 run locally and still don't get this, but my best guess is that because printing out to the same stdout (both the metadrive bridge and OP) which causes a small chance for them trying to print at the same time.

3b644dd change makes it don't print the metadrive state during test, which is for interactive purposes in the first place, and the unittest already covered always be able to engage

@bongbui321 bongbui321 marked this pull request as ready for review May 21, 2024 15:37
Copy link
Contributor

@adeebshihadeh adeebshihadeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had no issues running locally now. However, it's easy to make the test pass when it shouldn't with this patch. I think adding a check on distance (based on the time) should be enough. Other than that, seems good to go.

diff --git a/tools/sim/bridge/common.py b/tools/sim/bridge/common.py
index 64407143f..997a2e0cf 100644
--- a/tools/sim/bridge/common.py
+++ b/tools/sim/bridge/common.py
@@ -184,6 +184,7 @@ Ignition: {self.simulator_state.ignition} Engaged: {self.simulator_state.is_enga
       brake_out = brake_op if self.simulator_state.is_engaged else brake_manual
       steer_out = steer_op if self.simulator_state.is_engaged else steer_manual

+      throttle_out = 0.
       self.world.apply_controls(steer_out, throttle_out, brake_out)
       self.world.read_state()
       self.world.read_sensors(self.simulator_state)

@bongbui321
Copy link
Contributor Author

bongbui321 commented May 22, 2024

The current distance vs time check is decent for now. I intend to add fps check and OP time in CI vs real time check in the metadrive GHA bounty. Check for staying still at 5s works locally but needed 30s in CI due it being slower, will improve this for the CI bounty

@adeebshihadeh adeebshihadeh merged commit fe9a091 into commaai:master May 22, 2024
16 checks passed
@adeebshihadeh
Copy link
Contributor

Nice work! Looking forward to getting this in CI.

@bongbui321 bongbui321 deleted the metadrive_loop branch May 22, 2024 17:35
macdoos pushed a commit to macdoos/openpilot that referenced this pull request May 25, 2024
* finish failure on crossing any line

* update

* standardize queue messages

* update control_command_gen

* fix

* fix logic

* update closing type

* update test

* update logic

* update test

* add out of lane to local

* ci arrive_dest

* pytest integration

* update ci_config

* fix ruff

* move test termination to time

* better

* better order

* curve_len

* add buffer

* cleanup

* cleanup

* cleanup

* cleanup

* out_of_lane

* cleanup

* merge tests

* run 90s

* change test name

* local out of lane detect

* out_of_lane

* static anal

* cleanup

* test_duration

* change setup_class -> setup_create_bridge

* no print state during test

* new out_of_lane detect

* cleanup print in common.py

* fix

* fix

* check distance vs time

* cleanup

* cleanup increase check time

* minimum bridge test time

* wording

* cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
simulation running openpilot in environments like CARLA tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[$500 bounty] Drive a loop in MetaDrive
2 participants