BerkeleyLearnVerify / Scenic

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

[Using Scenic Programmatically] Example code NewtonianSimulator cannot find global parameters #47

Closed luigiberducci closed 2 years ago

luigiberducci commented 2 years ago

Hello everyone! I wanted to notify a problem experienced by running the 2nd example reported in the documentation. The example is reported here:

import scenic
from scenic.simulators.newtonian import NewtonianSimulator
scenario = scenic.scenarioFromFile('examples/driving/badlyParkedCarPullingIn.scenic',
                                   model='scenic.simulators.newtonian.model')
scene, _ = scenario.generate()
simulator = NewtonianSimulator()
simulation = simulator.simulate(scene, maxSteps=10)
if simulation:  # `simulate` can return None if simulation fails
        result = simulation.result
        for i, state in enumerate(result.trajectory):
                egoPos, parkedCarPos = state
                print(f'Time step {i}: ego at {egoPos}; parked car at {parkedCarPos}')

When running, the NewtonianSimulator is not able to find the global parameter "map" that is defined in the scenario file.

The complete error message follows:

Traceback (most recent call last):
  File "/home/luigi/anaconda3/lib/python3.8/code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "/home/luigi/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/213.7172.26/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/luigi/Development/ScenicOriginal/src/scenic/simulators/newtonian/__init__.py", line 17, in <module>
    from .simulator import NewtonianSimulator
  File "/home/luigi/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/213.7172.26/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/home/luigi/Development/ScenicOriginal/src/scenic/simulators/newtonian/simulator.py", line 15, in <module>
    import scenic.domains.driving.model as drivingModel
  File "/home/luigi/.local/share/JetBrains/Toolbox/apps/PyCharm-P/ch-0/213.7172.26/plugins/python/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/home/luigi/Development/ScenicOriginal/src/scenic/syntax/translator.py", line 719, in exec_module
    code, pythonSource = compileStream(stream, module.__dict__, filename=self.filepath)
  File "/home/luigi/Development/ScenicOriginal/src/scenic/syntax/translator.py", line 290, in compileStream
    executeCodeIn(code, namespace)
  File "/home/luigi/Development/ScenicOriginal/src/scenic/syntax/translator.py", line 2175, in executeCodeIn
    exec(code, namespace)
  File "/home/luigi/Development/ScenicOriginal/src/scenic/domains/driving/model.scenic", line 47, in <module>
    raise RuntimeError('need to specify map before importing driving model '
RuntimeError: need to specify map before importing driving model (set the global parameter "map")

It would be great to receive any feedback on how to fix this problem.

Thanks a lot! Luigi

dfremont commented 2 years ago

Hello Luigi,

Thanks for catching this! The example code is fine, but there was an internal issue in the Newtonian simulator which caused this counter-intuitive error message. I've pushed a quick fix, which works on my end -- please let me know if this solves the problem for you.

luigiberducci commented 2 years ago

Thanks a lot, Daniel. It works fine now!

abol-karimi commented 1 year ago

When I run the above script, I get this error:

ego = Car with behavior DriveAvoidingCollisions(avoidance_threshold=5)
          ^
ScenicSyntaxError: invalid syntax