BerkeleyLearnVerify / Scenic

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

VerifaiRange sampling values far beyond range (Fixed with solution mentioned on Slack, posting for the record) #276

Closed Kai-X-Org closed 2 months ago

Kai-X-Org commented 4 months ago

System Details

1.Python 3.10.14 2.Scenic 3.0.0rc1, with latest pull of VerifAI 3.Ubuntu 20.04 on x86

  1. No simulator. Just Scenic

Detailed Description

  1. When sampling Scenic values using VerifaiRange, certain programs shows sampling far beyond range or just weird sampling behaviors.
  2. For instance, consider the following program
    
    param x1 = VerifaiRange(5, 6.5)
    param y1 = VerifaiRange(0, 1.5)
    param yaw1 = VerifaiRange(0, 180)

param x2 = VerifaiRange(5, 6.5) param y2 = VerifaiRange(0, 3) param yaw2 = VerifaiRange(0, 180)

param x3 = VerifaiRange(5, 6.5) param y3 = VerifaiRange(0, 3) param yaw3 = VerifaiRange(0, 180)

param x4 = VerifaiRange(-0.5, 1) param y4 = VerifaiRange(0, 0.5)

obj1 = new Object at (globalParameters.x1, globalParameters.y1, 0), with yaw globalParameters.yaw1, with shape SpheroidShape(dimensions=(0.5, 0.5, 0.5)), with color[0, 0, 0] obj1 = new Object at (globalParameters.x2, globalParameters.y2, 0), with yaw globalParameters.yaw2, with shape SpheroidShape(dimensions=(0.5, 0.5, 0.5)), with color[0.25, 0, 0] obj1 = new Object at (globalParameters.x3, globalParameters.y3, 0), with yaw globalParameters.yaw3, with shape SpheroidShape(dimensions=(0.5, 0.5, 0.5)), with color[0.5, 0, 0] obj1 = new Object at (globalParameters.x4, globalParameters.y4, 0), with shape SpheroidShape(dimensions=(0.5, 0.5, 0.5)), with color[0.75, 0, 0]


The sampled Scene using the Scenic GUI is shown in the first picture, where some objects are far out of range in position. Each object has radius 0.5m. The solution mentioned on Slack worked with changing the body of scenic.core.external_params.VerifaiSampler.valueFor to return getattr(self.cachedSample, f'param{param.index}')

<img width="1423" alt="Screenshot 2024-06-05 at 10 44 54" src="https://github.com/BerkeleyLearnVerify/Scenic/assets/70188506/9841be3c-8b0f-4484-a83a-50da549e58b5">

### Steps To Reproduce

1. Run the Scenic program shown above.

### Issue Submission Checklist

- [X] 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