Contains a simple but yet powerful dependency graph engine allowing computations to be organized more efficiently.
Iterator starting at rootPlugShell going “up”stream ( input ) or “down”stream ( output ) breadth first over plugs, applying filter functions as defined.
Parameters: |
|
---|
Bases: object
Simple class defining the type of a plug and several flags that affect it. Additionally it can determine how well suited another attribute is
Nodes are automatically computable if they are affected by another plug. If this is not the case, they are marked input only and are not computed. If this flag is true, even unaffeted plugs are computable. Plugs that affect something are automatically input plugs and will not be computed. If the plug does not affect anything and this flag is False, they are seen as input plugs anyway.
The system does not allow plugs to be input and output plugs at the same time, thus your compute cannot be triggered by your own compute
cls: if True, the plug requires classes to be set ( instances of ‘type’ ) , but no instances of these classes uncached: if False, computed values may be cached, otherwise they will always be recomputed. unconnectable: if True, the node cannot be the destination of a connection check_passing_values: check each value as it flows through a connection - usually compatability is only checked on connection and once values are set, but not if they flow through an existing connection
Compute affinity for otherattr.
Returns: | rating from 0 to 255 defining how good the attribtues match each other in general - how good can we store values of otherattr ? Thus this comparison is directed. |
---|---|
Note: | for checking connections, use connectionAffinity |
Compute value’s compatability rate
Returns: | value between 0 and 255, 0 means no compatability, 255 a perfect match. if larger than 0, the plug can hold the value ( assumed the flags are set correctly ). |
---|
Compute connection affinity for given destination attribute
Returns: | rating from 0 to 255 defining the quality of the connection to otherplug. an affinity of 0 mean connection is not possible, 255 mean the connection is perfectly suited. The connection is a directed one from self -> otherplug |
---|
Returns: | default value stored for this attribute, or raise |
---|---|
Note: | handles dynamic defaults, so you should not directly access the default member variable |
Raises MissingDefaultValueError: | |
if attribute does not have a default value | |
Raises TypeError: | |
if value returned by dynamic attribute has incorrect type |
Bases: networkx.classes.digraph.DiGraph, mrv.interface.iDuplicatable
Holds the nodes and their connections
Nodes are kept in a separate list whereas the plug connections are kept in the underlying DiGraph
Returns: | item with separator added to it ( just once ) |
---|---|
Note: | operates best on strings |
Parameters: |
|
Returns: | basename of this path, ‘/hello/world’ -> ‘world’ |
---|
Returns: | list of intermediate children of path, [ child1 , child2 ] |
---|---|
Parameter: | predicate – return True to include x in result |
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Returns: | list of all children of path, [ child1 , child2 ] |
---|---|
Parameters: |
|
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Connect this plug to destinationshell such that destinationshell is an input plug for our output
Parameters: |
|
---|---|
Returns: | self on success, allows chained connections |
Raises PlugAlreadyConnected: | |
if destinationshell is connected and force is False |
|
Raises PlugIncompatible: | |
if destinationshell does not appear to be compatible to this one |
Copy the values of ourselves onto the given instance which must be an instance of our class to be compatible. Only the common classes will be copied to instance
Returns: | altered instance |
---|---|
Note: | instance will be altered during the process |
Implements a c-style copy constructor by creating a new instance of self and applying the copyFrom methods from base to all classes implementing the copyfrom method. Thus we will call the method directly on the class
Parameters: |
|
---|
Returns: | True if the node is in this graph, false otherwise |
---|
Returns: | the connected input plug of plugshell or None if there is no such connection |
---|---|
Note: | input plugs have on plug at most, output plugs can have more than one connected plug |
Returns: | True if self is a part of other, and thus can be found in other |
---|---|
Note: | operates on strings only |
Returns: | True if this path is the root of the DAG |
---|
Returns: | True other starts with self |
---|---|
Note: | operates on strings |
Note: | we assume other has the same type as self, thus the same separator |
Returns: | generator returning all nodes that are connected in this graph, in no particular order. For an ordered itereration, use iterShells. |
---|---|
Parameter: | predicate – if True for node, it will be returned |
Returns: | generator returning all nodes in this graph |
---|---|
Parameter: | predicate – if True for node, it will be returned |
Note: | there is no particular order |
Returns: | generator retrieving all parents up to the root |
---|---|
Parameter: | predicate – returns True for all x that you want to be returned |
Returns: | instance of a node according to the given node id |
---|---|
Raises NameError: | |
if no such node exists in graph |
Returns: | immutable copy of the nodes used in the graph |
---|
Returns: | number of nodes in the graph |
---|
Returns: | a list of plugs being the destination of the connection to plugshell |
---|---|
Parameter: | predicate – plug will only be returned if predicate is true for it - shells will be passed in |
Returns: | parent of this path, ‘/hello/world’ -> ‘/hello’ or None if this path is the dag’s root |
---|
Returns: | all parents of this path, ‘/hello/my/world’ -> [ ‘/hello/my’,’/hello’ ] |
---|
Returns: | the root of the DAG - it has no further parents |
---|
Returns: | True if this instance supports the interface of the given type |
---|---|
Parameter: | interface_type – Type of the interface you require this instance to support |
Note: | Must be used in case you only have a weak reference of your interface instance or proxy which is a case where the ordinary isinstance( obj, iInterface ) will not work |
Bases: mrv.interface.iDuplicatable
Base class that provides support for plugs to the superclass. It will create some simple tracking attriubtes required for the plug system to work
Nodes can compute values of their plugs if these do not have a cache.
Nodes are identified by an ID - the default graph implementation though will be okay with just having instances. It is also being used for string representations of this node
Returns: | item with separator added to it ( just once ) |
---|---|
Note: | operates best on strings |
Parameters: |
|
Returns: | basename of this path, ‘/hello/world’ -> ‘world’ |
---|
Returns: | list of intermediate children of path, [ child1 , child2 ] |
---|---|
Parameter: | predicate – return True to include x in result |
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Returns: | list of all children of path, [ child1 , child2 ] |
---|---|
Parameters: |
|
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Called whenever a plug needs computation as the value its value is not cached or marked dirty ( as one of the inputs changed )
Parameters: |
|
---|---|
Note: | to be implemented by superclass |
Returns: | Tuples of input shells defining a connection of the given type from tuple( InputNodeOuptutShell, OurNodeInputShell ) for input connections and tuple( OurNodeOuptutShell, OutputNodeInputShell ) |
---|---|
Parameters: |
|
Just take the graph from other, but do not ( never ) duplicate it
Parameter: | add_to_graph – if true, the new node instance will be added to the graph of |
---|---|
Note: | default implementation does not copy plug caches ( which are stored in the node dict - this is because a reevaluate is usually required on the duplicated node |
Copy the values of ourselves onto the given instance which must be an instance of our class to be compatible. Only the common classes will be copied to instance
Returns: | altered instance |
---|---|
Note: | instance will be altered during the process |
Create a copy of self and return it
Note: | override by subclass - the __init__ methods shuld do the rest |
---|
Implements a c-style copy constructor by creating a new instance of self and applying the copyFrom methods from base to all classes implementing the copyfrom method. Thus we will call the method directly on the class
Parameters: |
|
---|
Returns: | sorted list of (rate,plug) tuples suitable to deal with the given attribute. Thus they could connect to it as well as get their value set. Most suitable plug comes first. Incompatible plugs will be pruned. |
---|---|
Parameters: |
|
Raises TypeError: | |
if ambiguous input was found |
Returns: | ID of this instance |
---|
Returns: | list of plugs suitable as input |
---|---|
Note: | convenience method |
Returns: | list of static plugs suitable as input |
---|---|
Note: | convenience method |
Returns: | True if self is a part of other, and thus can be found in other |
---|---|
Note: | operates on strings only |
Returns: | True if this path is the root of the DAG |
---|
Returns: | True other starts with self |
---|---|
Note: | operates on strings |
Note: | we assume other has the same type as self, thus the same separator |
Returns: | generator retrieving all parents up to the root |
---|---|
Parameter: | predicate – returns True for all x that you want to be returned |
Returns: | list of plugs suitable to deliver output |
---|---|
Note: | convenience method |
Returns: | list of static plugs suitable to deliver output |
---|---|
Note: | convenience method |
Returns: | parent of this path, ‘/hello/world’ -> ‘/hello’ or None if this path is the dag’s root |
---|
Returns: | all parents of this path, ‘/hello/my/world’ -> [ ‘/hello/my’,’/hello’ ] |
---|
Returns: | list of dynamic plugs as defined on this node - they are usually retrieved on class level, but may be overridden on instance level |
---|---|
Parameter: | predicate – return static plug only if predicate is true |
Returns: | list of static plugs as defined on this node - they are class members |
---|---|
Parameter: | predicate – return static plug only if predicate is true |
Note: | Use this method only if you do not have an instance - there are nodes that actually have no static plug information, but will dynamically generate them. For this to work, they need an instance - thus the plugs method is an instance method and is meant to be the most commonly used one. |
Returns: | the root of the DAG - it has no further parents |
---|
Returns: | True if this instance supports the interface of the given type |
---|---|
Parameter: | interface_type – Type of the interface you require this instance to support |
Note: | Must be used in case you only have a weak reference of your interface instance or proxy which is a case where the ordinary isinstance( obj, iInterface ) will not work |
Returns: | a plugshell as suitable to for this class |
---|
Returns: | list of shells made from plugs and our node |
---|
Epydoc: mrv.dge._NodeBaseCheckMeta
Bases: type
Class checking the consistency of the nodebase class before it is being created
Bases: tuple
Handles per-node-instance plug connection setup and storage. As plugs are descriptors and thus an instance of the class, per-node-instance information needs special treatment. This class is being returned whenever the descriptors get and set methods are called, it contains information about the node and the plug being involved, allowing to track connection info directly using the node dict
This allows plugs to be connected, and information to flow through the dependency graph. Plugs never act alone since they always belong to a parent node that will be asked for value computations if the value is not yet cached. :note: Do not instantiate this class youself, it must be created by the node as different node types can use different versions of this shell
Returns: | the cached value or raise |
---|---|
Raises ValueError: | |
Compute compatability rate for teh given value
Returns: | value between 0 and 255, 0 means no compatability, 255 a perfect match if larger than 0, the plug can hold the value ( assumed the flags are set correctly ) |
---|
Connect this plug to otherplugshell such that otherplugshell is an input plug for our output
Parameter: | kwargs – everything supported by Graph.connect |
---|---|
Returns: | self on success, allows chained connections |
Raises PlugAlreadyConnected: | |
if otherplugshell is connected and force is False | |
Raises PlugIncompatible: | |
if otherplugshell does not appear to be compatible to this one |
Returns: | get all input and or output connections from this shell or to this shell as edges ( sourceshell, destinationshell ) |
---|---|
Parameter: | predicate – return true for each destination shell that you can except in the returned edge or the sourceshell where your shell is the destination. |
Note: | Use this method to get edges read for connection/disconnection |
Returns: | value of the plug |
---|---|
Parameter: | mode – optional arbitary value specifying the mode of the get attempt |
Returns: | True if currently store a cached value |
---|
Returns: | the connected input plug or None if there is no such connection |
---|---|
Parameter: | predicate – plug will only be returned if predicate is true for it |
Note: | input plugs have on plug at most, output plugs can have more than one connected plug |
Returns: | True, if the shell is connected as source or as destination of a connection |
---|
Returns: | a list of plugs being the destination of the connection |
---|---|
Parameter: | predicate – plug will only be returned if predicate is true for it - shells will be passed in |
Bases: object
deque(iterable[, maxlen]) –> deque object
Build an ordered collection accessible from endpoints only.
Bases: mrv.interface.Interface
Simple interface allowing any class to be properly duplicated
Note: | to implement this interface, implement createInstance and copyFrom in your class |
---|
Returns: | item with separator added to it ( just once ) |
---|---|
Note: | operates best on strings |
Parameters: |
|
Returns: | basename of this path, ‘/hello/world’ -> ‘world’ |
---|
Returns: | list of intermediate children of path, [ child1 , child2 ] |
---|---|
Parameter: | predicate – return True to include x in result |
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Returns: | list of all children of path, [ child1 , child2 ] |
---|---|
Parameters: |
|
Note: | the child objects returned are supposed to be valid paths, not just relative paths |
Copy the data from other into self as good as possible Only copy the data that is unique to your specific class - the data of other classes will be taken care of by them !
Note: | you must support args and kwargs if one of your iDuplicate bases does |
---|
Copy the values of ourselves onto the given instance which must be an instance of our class to be compatible. Only the common classes will be copied to instance
Returns: | altered instance |
---|---|
Note: | instance will be altered during the process |
Create and Initialize an instance of self.__class__( ... ) based on your own data
Returns: | new instance of self |
---|---|
Note: | using self.__class__ instead of an explicit class allows derived classes that do not have anything to duplicate just to use your implementeation |
Note: | you must support args and kwargs if one of your iDuplicate bases does |
Implements a c-style copy constructor by creating a new instance of self and applying the copyFrom methods from base to all classes implementing the copyfrom method. Thus we will call the method directly on the class
Parameters: |
|
---|
Returns: | True if self is a part of other, and thus can be found in other |
---|---|
Note: | operates on strings only |
Returns: | True if this path is the root of the DAG |
---|
Returns: | True other starts with self |
---|---|
Note: | operates on strings |
Note: | we assume other has the same type as self, thus the same separator |
Returns: | generator retrieving all parents up to the root |
---|---|
Parameter: | predicate – returns True for all x that you want to be returned |
Returns: | parent of this path, ‘/hello/world’ -> ‘/hello’ or None if this path is the dag’s root |
---|
Returns: | all parents of this path, ‘/hello/my/world’ -> [ ‘/hello/my’,’/hello’ ] |
---|
Returns: | the root of the DAG - it has no further parents |
---|
Returns: | True if this instance supports the interface of the given type |
---|---|
Parameter: | interface_type – Type of the interface you require this instance to support |
Note: | Must be used in case you only have a weak reference of your interface instance or proxy which is a case where the ordinary isinstance( obj, iInterface ) will not work |
Bases: object
Defines an interface allowing to compare compatabilies according to types.
Plugs can either be input plugs or output plugs - output plugs affect no other plug on a node, but are affected by 0 or more plugs .
By convention, a plug has a name - that name must also be the name of the member attribute that stores the plag. Plugs, possibly different instances of it, need to be re-retrieved on freshly duplicated nodes to allow graph duplication to be done properly
Note: | if your plug class supports the setName method, a metaclass will adjust the name of your plug to match the name it has in the parent class |
---|
Returns: | tuple containing affected plugs ( plugs that are affected by our value ) |
---|
Returns: | tuple containing plugs that affect us ( plugs affecting our value ) |
---|
Returns: | name of the plug ( the name that identifies it on the node |
---|
Returns: | True if this is an input plug that will never cause computations |
---|
Returns: | True if this is an output plug that can trigger computations |
---|
Bases: mrv.dge.iPlug
Defines an interface allowing to compare compatabilies according to types.
Plugs are implemented as descriptors, thus they will be defined on node class level, and all static information will remain static
As descriptors, they are defined statically on the class, and some additional information such as connectivity, is stored on the respective class instance. These special methods are handled using NodeBase class
Plugs are implemented as descriptors as all type information can be kept per class, whereas only connection information changes per node instance.
Plugs can either be input plugs or output plugs - output plugs affect no other plug on a node, but are affected by 0 or more plugs
Note: | class is lowercase as it is used as descriptor ( acting more like a function ) |
---|
Returns: | tuple containing affected plugs ( plugs that are affected by our value ) |
---|
Returns: | tuple containing plugs that affect us ( plugs affecting our value ) |
---|
Returns: | name of plug |
---|
Returns: | True if this is an input plug that will never cause computations |
---|
Returns: | True if this is an output plug that can trigger computations |
---|
Bases: exceptions.Exception
Base class for all errors indicating invalid access
Bases: exceptions.Exception
Thrown if the computation done by a plug failed by an unknown exception It will be passed on in the exception
Bases: mrv.dge.ComputeError
Raised by the derived class computing a value if the computational goal cannot be achieved ( anymore )
Epydoc: mrv.dge.ConnectionError
Bases: exceptions.Exception
Exception base for all plug related errors
Epydoc: mrv.dge.MissingDefaultValueError
Bases: mrv.dge.AccessError
Thrown if a default value is missing for input attributes that are not connected
Epydoc: mrv.dge.NotReadableError
Bases: mrv.dge.AccessError
Thrown if a non-readable attribute is being read
Epydoc: mrv.dge.NotWritableError
Bases: mrv.dge.AccessError
Thrown if a non-writable plug is being written to
Epydoc: mrv.dge.PlugAlreadyConnected
Bases: mrv.dge.ConnectionError
Thrown if one tries to connect a plug to otherplug when otherplug is already connected
Epydoc: mrv.dge.PlugIncompatible
Bases: mrv.dge.ConnectionError, exceptions.TypeError
Thrown whenever plugs are not compatible with each other during connection
Bases: mrv.dge.ComputeError
Raised if a plug was not handled by the node’s compute method