[PEAK] understanding the trellis code

P.J. Eby pje at telecommunity.com
Wed Jun 22 23:03:15 EDT 2011


At 11:36 PM 6/21/2011 +0200, nicky van foreest wrote:
>Hi,
>
>Some time ago I discovered Trellis to solve some of my problems with
>updating data in classes I use for simulations and numerical
>experiments. Now I would like to understand the Trellis code somewhat
>better, mostly out of curiosity and to improve my python skills. The
>code, however, is not particularly revealing, at least not for me.
>Does anybody have some tips where to begin? Otherwise, what algorithm
>is used to check and setup  the dependencies between the attributes?
>If I were to build this myself I think I would use some sort of
>dependency graph. But I cannot find this anywhere in the code.

The dependency graph is implemented via bidirectional linked lists 
between AbstractSubject and AbstractListener in peak.events.stm.

Both Subjects and Listeners can iterate their opposite ends, and a 
graph edge is created by simply invoking:

     Link(subject, listener)

The Link object is a weak reference to the listener (so that the link 
disappears if the listener is garbage collected) and holds a strong 
(normal) reference to the subject so the subject stays alive as long 
as listeners still exist.

A Trellis cell can be both a subject and a listener, thus making the 
graph transitive.  Cells also have a level attribute that indicates 
their distance from the graph roots.



More information about the PEAK mailing list