Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add remove_provider method #1917

Merged
merged 2 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
### Deprecated
### Fixed
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