motional / nuplan-devkit

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

"ArgumentError" creating the `NuPlanDBWrapper` class object. #233

Closed juanwulu closed 1 year ago

juanwulu commented 1 year ago

Hello dev-team,

I was exploring your tutorial notebooks on the master branch. But I ran into an ArgumentError trying to run the ORM Database API in the nuplan_advanced_model_training.ipynb notebook. The codes in the cell are as follows:

from nuplan.database.nuplan_db_orm.nuplandb_wrapper import NuPlanDBWrapper

nuplandb_wrapper = NuPlanDBWrapper(
    data_root=NUPLAN_DATA_ROOT,
    map_root=NUPLAN_MAPS_ROOT,
    db_files=NUPLAN_DB_FILES,
    map_version=NUPLAN_MAP_VERSION,
)

and the error message are as follows

ArgumentError                             Traceback (most recent call last)
Cell In[11], line 1
----> 1 from nuplan.database.nuplan_db_orm.nuplandb_wrapper import NuPlanDBWrapper
      3 NuPlanDBWrapper(
      4     data_root=NUPLAN_DATA_ROOT,
      5     map_root=NUPLAN_MAPS_ROOT,
      6     db_files=NUPLAN_DB_FILES,
      7     map_version=NUPLAN_MAP_VERSION
      8 )

File [~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/nuplandb_wrapper.py:13](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/nuplandb_wrapper.py:13)
     11 from nuplan.common.utils.s3_utils import check_s3_path_exists, expand_s3_dir
     12 from nuplan.database.maps_db.gpkg_mapsdb import GPKGMapsDB
---> 13 from nuplan.database.nuplan_db_orm.nuplandb import NuPlanDB
     14 from nuplan.database.nuplan_db_orm.scene import Scene
     16 logger = logging.getLogger(__name__)

File [~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/nuplandb.py:13](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/nuplandb.py:13)
     11 from nuplan.database.nuplan_db_orm.category import Category
     12 from nuplan.database.nuplan_db_orm.ego_pose import EgoPose
---> 13 from nuplan.database.nuplan_db_orm.image import Image
     14 from nuplan.database.nuplan_db_orm.lidar import Lidar
     15 from nuplan.database.nuplan_db_orm.lidar_box import LidarBox

File [~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/image.py:22](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/image.py:22)
     20 from nuplan.database.nuplan_db_orm.frame import Frame
     21 from nuplan.database.nuplan_db_orm.lidar_box import LidarBox
---> 22 from nuplan.database.nuplan_db_orm.lidar_pc import LidarPc
     23 from nuplan.database.nuplan_db_orm.models import Base
     24 from nuplan.database.nuplan_db_orm.scene import Scene

File [~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/lidar_pc.py:21](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/lidar_pc.py:21)
     19 from nuplan.database.nuplan_db_orm.lidar_box import LidarBox
     20 from nuplan.database.nuplan_db_orm.models import Base
---> 21 from nuplan.database.nuplan_db_orm.scene import Scene
     22 from nuplan.database.nuplan_db_orm.utils import get_boxes, get_future_box_sequence, pack_future_boxes, render_on_map
     23 from nuplan.database.utils.boxes.box3d import Box3D

File [~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/scene.py:19](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/Desktop/project/cvpr23-nuplan/nuplan-devkit/nuplan/database/nuplan_db_orm/scene.py:19)
     14 from nuplan.database.nuplan_db_orm.models import Base
     16 logger = logging.getLogger()
---> 19 class Scene(Base):
     20     """
     21     Scenes in a Log.
     22     """
     24     __tablename__ = 'scene'

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py:199](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_api.py:199), in DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw)
    196         cls._sa_registry = reg
    198 if not cls.__dict__.get("__abstract__", False):
--> 199     _as_declarative(reg, cls, dict_)
    200 type.__init__(cls, classname, bases, dict_)

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:248](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:248), in _as_declarative(registry, cls, dict_)
    242 def _as_declarative(
    243     registry: _RegistryType, cls: Type[Any], dict_: _ClassDict
    244 ) -> Optional[_MapperConfig]:
    245 
    246     # declarative scans the class for attributes.  no table or mapper
    247     # args passed separately.
--> 248     return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:329](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:329), in _MapperConfig.setup_mapping(cls, registry, cls_, dict_, table, mapper_kw)
    325     return _DeferredMapperConfig(
    326         registry, cls_, dict_, table, mapper_kw
    327     )
    328 else:
--> 329     return _ClassScanMapperConfig(
    330         registry, cls_, dict_, table, mapper_kw
    331     )

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:563](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:563), in _ClassScanMapperConfig.__init__(self, registry, cls_, dict_, table, mapper_kw)
    559 self.allow_dataclass_fields = bool(sdk and cld)
    561 self._setup_declared_events()
--> 563 self._scan_attributes()
    565 self._setup_dataclasses_transforms()
    567 with mapperlib._CONFIGURE_MUTEX:

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:1005](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:1005), in _ClassScanMapperConfig._scan_attributes(self)
   1001     self._collect_annotation(
   1002         name, annotation, base, False, obj
   1003     )
   1004 else:
-> 1005     collected_annotation = self._collect_annotation(
   1006         name, annotation, base, None, obj
   1007     )
   1008     is_mapped = (
   1009         collected_annotation is not None
   1010         and collected_annotation.mapped_container is not None
   1011     )
   1012     generated_obj = (
   1013         collected_annotation.attr_value
   1014         if collected_annotation is not None
   1015         else obj
   1016     )

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:1233](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/decl_base.py:1233), in _ClassScanMapperConfig._collect_annotation(self, name, raw_annotation, originating_class, expect_mapped, attr_value)
   1230     is_dataclass_field = False
   1232 is_dataclass_field = False
-> 1233 extracted = _extract_mapped_subtype(
   1234     raw_annotation,
   1235     self.cls,
   1236     originating_class.__module__,
   1237     name,
   1238     type(attr_value),
   1239     required=False,
   1240     is_dataclass_field=is_dataclass_field,
   1241     expect_mapped=expect_mapped
   1242     and not is_dataclass,  # self.allow_dataclass_fields,
   1243 )
   1245 if extracted is None:
   1246     # ClassVar can come out here
   1247     return None

File [~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/util.py:2306](https://file+.vscode-resource.vscode-cdn.net/home/juanwu/Desktop/project/cvpr23-nuplan/nuplan-cvpr-23/notebook/~/miniconda3/envs/nuplan/lib/python3.9/site-packages/sqlalchemy/orm/util.py:2306), in _extract_mapped_subtype(raw_annotation, cls, originating_module, key, attr_cls, required, is_dataclass_field, expect_mapped, raiseerr)
   2303     if not raiseerr:
   2304         return None
-> 2306     raise sa_exc.ArgumentError(
   2307         f'Type annotation for "{cls.__name__}.{key}" '
   2308         "can't be correctly interpreted for "
   2309         "Annotated Declarative Table form.  ORM annotations "
   2310         "should normally make use of the ``Mapped[]`` generic "
   2311         "type, or other ORM-compatible generic type, as a "
   2312         "container for the actual type, which indicates the "
   2313         "intent that the attribute is mapped. "
   2314         "Class variables that are not intended to be mapped "
   2315         "by the ORM should use ClassVar[].  "
   2316         "To allow Annotated Declarative to disregard legacy "
   2317         "annotations which don't use Mapped[] to pass, set "
   2318         '"__allow_unmapped__ = True" on the class or a '
   2319         "superclass this class.",
   2320         code="zlpr",
   2321     )
   2323 else:
   2324     return annotated, None

ArgumentError: Type annotation for "Scene.goal_ego_pose" can't be correctly interpreted for Annotated Declarative Table form.  ORM annotations should normally make use of the ``Mapped[]`` generic type, or other ORM-compatible generic type, as a container for the actual type, which indicates the intent that the attribute is mapped. Class variables that are not intended to be mapped by the ORM should use ClassVar[].  To allow Annotated Declarative to disregard legacy annotations which don't use Mapped[] to pass, set "__allow_unmapped__ = True" on the class or a superclass this class. (Background on this error at: https://sqlalche.me/e/20/zlpr)

For your information, I'm using miniconda version 22.11.1 on Linux Kernel version 5.19.0-32-generic. I followed the installation steps in your documentation and had no problem running codes from another notebook, nuplan_framework.ipynb. Could you help resolve this issue?

Much appreciated. :)

patk-motional commented 1 year ago

@ChocolateDave,

Thanks for raising the issue. We will investigate this issue and get back to you

tinkei commented 1 year ago

Same issue as #228 Make sure your SQLAlchemy package is below version 2 via pip install -U "SQLAlchemy<2.0.0"

More details here.

mrsandipandas commented 1 year ago

Same env as OP. Solved as installing SQLAlchemy==1.4.27.

bulbcult commented 1 year ago

Same env as OP. Solved as installing SQLAlchemy==1.4.27.

Solved with this approach! thx

juanwulu commented 1 year ago

@tinkei Thanks for the helpful suggestions. It would be really nice if the dev team can include this version requirements in their requirements.txt file.