Skip to content

Commit

Permalink
Update literals.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamenot committed Jun 9, 2023
1 parent c04a1cd commit 3cf15b1
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion envision/tests/test_data_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def test_covered_data_format(covered_data):

def test_primitive_data_format(primitive_data):
for unformatted, formatted in primitive_data:

es = EnvisionDataFormatter(EnvisionDataFormatterArgs(None))
es.add_any(unformatted)

Expand Down
13 changes: 5 additions & 8 deletions smarts/core/plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from smarts.core.coordinates import Dimensions, Heading, Point, Pose, RefLinePoint
from smarts.core.road_map import RoadMap
from smarts.core.utils.math import min_angles_difference_signed, vec_to_radians
from smarts.primatives.constants import SmartsLiteral
from smarts.primatives.constants import MISSING
from smarts.sstudio.types import EntryTactic, TrapEntryTactic


Expand Down Expand Up @@ -191,7 +191,7 @@ def _drove_off_map(self, veh_pos: Point, veh_heading: float) -> bool:
def default_entry_tactic(default_entry_speed: Optional[float] = None) -> EntryTactic:
"""The default tactic the simulation will use to acquire an actor for an agent."""
return TrapEntryTactic(
start_time=SmartsLiteral.MISSING,
start_time=MISSING,
wait_to_hijack_limit_s=0,
exclusion_prefixes=tuple(),
zone=None,
Expand Down Expand Up @@ -234,7 +234,7 @@ class Mission:
# An optional list of road IDs between the start and end goal that we want to
# ensure the mission includes
route_vias: Tuple[str, ...] = field(default_factory=tuple)
start_time: Union[float, Literal[SmartsLiteral.MISSING]] = SmartsLiteral.MISSING
start_time: Union[float, Literal[MISSING]] = MISSING
entry_tactic: Optional[EntryTactic] = None
via: Tuple[Via, ...] = ()
# if specified, will use vehicle_spec to build the vehicle (for histories)
Expand Down Expand Up @@ -284,12 +284,9 @@ def random_endless_mission(
return Mission.endless_mission(start_pose=target_pose)

def __post_init__(self):
if (
self.entry_tactic is not None
and self.entry_tactic.start_time != SmartsLiteral.MISSING
):
if self.entry_tactic is not None and self.entry_tactic.start_time != MISSING:
object.__setattr__(self, "start_time", self.entry_tactic.start_time)
elif self.start_time == SmartsLiteral.MISSING:
elif self.start_time == MISSING:
object.__setattr__(self, "start_time", 0.1)


Expand Down
5 changes: 3 additions & 2 deletions smarts/core/trap_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from smarts.core.utils.file import replace
from smarts.core.utils.math import clip, squared_dist
from smarts.core.vehicle import Vehicle
from smarts.primatives.constants import AUTO
from smarts.sstudio.types import MapZone, PositionalZone, TrapEntryTactic


Expand Down Expand Up @@ -355,11 +356,11 @@ def _mission2trap(self, road_map, mission: Mission, default_zone_dist: float = 6
default_entry_speed = entry_tactic.default_entry_speed
n_lane = None

if default_entry_speed is None:
if default_entry_speed is AUTO:
n_lane = road_map.nearest_lane(mission.start.point)
default_entry_speed = n_lane.speed_limit if n_lane is not None else 0

if zone is None:
if zone is AUTO:
n_lane = n_lane or road_map.nearest_lane(mission.start.point)
if n_lane is None:
zone = PositionalZone(mission.start.position[:2], size=(3, 3))
Expand Down
14 changes: 8 additions & 6 deletions smarts/primatives/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import sys
from enum import Enum
from typing import Final


class SmartsLiteral(Enum):
AUTO = "auto"
MAX = sys.maxsize
MISSING = sys.maxsize
AUTO: Final = "auto"
MAX: Final = 9223372036854775807
MISSING: Final = MAX
NONE: Final = None


AUTO = SmartsLiteral.AUTO
MAX = SmartsLiteral.MAX
AUTO: Final = SmartsLiteral.AUTO
MAX: Final = SmartsLiteral.MAX
MISSING = SmartsLiteral.MISSING
NONE: Final = SmartsLiteral.NONE
7 changes: 4 additions & 3 deletions smarts/sstudio/types/entry_tactic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@


from dataclasses import dataclass
from typing import Optional, Tuple
from typing import Literal, Tuple, Union

from smarts.core.condition_state import ConditionState
from smarts.primatives.constants import AUTO
from smarts.sstudio.types.condition import (
Condition,
ConditionRequires,
Expand All @@ -51,11 +52,11 @@ class TrapEntryTactic(EntryTactic):

wait_to_hijack_limit_s: float = 0
"""The amount of seconds a hijack will wait to get a vehicle before defaulting to a new vehicle"""
zone: Optional[MapZone] = None
zone: Union[MapZone, Literal[AUTO]] = AUTO
"""The zone of the hijack area"""
exclusion_prefixes: Tuple[str, ...] = tuple()
"""The prefixes of vehicles to avoid hijacking"""
default_entry_speed: Optional[float] = None
default_entry_speed: Union[float, Literal[AUTO]] = AUTO
"""The speed that the vehicle starts at when the hijack limit expiry emits a new vehicle"""
condition: Condition = LiteralCondition(ConditionState.TRUE)
"""A condition that is used to add additional exclusions."""
Expand Down
5 changes: 3 additions & 2 deletions smarts/sstudio/types/map_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
# The idea here is that anything in SMARTS that needs to use a RoadMap
# can call this builder to get or create one as necessary.
from dataclasses import dataclass
from typing import Any, Callable, Optional, Tuple
from typing import Any, Callable, Literal, Optional, Tuple, Union

from smarts.core.default_map_builder import get_road_map
from smarts.core.road_map import RoadMap
from smarts.primatives.constants import AUTO

MapBuilder = Callable[[Any], Tuple[Optional[RoadMap], Optional[str]]]

Expand All @@ -45,7 +46,7 @@ class MapSpec:
"""A path or URL or name uniquely designating the map source."""
lanepoint_spacing: float = 1.0
"""The default distance between pre-generated Lane Points (Waypoints)."""
default_lane_width: Optional[float] = None
default_lane_width: Union[float, Literal[AUTO]] = AUTO
"""If specified, the default width (in meters) of lanes on this map."""
shift_to_origin: bool = False
"""If True, upon creation a map whose bounding-box does not intersect with
Expand Down
12 changes: 6 additions & 6 deletions smarts/sstudio/types/mission.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from dataclasses import dataclass
from typing import Literal, Optional, Tuple, Union

from smarts.primatives.constants import SmartsLiteral
from smarts.primatives.constants import AUTO, MISSING
from smarts.sstudio.types.entry_tactic import EntryTactic
from smarts.sstudio.types.route import JunctionEdgeIDResolver, RandomRoute, Route

Expand Down Expand Up @@ -55,7 +55,7 @@ class Mission:
via: Tuple[Via, ...] = ()
"""Points on an road that an actor must pass through"""

start_time: Union[float, Literal[SmartsLiteral.MISSING]] = SmartsLiteral.MISSING
start_time: Union[float, Literal[MISSING]] = MISSING
"""The earliest simulation time that this mission starts but may start later in couple with
`entry_tactic`.
"""
Expand Down Expand Up @@ -87,7 +87,7 @@ class EndlessMission:
"""
via: Tuple[Via, ...] = ()
"""Points on a road that an actor must pass through"""
start_time: Union[float, Literal[SmartsLiteral.MISSING]] = SmartsLiteral.MISSING
start_time: Union[float, Literal[MISSING]] = MISSING
"""The earliest simulation time that this mission starts"""
entry_tactic: Optional[EntryTactic] = None
"""A specific tactic the mission should employ to start the mission"""
Expand All @@ -112,15 +112,15 @@ class LapMission:
"""The amount of times to repeat the mission"""
via: Tuple[Via, ...] = ()
"""Points on a road that an actor must pass through"""
start_time: Union[float, Literal[SmartsLiteral.MISSING]] = SmartsLiteral.MISSING
start_time: Union[float, Literal[MISSING]] = MISSING
"""The earliest simulation time that this mission starts"""
entry_tactic: Optional[EntryTactic] = None
"""A specific tactic the mission should employ to start the mission"""

def __post_init__(self):
assert isinstance(self.route, Route)
assert self.route.begin != SmartsLiteral.AUTO
assert self.route.end != SmartsLiteral.AUTO
assert self.route.begin != AUTO
assert self.route.end != AUTO
if self.start_time != sys.maxsize:
warnings.warn(
"`start_time` is deprecated. Instead use `entry_tactic=EntryTactic(start_time=...)`.",
Expand Down
6 changes: 3 additions & 3 deletions smarts/sstudio/types/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from smarts.core import gen_id
from smarts.core.utils.file import pickle_hash_int
from smarts.primatives.constants import SmartsLiteral
from smarts.primatives.constants import AUTO
from smarts.sstudio.types.map_spec import MapSpec


Expand Down Expand Up @@ -59,7 +59,7 @@ class Route:
"""

## road, lane index, offset
begin: Union[Tuple[str, int, Any], Literal[SmartsLiteral.AUTO]]
begin: Union[Tuple[str, int, Any], Literal[AUTO]]
"""The (road, lane_index, offset) details of the start location for the route.
road:
Expand All @@ -70,7 +70,7 @@ class Route:
The offset in meters into the lane. Also acceptable\\: "max", "random"
"""
## road, lane index, offset
end: Union[Tuple[str, int, Any], Literal[SmartsLiteral.AUTO]]
end: Union[Tuple[str, int, Any], Literal[AUTO]]
"""The (road, lane_index, offset) details of the end location for the route.
road:
Expand Down

0 comments on commit 3cf15b1

Please sign in to comment.