From a572f80c4ed5affce03f479a7016dea6a557e38c Mon Sep 17 00:00:00 2001 From: Tucker Date: Wed, 22 Mar 2023 19:24:27 -0400 Subject: [PATCH 1/2] Add remove_provider method. --- CHANGELOG.md | 2 +- smarts/core/smarts.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53d2429f69..b2ef8e4539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ 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. ### Changed ### Deprecated ### Fixed @@ -21,7 +22,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() From 36e0c1b478c07f37547dfe58d0dcf18cd4e48a12 Mon Sep 17 00:00:00 2001 From: Tucker Date: Wed, 22 Mar 2023 19:25:03 -0400 Subject: [PATCH 2/2] Update changelog. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2ef8e4539..0287b9868f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ 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