BerkeleyLearnVerify / Scenic

A compiler and scenario generator for the Scenic scenario description language.
https://scenic-lang.org/
Other
271 stars 93 forks source link

Cannot run two scenarios back to back #168

Closed abol-karimi closed 1 year ago

abol-karimi commented 1 year ago

Using Scenic's Python API, I cannot run a scenario immediately after another. For the second simulation, I get the following error:

  File "tests/scenic2/loop.py", line 28, in <module>
    res2 = simulate()
  File "tests/scenic2/loop.py", line 19, in simulate
    sim_result = simulator.simulate(
  File "/home/carla/Scenic/src/scenic/core/simulators.py", line 76, in simulate
    simulation.run(maxSteps)
  File "/home/carla/Scenic/src/scenic/core/simulators.py", line 216, in run
    raise InvalidScenarioError(f'agent {agent} tried incompatible '
scenic.core.errors.InvalidScenarioError: agent unnamed Car (139820564322960) tried incompatible  action(s) (<scenic.domains.driving.actions.RegulatedControlAction object at 0x7f2a8315ad60>,)

Platform:

Here is the loopy.py script:

#!/usr/bin/env python3.8
import scenic

seconds = 20
timestep = .05
render = False

def simulate(scenic_file):
    scenario = scenic.scenarioFromFile(
                    scenic_file,
                    params={'timestep': timestep,
                            'render': render,
                            },
                    cacheImports=False
                    )
    scene, _ = scenario.generate(maxIterations=1)
    simulator = scenario.getSimulator()
    sim_result = simulator.simulate(
                        scene,
                        maxSteps=int(seconds // timestep),
                        maxIterations=1,
                        raiseGuardViolations=True
                        ) 
    return sim_result

res1 = simulate('tests/scenic2/dynamic1.scenic')
res2 = simulate('tests/scenic2/dynamic2.scenic')

and the two scenic files dynamic1.scenic and dynamic2.scenic specify the same scenario:

param carla_map = 'Town05'
carla_map = globalParameters.carla_map
param map = f'/home/carla/CarlaUE4/Content/Carla/Maps/OpenDrive/{carla_map}.xodr'
model scenic.simulators.carla.model

p0 = network.intersections[0].incomingLanes[0].centerline.pointAlongBy(0)

ego = Car at p0, facing roadDirection,
  with behavior FollowLaneBehavior(4)
Eric-Vin commented 1 year ago

Hi Abolfazl,

That looks like one of the bugs in this issue, which was fixed in this PR. The good news is that the fix should have been backported to 2.x and made it into 2.1. Can you try updating to Version 2.1 of Scenic (which should be compatible with what you have right now) and see if that resolves the issue?

abol-karimi commented 1 year ago

Thanks for the quick reply! The minimal example above works fine with v2.1. However, my actual scenic code (which is a modular scenario) still triggers the same error.

Eric-Vin commented 1 year ago

Can you provide your code that reproduces it? Then we can investigate why things are still crashing.

abol-karimi commented 1 year ago

I see that scenic.simulators.carla.actions keeps a reference to scenic.simulators.carla.model in order to access the Vehicle and Pedestrian classes, which seems similar to the bug that was fixed.

dfremont commented 1 year ago

You're right, good catch! We'll think about how to fix this.

dfremont commented 1 year ago

@abol-karimi Hopefully this is now fixed in main; please give it a try and let us know.

abol-karimi commented 1 year ago

I applied your changes to v2.1.0 and it works, thank you!

I had tried porting my project to Scenic 3 but I noticed a significant slow down.

Eric-Vin commented 1 year ago

Glad to hear it's working now. We'll back-port the fix to 2.x!

How much of a slowdown are you experiencing? We're definitely trying to avoid a significant slowdown for 2.0 scenarios in Scenic 3.0. Could you share your scenario with us so that we can profile it and try to ameliorate the slowdown?

abol-karimi commented 1 year ago

That would be great! Since we want to publish the results, the code is in a private repository. I'll add you to the repo and will show you how to run it.

Eric-Vin commented 1 year ago

Sounds good! If you'd like you can email me at evin {at} ucsc.edu

Eric-Vin commented 1 year ago

The patch (and several others) have been back-ported to 2.x in this PR: https://github.com/BerkeleyLearnVerify/Scenic/pull/173 .

Please let me know if there's any other issues, but I'll go ahead and close the issue for now.