Esempio n. 1
0
def param(*quotedParams, **params):
    """Function implementing the param statement."""
    if evaluatingRequirement:
        raise RuntimeParseError(
            'tried to create a global parameter inside a requirement')
    for name, value in params.items():
        globalParameters[name] = toDistribution(value)
    assert len(quotedParams) % 2 == 0, quotedParams
    it = iter(quotedParams)
    for name, value in zip(it, it):
        globalParameters[name] = toDistribution(value)
Esempio n. 2
0
def param(*quotedParams, **params):
	"""Function implementing the param statement."""
	global loadingModel
	if evaluatingRequirement:
		raise RuntimeParseError('tried to create a global parameter inside a requirement')
	elif currentSimulation is not None:
		raise RuntimeParseError('tried to create a global parameter during a simulation')
	for name, value in params.items():
		if name not in lockedParameters and (not loadingModel or name not in _globalParameters):
			_globalParameters[name] = toDistribution(value)
	assert len(quotedParams) % 2 == 0, quotedParams
	it = iter(quotedParams)
	for name, value in zip(it, it):
		if name not in lockedParameters:
			_globalParameters[name] = toDistribution(value)
Esempio n. 3
0
def param(**params):
    """Function implementing the param statement."""
    if evaluatingRequirement:
        raise RuntimeParseError(
            'tried to create a global parameter inside a requirement')
    for name, value in params.items():
        globalParameters[name] = toDistribution(value)
Esempio n. 4
0
 def applyTo(self, obj, optionals):
     """Apply specifier to an object, including the specified optional properties."""
     val = self.value.evaluateIn(obj)
     val = toDistribution(val)
     assert not needsLazyEvaluation(val)
     obj._specify(self.property, val)
     for opt in optionals:
         assert opt in self.optionals
         obj._specify(opt, getattr(val, opt))
Esempio n. 5
0
    def __init__(self, *args, **kwargs):
        self.args = tuple(toDistribution(arg) for arg in args)
        self.kwargs = {
            name: toDistribution(arg)
            for name, arg in kwargs.items()
        }
        if not inspect.isgeneratorfunction(self.makeGenerator):
            raise RuntimeParseError(
                f'{self} does not take any actions'
                ' (perhaps you forgot to use "take" or "do"?)')

        # Validate arguments to the behavior
        sig = inspect.signature(self.makeGenerator)
        try:
            sig.bind(None, *args, **kwargs)
        except TypeError as e:
            raise RuntimeParseError(str(e)) from e
        Samplable.__init__(self,
                           itertools.chain(self.args, self.kwargs.values()))
        Invocable.__init__(self)
Esempio n. 6
0
 def uniformColor():
     """Return a uniformly random color."""
     return toDistribution(CarColor(Range(0, 1), Range(0, 1), Range(0, 1)))
Esempio n. 7
0
def param(**params):
	for name, value in params.items():
		globalParameters[name] = toDistribution(value)
Esempio n. 8
0
	def uniformColor():
		return toDistribution(CarColor(Range(0, 1), Range(0, 1), Range(0, 1)))