next up previous index
Next: Using Arguments in Variable Up: Opus Variables Previous: Interaction Variables   Index


Versioning

Opus uses a mechanism of versioning of variables and attributes. Each variable/attribute is initialized with a version number 0. Any subsequent change of that variable/attribute increments the version number. This allow us to only recompute variables, if it is really needed. This means that if a computation is invoked (by e.g. compute_variables()), it is checked, if any of the version numbers of all dependent variables has changed since the last computation. The computation is performed only, if there was any change in the dependencies tree. The mechanism is described in Section 22.3.3 in more detail.

For example,

>>> households.get_version("income")
0
>>> res = interactions.compute_variables([
             "urbansim.household_x_gridcell.cost_times_income"])
>>> interactions.get_version("cost_times_income")
0
>>> households.modify_attribute(name="income", data=[14000], index=[9])
>>> households.get_version("income")
1
>>> res = interactions.compute_variables([
             "urbansim.household_x_gridcell.cost_times_income"])
urbansim.household_x_gridcell.cost_times_income.......................0.0 sec
>>> interactions.get_version("cost_times_income")
1

The first call of compute_variables() didn't perform the actual computation, because nothing has changed since our previous computation on page [*]. After we modify one element of the ``income'' attribute (note that ``income'' is a dependent variable of ``cost_times_income'' defined in the dependencies() method), the variable is recomputed and the version number is increased.


next up previous index
Next: Using Arguments in Variable Up: Opus Variables Previous: Interaction Variables   Index
info (at) urbansim.org