Skip to content

Scenic crashes on custom map #459

@ipirwani-blip

Description

@ipirwani-blip

System Details

  1. Python version: 3.10.19
  2. Scenic version: 3.1.0
  3. Operation system: Linux a990320-lcedt 6.17.0-14-generic #14~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Jan 15 15:52:10 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  4. Simulator: CARLA 0.9.16

Detailed Description

  1. Scenic has a bug
  2. scenic --2d --model scenic.simulators.carla.model --simulate --count 1 --seed 12345 /home/user/carla-camera-placement/monolith/client/test_data/rag18.scenic -b
  3. Error log:
Using random seed = 12345
Beginning scenario construction...
/home/user/miniconda3/envs/carla-env/lib/python3.10/site-packages/pygame/pkgdata.py:25: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  from pkg_resources import resource_stream, resource_exists
pygame 2.6.1 (SDL 2.28.4, Python 3.10.19)
Hello from the pygame community. https://www.pygame.org/contribute.html
  Parsing OpenDRIVE file...
Traceback (most recent call last):
  File "/home/user/miniconda3/envs/carla-env/bin/scenic", line 3, in <module>
    from scenic.__main__ import dummy
  File "/home/user/Scenic_repo/src/scenic/__main__.py", line 195, in <module>
    scenario = errors.callBeginningScenicTrace(
  File "/home/user/Scenic_repo/src/scenic/core/errors.py", line 282, in callBeginningScenicTrace
    return func()
  File "/home/user/Scenic_repo/src/scenic/__main__.py", line 196, in <lambda>
    lambda: translator.scenarioFromFile(
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 138, in scenarioFromFile
    return _scenarioFromStream(
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 168, in _scenarioFromStream
    compileStream(stream, namespace, compileOptions, filename)
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 317, in compileStream
    executeCodeIn(code, namespace)
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 556, in executeCodeIn
    exec(code, namespace)
  File "/home/user/carla-camera-placement/monolith/client/test_data/rag18.scenic", line 1, in <module>
    """ TITLE: Nighttime Intersection Scenario
  File "/home/user/Scenic_repo/src/scenic/syntax/veneer.py", line 982, in model
    module = importlib.import_module(modelName)
  File "/home/user/miniconda3/envs/carla-env/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 394, in exec_module
    code, pythonSource = compileStream(
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 317, in compileStream
    executeCodeIn(code, namespace)
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 556, in executeCodeIn
    exec(code, namespace)
  File "/home/user/Scenic_repo/src/scenic/simulators/carla/model.scenic", line 45, in <module>
    from scenic.domains.driving.model import *
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 394, in exec_module
    code, pythonSource = compileStream(
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 317, in compileStream
    executeCodeIn(code, namespace)
  File "/home/user/Scenic_repo/src/scenic/syntax/translator.py", line 556, in executeCodeIn
    exec(code, namespace)
  File "/home/user/Scenic_repo/src/scenic/domains/driving/model.scenic", line 74, in <module>
    network : Network = Network.fromFile(globalParameters.map, **globalParameters.map_options)
  File "/home/user/Scenic_repo/src/scenic/domains/driving/roads.py", line 1078, in fromFile
    network = handlers[ext](path, **kwargs)
  File "/home/user/Scenic_repo/src/scenic/domains/driving/roads.py", line 1120, in fromOpenDrive
    road_map.parse(path)
  File "/home/user/Scenic_repo/src/scenic/formats/opendrive/xodr_parser.py", line 1489, in parse
    raise ValueError(
ValueError: planView of road 7 has inconsistent length
Image Image

Steps To Reproduce

  1. Scenic file:
""" TITLE: Nighttime Intersection Scenario 
AUTHOR: [Your Name], [Your Email] 
DESCRIPTION: 20 cars approach a 4-way intersection at night with a fixed camera.
"""

#################################
# MAP AND MODEL
#################################
param map = localPath('/home/user/CARLA/CarlaUE4/Content/Carla/Maps/OpenDrive/HQ.xodr')
param carla_map = 'HQ'
model scenic.simulators.carla.model
import carla

from utils.scenic_utils import get_lanes_within_distance

models_with_lights = [
    'vehicle.dodge.charger_police_2020',
    'vehicle.dodge.charger_2020',
    'vehicle.ford.crown',
    'vehicle.lincoln.mkz_2020',
    'vehicle.mercedes.coupe_2020',
    'vehicle.mini.cooper_s_2021',
    'vehicle.nissan.patrol_2021',
#    'vehicle.carlamotors.firetruck',
    'vehicle.ford.ambulance',
#    'vehicle.mercedes.sprinter',
    'vehicle.volkswagen.t2_2021',
#    'vehicle.mitsubishi.fusorosa'
]

#################################
# CONSTANTS
#################################
MODEL = 'vehicle.lincoln.mkz_2017'
TERM_TIME = 60

weather_params = {
    'cloudiness': Range(0, 100).sample(),
    'precipitation': Range(0, 100).sample(),
    'sun_altitude_angle': TruncatedNormal(-60, 30, -180, 10).sample(), # Night-time
    'fog_density': Range(0, 100).sample(),
    'wetness': Range(0, 100).sample()
}

param weather = weather_params

#################################
# AGENT BEHAVIORS
#################################
behavior EgoBehavior():
    # Ensure lights are on for night-time
    take SetVehicleLightStateAction(carla.VehicleLightState.All)
    do AutopilotBehavior(target_speed=Range(2, 5))

#################################
# SPATIAL RELATIONS
#################################
# 1. Sample a concrete intersection
# Note: filter returns a generator, so we convert to a list
# Filter for 4-way intersections where all incoming lanes are sufficiently long
intersections = list(filter(lambda i: (i.is4Way or i.is3Way) and any(s.isTrafficLight for s in i.signals), network.intersections))
# Use .sample() to get a concrete Intersection object immediately
intersection = Uniform(*intersections).sample()

# 2. Get the center point (as a concrete coordinate)
# Use the centroid of the intersection's polygon and convert to a Scenic Vector
from scenic.core.vectors import Vector
intersectionCenter = Vector(*intersection.polygon.centroid.coords[0])

cars = []
#################################
# SCENARIO SPECIFICATION
#################################
# Compute valid lanes once before the loop
valid_lanes = get_lanes_within_distance(intersection.incomingLanes, 100, network)

for _ in range(30):
    # Since intersection is a concrete object, we can access its incomingLanes list
    # Filter lanes to only include those that are long enough
    lane = Uniform(*valid_lanes)
    
    # Spawn vehicles 5-10 meters away from the intersection
    # We use 'at a distance' from the intersection center
    spawn_pt = new OrientedPoint on lane.centerline
    
    car = new Car at spawn_pt, 
              with color Color.defaultCarColor(),
              with blueprint Uniform(*models_with_lights),
              with behavior EgoBehavior()
    require (distance from car to intersection) >= 5.0
    # Add a requirement that this car is separated from all previously spawned cars
    for other_car in cars:
        require (distance from car to other_car) >= 8.0
    cars.append(car)

terminate after TERM_TIME seconds

#################################
# WRITE INTERSECTION POINT AS COLLISION_LOCATION YAML
#################################
# Use the intersection center as the "location" in the same format as
# incident_point_sampler output (e.g. 1.location.yaml) for downstream
# camera placement / SDG pipeline.
import yaml
_cx, _cy = intersection.polygon.centroid.coords[0]
_cy = -_cy
_z = 0.0  # 2D map; use 0 for z
_output = {
    'meta_data': {
        'actor_1_location_at_collision': {'x': _cx, 'y': _cy, 'z': _z},
        'actor_2_location_at_collision': {'x': _cx, 'y': _cy, 'z': _z},
        'distance': 20.0,
        'fov': 110,
        'height': 7.0,
        'location': {'x': _cx, 'y': _cy, 'z': _z},
        'number_of_cameras': 5,
        'sampler_type': 'uniform_sampler',
    }
}
with open(localPath('rag18.location.yaml'), 'w') as _f:
    yaml.dump(_output, _f, default_flow_style=False, sort_keys=False)

#################################
# WRITE WEATHER PARAMS IN A WEATHER JSON FILE
#################################
import json
with open(localPath('rag18.weather.json'), 'w') as _f:
    json.dump(weather_params, _f, sort_keys=False, indent=2)
  1. I can't attach the custom map; system wont let me do that. How can I communicate this?

Issue Submission Checklist

  • I am reporting an issue, not asking a question
  • I checked the open and closed issues, forum, etc. and have not found any solution
  • I have provided all necessary code, etc. to reproduce the issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: validIssue is valid and will be worked ontype: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions