Package cells :: Module cell :: Class Cell
[hide private]
[frames] | no frames]

Class Cell
source code

object --+
         |
        Cell
Known Subclasses:
RuleCell, InputCell, RuleThenInputCell, synapse.Synapse

The base Cell class. Does everything interesting.

Instance Methods [hide private]
  __init__(self, owner, name=None, rule=None, value=None, unchanged_if=None)
Initializes a Cell object.
  get(self, init=False)
Returns this cell's up-to-date value.
  set(self, value)
Sets this cell's value and begins propogation of the change, if neccessary.
  update(self, queryer=None)
Updates this cell to the current global DP (datapulse), returning True if it changed, False otherwise.
  propogate(self, propogate_first=None)
Propogates an update command to the set of cells which call this cell.
  run(self)
Runs the backing function (rule) for this cell.
  changed(self)
Did this cell's value change in this DP (datapulse)?
  calls_list(self)
Returns a generator of cell objects whose rules call this cell
  called_by_list(self)
Returns a generator of cell objects which this cell's rule calls
  propogation_list(self, elide=None)
Returns a generator of cell objects which this cell should propogate to, minus any cell passed in elide.
  add_calls(self, *calls_cells)
Appends the passed list of cells to this cell's calls list
  add_called_by(self, *cb_cells)
Appends the passed list of cells to this cell's called-by list
  remove_cb(self, *cb_cells)
Removes the passed list of cells from this cell's called-by list
  reset_calls(self)
Resets the calls list to empty

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


Class Variables [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, owner, name=None, rule=None, value=None, unchanged_if=None)
(Constructor)

source code 
Initializes a Cell object. You must not specify both rule and value.
Parameters:
  • name - This cell's name. When using a Cell with Models, this parameter is assigned automatically.
  • rule - Define a rule which backs this cell. You must only define one of rule or value. Lacking celltype, this creates a RuleCell. This must be passed a callable with the signature f(self, prev) -> value, where self is the model instance the cell is in and prev is the cell's out-of-date value.
  • value - Define a value for this cell. You must only define one of rule or value. Lacking celltype, this creates an InputCell.
  • unchanged_if - Sets a function to determine if a cell's value has changed. For example,
    >>> class A(cells.Model):
    ...     x = cells.makecell(value=1,
    ...                        unchanged_if=lambda n,o:abs(n-o)>5)
    ...     y = cells.makecell(rule=lambda s,p: s.x * 2)
    ... 
    >>> a = A()
    >>> a.x
    1
    
    >>> a.y
    2
    
    >>> a.x = 3
    >>> a.x
    3
    
    >>> a.y
    6
    
    >>> a.x = 90
    >>> a.x
    3
    
    >>> a.y
    6
    The signature for the passed function is f(old, new) -> bool.
Returns:
None

Raises:
  • RuleAndValueInitError - If both rule and value are passed, raise an exception
Overrides: object.__init__

get(self, init=False)

source code 
Returns this cell's up-to-date value.
Returns:
value

set(self, value)

source code 
Sets this cell's value and begins propogation of the change, if neccessary.
Parameters:
  • value - The value to set this cell's value to.
Returns:
None

update(self, queryer=None)

source code 
Updates this cell to the current global DP (datapulse), returning True if it changed, False otherwise.
Parameters:
  • queryer - The cell to propogate to first, if neccessary
Returns:
bool

propogate(self, propogate_first=None)

source code 
Propogates an update command to the set of cells which call this cell.
Parameters:
  • propogate_first - If cell A asks cell B to update, and cell B's value changes (causing a propogate call), it must propogate to A first, before any of the other cells which call B.
Returns:
None

run(self)

source code 
Runs the backing function (rule) for this cell. The sequence is:
  1. Remove this cell from all other cell's called-by sets
  2. Empty this cell's calls set.
  3. Run the function, which as a side effect may add this cell to other cells' called-by sets and add links in this cell's calls set
  4. If this cell's value changes,

    4.1 Run any observers in this cell's Model

    4.2 Return True
Returns:
bool

changed(self)

source code 
Did this cell's value change in this DP (datapulse)?
Returns:
bool

calls_list(self)

source code 
Returns a generator of cell objects whose rules call this cell
Returns:
generator

called_by_list(self)

source code 
Returns a generator of cell objects which this cell's rule calls
Returns:
generator

propogation_list(self, elide=None)

source code 
Returns a generator of cell objects which this cell should propogate to, minus any cell passed in elide.
Parameters:
  • elide - Remove a cell from the list of cells to propogate a change to. Used by propogate to remove a cell it had to propogate to first.
Returns:
generator

add_calls(self, *calls_cells)

source code 
Appends the passed list of cells to this cell's calls list

add_called_by(self, *cb_cells)

source code 
Appends the passed list of cells to this cell's called-by list

remove_cb(self, *cb_cells)

source code 
Removes the passed list of cells from this cell's called-by list

reset_calls(self)

source code 
Resets the calls list to empty