motional / nuplan-devkit

The devkit of the nuPlan dataset.
https://www.nuplan.org
Other
674 stars 129 forks source link

How to simulate the data in the 'trainval' but not in the 'mini' ? #212

Open zurzeit opened 1 year ago

zurzeit commented 1 year ago

My problem

Hello, I am trying to simulate the simple planner run on one of the .db in the training data. I copied the code from the 'nuplan_framework' and modify a little bit.
It is alright for me to run the '.db file' in the mini folder but fail to run in the trainval folder. I traced the output message from the terminal and this is what I found. 2023-01-03 17:51:10,291 INFO {/.../nuplan-devkit/nuplan/planning/script/builders/simulation_builder.py:57} Extracting scenarios 0...DONE! It seems that I didn't get any scenario in the process. I also traced the code in the function 'get_scenarios_from_db()' and found that there is nothing output from the function 'execute_many(query, args, log_file)'. Hence, I am wondering if I miss anything in my code. Thank you in advance!

Data folder architecture

├── maps
│       ├── nuplan-maps-v1.0.json
│       ├── sg-one-north
│       ├── us-ma-boston
│       ├── us-nv-las-vegas-strip
│       └── us-pa-pittsburgh-hazelwood
└── nuplan-v1.1
        ├── mini
        └── trainval     #(The data are all from the 'Boston dataset')

My modification

  1. I modified 'scenario_builder from 'nuplan_mini' to 'nuplan'
  2. Choose the logname in the 'trainval' folder. (logname = '2021.08.18.18.32.06_veh-28_00049_00111' )
  3. change the scenario_filter.map_names to us-ma-boston
  4. set the scenario_filter.scenario_types to null

My code

import os
os.environ['USE_PYGEOS'] = '0'
import geopandas
from pathlib import Path
import tempfile

import hydra
import sys

SAVE_DIR = Path(tempfile.gettempdir()) / 'tutorial_nuplan_framework'  # optionally replace with persistent dir
# Location of path with all simulation configs
CONFIG_PATH = '../nuplan/planning/script/config/simulation'
CONFIG_NAME = 'default_simulation'

DATASET_TYPE = 'nuplan'
logname = '2021.08.18.18.32.06_veh-28_00049_00111' # for nuplan
SCENARIO_FILTER_MAPS = 'us-ma-boston'

# Select the planner and simulation challenge
PLANNER = 'simple_planner'  # [simple_planner, ml_planner]
CHALLENGE = 'open_loop_boxes'  # [open_loop_boxes, closed_loop_nonreactive_agents, closed_loop_reactive_agents]
DATASET_PARAMS = [
    f'scenario_builder={DATASET_TYPE}',  

    'scenario_filter=one_hand_picked_scenario',
    f'scenario_filter.log_names=[{logname}]',
    f'scenario_filter.map_names=[{SCENARIO_FILTER_MAPS}]',    
    'scenario_filter.scenario_types=null',  # select scenario types
]

# Name of the experiment
EXPERIMENT = 'open_loop_boxes_simulation_simple_experiment'

# Initialize configuration management system
hydra.core.global_hydra.GlobalHydra.instance().clear()  
hydra.initialize(config_path=CONFIG_PATH)

# Compose the configuration
cfg = hydra.compose(config_name=CONFIG_NAME, overrides=[
    f'experiment_name={EXPERIMENT}',
    f'group={SAVE_DIR}',
    f'planner={PLANNER}',
    f'+simulation={CHALLENGE}',

    *DATASET_PARAMS,
])

from nuplan.planning.script.run_simulation import main as main_simulation

main_simulation(cfg)
simple_simulation_folder = cfg.output_dir
zurzeit commented 1 year ago

I think I found the reason! Because the log I chose consists 4 scenes. And in the file "/.../nuplan-devkit/nuplan/database/nuplan_db/nuplan_scenario_queries.py function get_scenarios_from_db(), there is a condition in the query "valid_scenes" which finds the scenes which has at least 2 scenes before and 2 scenes after itself. As a result, the log with only 4 scenes fails to find any possible scene and return 0 scenario. I choose another .db in trainval with more than 4 scenes and the result came out successfully.

zurzeit commented 1 year ago

What is the reason behind to have the "valid_scenes" to check that condition?