facebookresearch / nocturne

A data-driven, fast driving simulator for multi-agent coordination under partial observability.
MIT License
259 stars 29 forks source link

[Bug] Unexpected behavior when setting padding=True in scenario.visible_state() #48

Closed bhyang closed 2 years ago

bhyang commented 2 years ago

Operating system

Ubuntu 20.04

Bug description

Hi,

The description for the visible_state method in examples/nocturne_functions.py says that setting padding=True will add extra objects to the dict to hit the maximum number of objects for each type.

So for the default scenario config (where max_visible_objects is 16) we'd expect visible_dict['objects'].shape == (16,13).

But if you set padding=True, you actually get (7,13). The original unpadded shape is (5,13).

Additionally, visible_dict['traffic_lights'] and visible_dict['stop_signs'] have shapes (0,12) and (0,3) respectively when padding=True even though the maxes are nonzero.

The final shapes will also change depending on the vehicles and scenarios even when padding=True.

If I'm misunderstanding the expected behavior, please let me know.

Thanks!

Steps to reproduce

Here's a short script that reproduces the issue (run the same as examples/nocturne_functions.py)

import hydra
import numpy as np

from cfgs.config import PROJECT_PATH, get_scenario_dict, set_display_window
from nocturne import Simulation, Action

@hydra.main(config_path="../cfgs/", config_name="config")
def main(cfg):
    # load scenario. by default this won't have pedestrians or cyclists
    scenario_config = get_scenario_dict(cfg)
    sim = Simulation(scenario_path=str(PROJECT_PATH / 'examples' /
                                       'example_scenario.json'),
                     config=scenario_config)
    scenario = sim.getScenario()
    vehs = scenario.getObjectsThatMoved()

    visible_dict = scenario.visible_state(object=vehs[0],
                                          view_dist=80,
                                          view_angle=120 * (np.pi / 180),
                                          padding=True)

    print('Expecting {} objects, got {}'.format(scenario_config['max_visible_objects'], visible_dict['objects'].shape[0]))
    print('Expecting {} road points, got {}'.format(scenario_config['max_visible_road_points'], visible_dict['road_points'].shape[0]))
    print('Expecting {} traffic lights, got {}'.format(scenario_config['max_visible_traffic_lights'], visible_dict['traffic_lights'].shape[0]))
    print('Expecting {} stop signs, got {}'.format(scenario_config['max_visible_stop_signs'], visible_dict['stop_signs'].shape[0]))

main()

Relevant log output

No response

xiaomengy commented 2 years ago

Thanks for reporting this. We will investigate it ASAP.

eugenevinitsky commented 2 years ago

Ah! The bug here is that the named values are not working. In the pybind code there's a missing argument to the corresponding C++ function so instead of passing padding=0 you wind up passing a head_angle=0. Thank you for catching and reporting this! We've also added unit tests there so that this doesn't happen again.

We'll merge it shortly but the fix is here: https://github.com/facebookresearch/nocturne/pull/49

eugenevinitsky commented 2 years ago

It is now merged and if you pull master this should be resolved. I'm closing this but feel free to re-open it if you find issues!