Skip to content

Commit

Permalink
Merge pull request #99 from motional/update-devkit-v0.4
Browse files Browse the repository at this point in the history
Update devkit to v0.4
  • Loading branch information
patk-motional authored Aug 11, 2022
2 parents 5f169ee + d87bee8 commit be36ee5
Show file tree
Hide file tree
Showing 424 changed files with 14,053 additions and 10,386 deletions.
3 changes: 2 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")
package(default_visibility = ["//visibility:public"])

filegroup(
name = "jenkins_env",
name = "requirements",
data = [
"requirements.txt",
"requirements_torch.txt",
],
)

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ______________________________________________________________________
<a href="https://github.com/motional/nuplan-devkit/blob/master/tutorials/nuplan_framework.ipynb">Tutorial</a>
</p>

[![python](https://img.shields.io/badge/python-3.8%20%7C%203.9-blue.svg)]()
[![python](https://img.shields.io/badge/python-%20%203.9-blue.svg)]()
[![license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/motional/nuplan-devkit/blob/master/LICENSE.txt)

______________________________________________________________________
Expand All @@ -32,8 +32,10 @@ Stay tuned for the upcoming nuPlan ML planning challenges!
______________________________________________________________________

## Changelog
- Aug 05 2022
* v0.4 Devkit: Database optimization, PYGEOS warning suppression, metrics improvements, scenario filter for training.
- Jul 15 2022
* v0.3 Devkit: Updates to the devit including but not limited to: nuBoard update, reduce RAM usage during caching and training, new map APIs, simulation and metrics runtime improvements.
* v0.3 Devkit: Updates to the devit including but not limited to: nuBoard update, reduce RAM usage during caching and training, new map APIs, simulation and metrics runtime improvements.
- Jun 10 2022
* v1.0 Dataset: Full nuPlan dataset release with over 1,300 hours of driving data (15,000+ logs) across 4 cities (Las Vegas, Pittsburgh, Boston, Singapore).
* v0.2 Devkit: Multiple devkit updates with improvements across the whole framework (planning models, training, simulation, metrics, dashboard, tutorials and more).
Expand Down
4 changes: 2 additions & 2 deletions nuplan/cli/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ py_library(
name = "db_cli",
srcs = ["db_cli.py"],
deps = [
"//nuplan/database/nuplan_db:nuplandb",
"//nuplan/database/nuplan_db:scenario_tag",
"//nuplan/database/nuplan_db:db_cli_queries",
"//nuplan/planning/scenario_builder/nuplan_db:nuplan_scenario_utils",
],
)

Expand Down
117 changes: 66 additions & 51 deletions nuplan/cli/db_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,40 @@

import typer

from nuplan.database.nuplan_db.nuplandb import NuPlanDB
from nuplan.database.nuplan_db.scenario_tag import ScenarioTag
from nuplan.database.nuplan_db.db_cli_queries import (
get_db_description,
get_db_duration_in_us,
get_db_log_duration,
get_db_log_vehicles,
get_db_scenario_info,
)
from nuplan.planning.scenario_builder.nuplan_db.nuplan_scenario_utils import download_file_if_necessary

cli = typer.Typer()

NUPLAN_DATA_ROOT = os.getenv('NUPLAN_DATA_ROOT', "/data/sets/nuplan/")
NUPLAN_DB_VERSION = f'{NUPLAN_DATA_ROOT}/nuplan-v1.0/mini/2021.07.16.20.45.29_veh-35_01095_01486.db'


def _ensure_file_downloaded(data_root: str, potentially_remote_path: str) -> str:
"""
Attempts to download the DB file from a remote URL if it does not exist locally.
If the download fails, an error will be raised.
:param data_root: The location to download the file, if necessary.
:param potentially_remote_path: The path to the file.
:return: The resulting file path. Will be one of a few options:
* If potentially_remote_path points to a local file, will return potentially_remote_path
* If potentially_remote_file points to a remote file, it does not exist currently, and the file can be successfully downloaded, it will return the path of the downloaded file.
* In all other cases, an error will be raised.
"""
output_file_path: str = download_file_if_necessary(data_root, potentially_remote_path)

if not os.path.exists(output_file_path):
raise ValueError(f"{potentially_remote_path} could not be downloaded.")

return output_file_path


@cli.command()
def info(
db_version: str = typer.Argument(NUPLAN_DB_VERSION, help="The database version."),
Expand All @@ -20,11 +45,24 @@ def info(
"""
Print out detailed information about the selected database.
"""
# Construct database
db = NuPlanDB(load_path=db_version, data_root=data_root)
# Use the default __str__
typer.echo("DB info")
typer.echo(db)
db_version = _ensure_file_downloaded(data_root, db_version)
db_description = get_db_description(db_version)

for table_name, table_description in db_description.tables.items():
typer.echo(f"Table {table_name}: {table_description.row_count} rows")

for column_name, column_description in table_description.columns.items():
typer.echo(
"".join(
[
f"\tcolumn {column_name}: {column_description.data_type} ",
"NULL " if column_description.nullable else "NOT NULL ",
"PRIMARY KEY " if column_description.is_primary_key else "",
]
)
)

typer.echo()


@cli.command()
Expand All @@ -35,16 +73,11 @@ def duration(
"""
Print out the duration of the selected db.
"""
# Construct database
db = NuPlanDB(load_path=db_version, data_root=data_root)

# Approximate the duration of db by dividing the number of lidar_pc and the frequency of the DB
assumed_db_frequency = 20
db_duration_s = len(db.lidar_pc) / assumed_db_frequency
db_version = _ensure_file_downloaded(data_root, db_version)
db_duration_us = get_db_duration_in_us(db_version)
db_duration_s = float(db_duration_us) / 1e6
db_duration_str = time.strftime("%H:%M:%S", time.gmtime(db_duration_s))
typer.echo(
f"DB approximate duration (assuming db frequency {assumed_db_frequency}Hz) is {db_duration_str} [HH:MM:SS]"
)
typer.echo(f"DB duration is {db_duration_str} [HH:MM:SS]")


@cli.command()
Expand All @@ -55,20 +88,15 @@ def log_duration(
"""
Print out the duration of every log in the selected db.
"""
# Construct database
db = NuPlanDB(load_path=db_version, data_root=data_root)

# Approximate the duration of db by dividing the number of lidar_pc and the frequency of the DB
assumed_db_frequency = 20
db_version = _ensure_file_downloaded(data_root, db_version)
num_logs = 0
for log_file_name, log_file_duration_us in get_db_log_duration(db_version):
log_file_duration_s = float(log_file_duration_us) / 1e6
log_file_duration_str = time.strftime("%H:%M:%S", time.gmtime(log_file_duration_s))
typer.echo(f"The duration of log {log_file_name} is {log_file_duration_str} [HH:MM:SS]")
num_logs += 1

# Print out for every log the approximate durations
typer.echo(f"The DB: {db.name} contains {len(db.log)} logs")

for log in db.log:
lidar_pcs = [lidar for scene in log.scenes for lidar in scene.lidar_pcs]
db_duration_s = len(lidar_pcs) / assumed_db_frequency
db_duration_str = time.strftime("%H:%M:%S", time.gmtime(db_duration_s))
typer.echo(f"\tThe approximate duration of log {log.logfile} is {db_duration_str} [HH:MM:SS]")
typer.echo(f"There are {num_logs} total logs.")


@cli.command()
Expand All @@ -79,14 +107,9 @@ def log_vehicle(
"""
Print out vehicle information from every log in the selected database.
"""
# Construct database
db = NuPlanDB(load_path=db_version, data_root=data_root)

# Print out for every log the used vehicle
typer.echo("The used vehicles for every log follow:")

for log in db.log:
typer.echo(f"\tFor the log {log.logfile} vehicle {log.vehicle_name} of type {log.vehicle_type} was used")
db_version = _ensure_file_downloaded(data_root, db_version)
for log_file, vehicle_name in get_db_log_vehicles(db_version):
typer.echo(f"For the log {log_file}, vehicle {vehicle_name} was used.")


@cli.command()
Expand All @@ -97,21 +120,13 @@ def scenarios(
"""
Print out the available scenarios in the selected db.
"""
# Construct database
db = NuPlanDB(load_path=db_version, data_root=data_root)

# Read all available tags:
available_types = [tag[0] for tag in db.session.query(ScenarioTag.type).distinct().all()]

# Tag table
tag_table = db.scenario_tag

# Print out the available scenarios
typer.echo(f"The available scenario tags from db: {db_version} follow, in total {len(available_types)} scenarios")
db_version = _ensure_file_downloaded(data_root, db_version)
total_count = 0
for tag, num_scenarios in get_db_scenario_info(db_version):
typer.echo(f"{tag}: {num_scenarios} scenarios.")
total_count += num_scenarios

for tag in available_types:
tags = tag_table.select_many(type=tag)
typer.echo(f"\t - {tag} has {len(tags)} scenarios")
typer.echo(f"TOTAL: {total_count} scenarios.")


if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions nuplan/cli/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ py_test(
srcs = ["test_nuplan_cli.py"],
deps = [
"//nuplan/cli:nuplan_cli",
"//nuplan/common/actor_state:oriented_box",
"//nuplan/common/actor_state:state_representation",
"//nuplan/database/nuplan_db:db_description_types",
],
)
Loading

0 comments on commit be36ee5

Please sign in to comment.