Skip to content

Commit

Permalink
Add remove_provider method (#1917)
Browse files Browse the repository at this point in the history
* Add remove_provider method.

* Update changelog.
  • Loading branch information
Gamenot authored Mar 24, 2023
1 parent 960bd08 commit 816a17b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
- Changed the `lanepoint_spacing` setting in `MapSpec` to be non-optional. Lanepoints are now generated lazily when waypoints are used.
### Deprecated
Expand Down
29 changes: 28 additions & 1 deletion smarts/core/smarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 816a17b

Please sign in to comment.