scenic.core.lazy_eval

Support for lazy evaluation of expressions and specifiers.

Lazy evaluation is necessary for expressions like 30 deg relative to roadDirection where roadDirection is a vector field and so defines a different heading at different positions. Scenic defers evaluation of such expressions until they are used in the definition of an object, when the required context (here, a position) is available. This is implemented by representing lazy values as special objects which capture all operations applied to them (in a similar way to Distribution objects). The main class of such objects is DelayedArgument: in the above example, the relative to operator returns such an object. However, since lazy values can appear as arguments to distributions, Distribution objects can also require lazy evaluation (prior to sampling); therefore both of these classes derive from a common abstract class LazilyEvaluable.

Summary of Module Members

Functions

makeDelayedFunctionCall

Utility function for creating a lazily-evaluated function call.

makeDelayedOperatorHandler

needsLazyEvaluation

Whether the given value requires lazy evaluation.

requiredProperties

Set of properties needed to evaluate the given value, if any.

valueInContext

Evaluate something in the context of an object being constructed.

Classes

DelayedArgument

Specifier arguments requiring other properties to be evaluated first.

LazilyEvaluable

Values which may require evaluation in the context of an object being constructed.

Member Details

class LazilyEvaluable(requiredProps)[source]

Values which may require evaluation in the context of an object being constructed.

If a LazilyEvaluable specifies any properties it depends on, then it cannot be evaluated to a normal value except during the construction of an object which already has values for those properties.

Parameters

requiredProps – sequence of strings naming all properties which this value can depend on (formally, which must exist in the object passed as the context to evaluateIn).

Attributes

_requiredProperties – set of strings as above.

evaluateIn(context)[source]

Evaluate this value in the context of an object being constructed.

The object must define all of the properties on which this value depends.

evaluateInner(context)[source]

Actually evaluate in the given context, which provides all required properties.

Overridden by subclasses.

static makeContext(**props)[source]

Make a context with the given properties for testing purposes.

class DelayedArgument(requiredProps, value, _internal=False)[source]

Bases: scenic.core.lazy_eval.LazilyEvaluable

Specifier arguments requiring other properties to be evaluated first.

The value of a DelayedArgument is given by a function mapping the context (object under construction) to a value.

Note

When called from a dynamic behavior, constructors for delayed arguments return actual evaluations, not DelayedArgument objects. The agent running the behavior is used as the evaluation context.

Parameters
  • requiredProps – see LazilyEvaluable.

  • value – function taking a single argument (the context) and returning the corresponding evaluation of this object.

  • _internal (bool) – set to True for internal uses that need to suppress the exceptional handling of calls from dynamic behaviors above.

makeDelayedFunctionCall(func, args, kwargs)[source]

Utility function for creating a lazily-evaluated function call.

valueInContext(value, context)[source]

Evaluate something in the context of an object being constructed.

requiredProperties(thing)[source]

Set of properties needed to evaluate the given value, if any.

needsLazyEvaluation(thing)[source]

Whether the given value requires lazy evaluation.