Package param :: Class Dynamic
[hide private]
[frames] | no frames]

Class Dynamic

source code


Parameter whose value can be generated dynamically by a callable object.

If a Parameter is declared as Dynamic, it can be set a callable object (such as a function or callable class), and getting the parameter's value will call that callable.

Note that at present, the callable object must allow attributes to be set on itself.

[Python 2.4 limitation: the callable object must be an instance of a callable class, rather than a named function or a lambda function, otherwise the object will not be picklable or deepcopyable.]

Setting Dynamic.time_fn allows the production of dynamic values to be controlled: a new value will be produced only if the current value of time_fn is greater than what it was last time the parameter value was requested.

If time_fn is set to None, a new value is always produced.

If Dynamic.time_fn is set to something other than None, it must, when called, produce a number.

Nested Classes [hide private]

Inherited from parameterized.Parameter: __metaclass__

Instance Methods [hide private]
 
time_fn()
Return the current simulation time as a FixedPoint object.
source code
 
__init__(self, **params)
Call the superclass's __init__ and set instantiate=True if the default is dynamic.
source code
 
_initialize_generator(self, gen, obj=None)
Add 'last time' and 'last value' attributes to the generator.
source code
 
__get__(self, obj, objtype)
Call the superclass's __get__; if the result is not dynamic return that result, otherwise ask that result to produce a value and return it.
source code
 
__set__(self, obj, val)
Call the superclass's set and keep this parameter's instantiate value up to date (dynamic parameters must be instantiated).
source code
 
_produce_value(self, gen, force=False)
Return a value from gen.
source code
 
_value_is_dynamic(self, obj, objtype=None)
Return True if the parameter is actually dynamic (i.e.
source code
 
_inspect(self, obj, objtype=None)
Return the last generated value for this parameter.
source code
 
_force(self, obj, objtype=None)
Force a new value to be generated, and return it.
source code

Inherited from parameterized.Parameter: __delete__, __getstate__, __setstate__

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  __classdoc = '\n Parameter whose value can be generated dyn...
str(object) -> string
Properties [hide private]

Inherited from parameterized.Parameter: constant, default, doc, instantiate, pickle_default_value, precedence, readonly

Inherited from object: __class__

Method Details [hide private]

time_fn()

source code 

Return the current simulation time as a FixedPoint object.

If the time returned will be used in the computation of a floating point variable, it should be cast into a floating point number by float().

__init__(self, **params)
(Constructor)

source code 
Call the superclass's __init__ and set instantiate=True if the default is dynamic.
Overrides: object.__init__

__get__(self, obj, objtype)

source code 
Call the superclass's __get__; if the result is not dynamic return that result, otherwise ask that result to produce a value and return it.
Overrides: parameterized.Parameter.__get__

__set__(self, obj, val)

source code 

Call the superclass's set and keep this parameter's instantiate value up to date (dynamic parameters must be instantiated).

If val is dynamic, initialize it as a generator.

Overrides: parameterized.Parameter.__set__

_produce_value(self, gen, force=False)

source code 

Return a value from gen.

If there is no time_fn, then a new value will be returned (i.e. gen will be asked to produce a new value).

If force is True, or the value of time_fn() is greater than what it was was last time produce_value was called, a new value will be produced and returned. Otherwise, the last value gen produced will be returned.

_value_is_dynamic(self, obj, objtype=None)

source code 
Return True if the parameter is actually dynamic (i.e. the value is being generated).

Class Variable Details [hide private]

__classdoc

str(object) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

Value:
'''
    Parameter whose value can be generated dynamically by a callable
    object.
    
    If a Parameter is declared as Dynamic, it can be set a callable
    object (such as a function or callable class), and getting the
    parameter\'s value will call that callable.

...