scenic.syntax.veneer¶
Python implementations of Scenic language constructs.
This module is automatically imported by all Scenic programs. In addition to defining the built-in functions, operators, specifiers, etc., it also stores global state such as the list of all created Scenic objects.
Summary of Module Members¶
Functions
The ‘ahead of X [by Y]’ polymorphic specifier. |
|
The ‘angle from <vector> to <vector>’ operator. |
|
The ‘angle to <vector>’ operator (using the position of ego as the reference). |
|
The ‘apparent heading of <oriented point> [from <vector>]’ operator. |
|
The ‘apparently facing <heading> [from <vector>]’ specifier. |
|
The ‘at <vector>’ specifier. |
|
The ‘back of <object>’ operator. |
|
The ‘back left of <object>’ operator. |
|
The ‘back right of <object>’ operator. |
|
The ‘behind X [by Y]’ polymorphic specifier. |
|
The ‘beyond X by Y [from Z]’ polymorphic specifier. |
|
The ‘X can see Y’ polymorphic operator. |
|
The ‘distance from <vector> [to <vector>]’ operator. |
|
The ‘facing X’ polymorphic specifier. |
|
The ‘facing toward <vector>’ specifier. |
|
The ‘<VectorField> at <vector>’ operator. |
|
The ‘follow <field> from <vector> for <number>’ operator. |
|
The ‘following F [from X] for D’ specifier. |
|
The ‘front of <object>’ operator. |
|
The ‘front left of <object>’ operator. |
|
The ‘front right of <object>’ operator. |
|
The ‘in/on <region>’ specifier. |
|
The ‘left of <object>’ operator. |
|
The ‘left of X [by Y]’ polymorphic specifier. |
|
The ‘X offset along H by Y’ polymorphic operator. |
|
The ‘offset along X by Y’ polymorphic specifier. |
|
The ‘offset by <vector>’ specifier. |
|
The ‘relative heading of <heading> [from <heading>]’ operator. |
|
The ‘relative position of <vector> [from <vector>]’ operator. |
|
The ‘X relative to Y’ polymorphic operator. |
|
The ‘right of <object>’ operator. |
|
The ‘right of X [by Y]’ polymorphic specifier. |
|
|
|
The ‘visible <region>’ operator. |
|
The ‘visible from <Point>’ specifier. |
|
The ‘visible’ specifier (equivalent to ‘visible from ego’). |
|
The ‘with <property> <value>’ specifier. |
|
|
Activate the veneer when beginning to compile a Scenic module. |
|
Whether a Region or distribution over Regions always provides an orientation. |
|
Deactivate the veneer after compiling a Scenic module. |
Function implementing loads and stores to the ‘ego’ pseudo-variable. |
|
|
Find all names the given lambda depends on, along with their current bindings. |
|
Are we in the middle of compiling a Scenic module? |
|
|
Function implementing the mutate statement. |
|
Function implementing the param statement. |
|
|
Register a parameter whose value is given by an external sampler. |
|
Add a Scenic object to the global list of created objects. |
Function implementing the require statement. |
|
The built-in resample function. |
|
Built-in function printing a message when the verbosity is >0. |
Member Details¶
-
class
Vector
(x, y)[source]¶ Bases:
scenic.core.distributions.Samplable
,collections.abc.Sequence
A 2D vector, whose coordinates can be distributions.
-
class
Region
(name, *dependencies, orientation=None)[source]¶ Bases:
scenic.core.distributions.Samplable
Abstract class for regions.
-
intersect
(other, triedReversed=False)[source]¶ Get a
Region
representing the intersection of this one with another.
-
static
uniformPointIn
(region)[source]¶ Get a uniform
Distribution
over points in aRegion
.
-
uniformPoint
()[source]¶ Sample a uniformly-random point in this
Region
.Can only be called on fixed Regions with no random parameters.
-
-
class
PointSetRegion
(name, points, kdTree=None, orientation=None, tolerance=1e-06)[source]¶ Bases:
scenic.core.regions.Region
Region consisting of a set of discrete points.
No
Object
can be contained in aPointSetRegion
, since the latter is discrete. (This may not be true for subclasses, e.g.GridRegion
.)- Parameters
name (str) – name for debugging
points (iterable) – set of points comprising the region
kdtree (
scipy.spatial.KDTree
, optional) – k-D tree for the points (one will be computed if none is provided)orientation (
VectorField
, optional) – orientation for the regiontolerance (float, optional) – distance tolerance for checking whether a point lies in the region
-
class
PolygonalRegion
(points=None, polygon=None, orientation=None)[source]¶ Bases:
scenic.core.regions.Region
Region given by one or more polygons (possibly with holes)
-
class
PolylineRegion
(points=None, polyline=None, orientation=True)[source]¶ Bases:
scenic.core.regions.Region
Region given by one or more polylines (chain of line segments)
-
class
Workspace
(region=<scenic.core.regions.AllRegion object>)[source]¶ Bases:
scenic.core.regions.Region
A workspace describing the fixed world of a scenario
-
class
Range
(low, high)[source]¶ Bases:
scenic.core.distributions.Distribution
Uniform distribution over a range
-
class
Options
(opts)[source]¶ Bases:
scenic.core.distributions.MultiplexerDistribution
Distribution over a finite list of options.
Specified by a dict giving probabilities; otherwise uniform over a given iterable.
-
class
Normal
(mean, stddev)[source]¶ Bases:
scenic.core.distributions.Distribution
Normal distribution
-
Discrete
¶ alias of
scenic.core.distributions.Options
-
class
VerifaiParameter
(domain)[source]¶ Bases:
scenic.core.external_params.ExternalParameter
An external parameter sampled using one of VerifAI’s samplers.
-
static
withPrior
(dist, buckets=None)[source]¶ Creates a
VerifaiParameter
using the given distribution as a prior.Since the VerifAI cross-entropy sampler currently only supports piecewise-constant distributions, if the prior is not of that form it may be approximated. For most built-in distributions, the approximation is exact: for a particular distribution, check its
bucket
method.
-
static
-
class
VerifaiRange
(low, high, buckets=None, weights=None)[source]¶ Bases:
scenic.core.external_params.VerifaiParameter
A
Range
(real interval) sampled by VerifAI.
-
class
VerifaiDiscreteRange
(low, high, weights=None)[source]¶ Bases:
scenic.core.external_params.VerifaiParameter
A
DiscreteRange
(integer interval) sampled by VerifAI.
-
class
VerifaiOptions
(opts)[source]¶ Bases:
scenic.core.distributions.Options
An
Options
(discrete set) sampled by VerifAI.
-
class
Mutator
[source]¶ Bases:
object
An object controlling how the
mutate
statement affects anObject
.A
Mutator
can be assigned to themutator
property of anObject
to control the effect of themutate
statement. When mutation is enabled for such an object using that statement, the mutator’sappliedTo
method is called to compute a mutated version.
-
class
Point
(*args, **kwargs)[source]¶ Bases:
scenic.core.object_types.Constructible
Implementation of the Scenic class
Point
.The default mutator for
Point
adds Gaussian noise toposition
with a standard deviation given by thepositionStdDev
property.- Attributes
-
class
OrientedPoint
(*args, **kwargs)[source]¶ Bases:
scenic.core.object_types.Point
Implementation of the Scenic class
OrientedPoint
.The default mutator for
OrientedPoint
adds Gaussian noise toheading
with a standard deviation given by theheadingStdDev
property, then applies the mutator forPoint
.- Attributes
heading (float) – Heading of the
OrientedPoint
. Default value 0 (North).viewAngle (float) – View cone angle for
can see
operator. Default value \(2\pi\).
-
class
Object
(*args, **kwargs)[source]¶ Bases:
scenic.core.object_types.OrientedPoint
,scenic.core.geometry.RotatedRectangle
Implementation of the Scenic class
Object
.- Attributes
width (float) – Width of the object, i.e. extent along its X axis. Default value 1.
height (float) – Height of the object, i.e. extent along its Y axis. Default value 1.
allowCollisions (bool) – Whether the object is allowed to intersect other objects. Default value
False
.requireVisible (bool) – Whether the object is required to be visible from the
ego
object. Default valueTrue
.regionContainedIn (
Region
orNone
) – ARegion
the object is required to be contained in. IfNone
, the object need only be contained in the scenario’s workspace.cameraOffset (
Vector
) – Position of the camera for thecan see
operator, relative to the object’sposition
. Default0 @ 0
.
-
class
PropertyDefault
(requiredProperties, attributes, value)[source]¶ Bases:
object
A default value, possibly with dependencies.
-
ego
(obj=None)[source]¶ Function implementing loads and stores to the ‘ego’ pseudo-variable.
The translator calls this with no arguments for loads, and with the source value for stores.
-
RelativeTo
(X, Y)[source]¶ The ‘X relative to Y’ polymorphic operator.
- Allowed forms:
F relative to G (with at least one a field, the other a field or heading) <vector> relative to <oriented point> (and vice versa) <vector> relative to <vector> <heading> relative to <heading>
-
OffsetAlong
(X, H, Y)[source]¶ The ‘X offset along H by Y’ polymorphic operator.
- Allowed forms:
<vector> offset along <heading> by <vector> <vector> offset along <field> by <vector>
-
RelativePosition
(X, Y=None)[source]¶ The ‘relative position of <vector> [from <vector>]’ operator.
If the ‘from <vector>’ is omitted, the position of ego is used.
-
RelativeHeading
(X, Y=None)[source]¶ The ‘relative heading of <heading> [from <heading>]’ operator.
If the ‘from <heading>’ is omitted, the heading of ego is used.
-
ApparentHeading
(X, Y=None)[source]¶ The ‘apparent heading of <oriented point> [from <vector>]’ operator.
If the ‘from <vector>’ is omitted, the position of ego is used.
-
DistanceFrom
(X, Y=None)[source]¶ The ‘distance from <vector> [to <vector>]’ operator.
If the ‘to <vector>’ is omitted, the position of ego is used.
-
CanSee
(X, Y)[source]¶ The ‘X can see Y’ polymorphic operator.
- Allowed forms:
<point> can see <object> <point> can see <vector>
-
With
(prop, val)[source]¶ The ‘with <property> <value>’ specifier.
Specifies the given property, with no dependencies.
-
In
(region)[source]¶ The ‘in/on <region>’ specifier.
Specifies ‘position’, with no dependencies. Optionally specifies ‘heading’ if the given Region has a preferred orientation.
-
Beyond
(pos, offset, fromPt=None)[source]¶ The ‘beyond X by Y [from Z]’ polymorphic specifier.
Specifies ‘position’, with no dependencies.
- Allowed forms:
beyond <vector> by <number> [from <vector>] beyond <vector> by <vector> [from <vector>]
If the ‘from <vector>’ is omitted, the position of ego is used.
-
VisibleFrom
(base)[source]¶ The ‘visible from <Point>’ specifier.
Specifies ‘position’, with no dependencies.
This uses the given object’s ‘visibleRegion’ property, and so correctly handles the view regions of Points, OrientedPoints, and Objects.
-
VisibleSpec
()[source]¶ The ‘visible’ specifier (equivalent to ‘visible from ego’).
Specifies ‘position’, with no dependencies.
-
OffsetBy
(offset)[source]¶ The ‘offset by <vector>’ specifier.
Specifies ‘position’, with no dependencies.
-
OffsetAlongSpec
(direction, offset)[source]¶ The ‘offset along X by Y’ polymorphic specifier.
Specifies ‘position’, with no dependencies.
- Allowed forms:
offset along <heading> by <vector> offset along <field> by <vector>
-
Facing
(heading)[source]¶ The ‘facing X’ polymorphic specifier.
- Specifies ‘heading’, with dependencies depending on the form:
facing <number> – no dependencies; facing <field> – depends on ‘position’.
-
FacingToward
(pos)[source]¶ The ‘facing toward <vector>’ specifier.
Specifies ‘heading’, depending on ‘position’.
-
ApparentlyFacing
(heading, fromPt=None)[source]¶ The ‘apparently facing <heading> [from <vector>]’ specifier.
Specifies ‘heading’, depending on ‘position’.
If the ‘from <vector>’ is omitted, the position of ego is used.
-
LeftSpec
(pos, dist=0)[source]¶ The ‘left of X [by Y]’ polymorphic specifier.
Specifies ‘position’, depending on ‘width’. See other dependencies below.
- Allowed forms:
left of <oriented point> [by <scalar/vector>] – optionally specifies ‘heading’; left of <vector> [by <scalar/vector>] – depends on ‘heading’.
If the ‘by <scalar/vector>’ is omitted, zero is used.
-
RightSpec
(pos, dist=0)[source]¶ The ‘right of X [by Y]’ polymorphic specifier.
Specifies ‘position’, depending on ‘width’. See other dependencies below.
- Allowed forms:
right of <oriented point> [by <scalar/vector>] – optionally specifies ‘heading’; right of <vector> [by <scalar/vector>] – depends on ‘heading’.
If the ‘by <scalar/vector>’ is omitted, zero is used.
-
Ahead
(pos, dist=0)[source]¶ The ‘ahead of X [by Y]’ polymorphic specifier.
Specifies ‘position’, depending on ‘height’. See other dependencies below.
Allowed forms:
ahead of
<oriented point> [by
<scalar/vector>] – optionally specifies ‘heading’;ahead of
<vector> [by
<scalar/vector>] – depends on ‘heading’.
If the ‘by <scalar/vector>’ is omitted, zero is used.
-
Behind
(pos, dist=0)[source]¶ The ‘behind X [by Y]’ polymorphic specifier.
Specifies ‘position’, depending on ‘height’. See other dependencies below.
- Allowed forms:
behind <oriented point> [by <scalar/vector>] – optionally specifies ‘heading’; behind <vector> [by <scalar/vector>] – depends on ‘heading’.
If the ‘by <scalar/vector>’ is omitted, zero is used.
-
Following
(field, dist, fromPt=None)[source]¶ The ‘following F [from X] for D’ specifier.
Specifies ‘position’, and optionally ‘heading’, with no dependencies.
- Allowed forms:
following <field> [from <vector>] for <number>
If the ‘from <vector>’ is omitted, the position of ego is used.
-
Front
(X)¶ The ‘front of <object>’ operator.
-
Back
(X)¶ The ‘back of <object>’ operator.
-
Left
(X)¶ The ‘left of <object>’ operator.
-
Right
(X)¶ The ‘right of <object>’ operator.
-
FrontLeft
(X)¶ The ‘front left of <object>’ operator.
-
FrontRight
(X)¶ The ‘front right of <object>’ operator.
-
BackLeft
(X)¶ The ‘back left of <object>’ operator.
-
BackRight
(X)¶ The ‘back right of <object>’ operator.