BerkeleyLearnVerify / Scenic

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

model parameter in scenic.scenarioFromFile being ignored? #201

Closed ArikGuitarik closed 7 months ago

ArikGuitarik commented 7 months ago

Versions: Scenic 2.1.0, Python 3.10/3.11

I am trying to use scenic.scenarioFromFile(..., model=...), but it seems to ignore whatever I pass in for model.

Am I correct in the assumption that it should not matter whether I specify the world model within the scenario file or in the model parameter of scenarioFromFile?

Example:

> dummy_model.scenic
class Dummy:
    foo: str

> dummy_scenario_1.scenic
model dummy_model
ego = Dummy with foo "bar"

> dummy_script_1.py
from scenic import scenarioFromFile
scenarioFromFile("dummy_scenario_1.scenic")

> dummy_scenario_2.scenic
ego = Dummy with foo "bar"

> dummy_script_2.py
from scenic import scenarioFromFile
scenarioFromFile("dummy_scenario_2.scenic", model="dummy_model")

Running dummy_script_1.py succeeds, running dummy_script_2.py results in a ScenicSyntaxError.

Is there a problem with my code, with my expectation or with Scenic?

dfremont commented 7 months ago

Hello Arik, your assumption is almost right, but the model parameter to scenarioFromFile just overrides whatever is specified in the model statement in the scenario. The scenario itself needs to have a model statement to be overridden: otherwise Scenic would not know at which point the world model should be imported (which can matter because some world models require certain global parameters to have been specified before they are imported, in order to configure things like the map to use). We should improve our documentation for that!

Anyway, if you add a model statement to your scenario then it should work, and in fact it does work in Scenic 3 (with the syntax ported to Scenic 3), but unfortunately it hits a bug in Scenic 2. We can look into fixing that, but in the mean time you might consider porting to Scenic 3: that will bring various benefits such as a more informative error than the misleading ScenicSyntaxError you're currently getting.

(By the way: your definition of the property foo in the class Dummy doesn't do what you expect: it sets the default value of foo to the class str. Scenic differs from Python in this respect: the colon introduces a default value, not a type annotation.)

ArikGuitarik commented 7 months ago

Ah, I see! Thank you so much for the swift and helpful response :)