diff --git a/CHANGELOG.md b/CHANGELOG.md index 53d2429f69..0287b9868f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ Copy and pasting the git commit messages is __NOT__ enough. ## [Unreleased] ### Added +- Added vehicle of interest coloring through scenario studio. This lets the scenario color vehicles that match a certain pattern of vehicle id. +- SMARTS now provides `remove_provider` to remove a provider from the simulation. Use carefully. ### Changed ### Deprecated ### Fixed @@ -21,7 +23,6 @@ Copy and pasting the git commit messages is __NOT__ enough. ### Added - Added support for the [Argoverse 2 Motion Forecasting Dataset](https://www.argoverse.org/av2.html#forecasting-link) (see `scenarios/argoverse`) - Added `waymo_open_dataset` as a module at the SMARTS repo level, to be able to load waymo scenarios without any external packages -- Added vehicle of interest coloring through scenario studio. This lets the scenario color vehicles that match a certain pattern of vehicle id. ### Changed ### Deprecated ### Fixed diff --git a/smarts/core/smarts.py b/smarts/core/smarts.py index 9578d2b44a..d3d9614497 100644 --- a/smarts/core/smarts.py +++ b/smarts/core/smarts.py @@ -21,7 +21,7 @@ import logging import os import warnings -from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, Tuple +from typing import Any, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union import numpy as np from scipy.spatial.distance import cdist @@ -503,6 +503,33 @@ def _insert_provider( provider.recovery_flags = recovery_flags self._providers.insert(index, provider) + def remove_provider(self, requested_type_or_provider: Union[type, Provider]): + """Remove a provider from the simulation. + + Args: + requested_type (type | Provider): The type of the provider to remove or provider to remove. + + Returns: + Optional[Provider]: The provider that was removed. + """ + self._check_valid() + out_provider = None + if isinstance(requested_type_or_provider, type): + for i, provider in enumerate(self._providers): + if isinstance(provider, requested_type_or_provider): + self._providers.pop(i) + out_provider = provider + elif isinstance(requested_type_or_provider, Provider): + try: + self._providers.remove(requested_type_or_provider) + except ValueError: + pass + else: + out_provider = requested_type_or_provider + if isinstance(out_provider, TrafficProvider): + self._traffic_sims.remove(out_provider) + return out_provider + def switch_ego_agents(self, agent_interfaces: Dict[str, AgentInterface]): """Change the ego agents in the simulation. Effective on the next reset.""" self._check_valid()