Inheritance |
|
You can use the methods on this object to query the graph structure and find work items.
Methods ¶
Static methods ¶
workItem(id)
→ pdg.WorkItem
Static method
Returns the work item with the specified unique id across all PDG graphs,
or None
if no item exists with the id.
Instance methods ¶
bindGlobalAttribute(attrib_name, work_item)
Binds an existing global attribute to the lifetime of the specified pdg.WorkItem instance.
boundAttributeWorkItem(attrib_name)
→ pdg.WorkItem
Returns the work item that the specified global attribute is bound to, or None
if the attribute does not exist or isn’t bound.
dependencyForKey(key)
→ pdg.Dependency
Returns an external dependency object for the specified key.
dependencyGraph(expand_partitions=False, scheduler=None)
→ tuple
of dict
Returns the entire static dependency graph, represented as a tuple containing a map of work item->dependencies, work item->dependents and a list of items currently ready to cook.
The expand_partitions
argument configures whether partitions should be
expanded into a flat dependency graph containing only regular work items, or
kept in the tuple.
If a pdg.SchedulerBase is passed in, it will be used to filter the dependency graph so that only work items that are processed by that scheduler are included.
dirty(remove_outputs)
Deletes all work items in the graph. If remove_outputs
is True
, the output files for the work items are deleted on disk.
It is invalid to dirty a graph while it is actively cooking.
nodePort(node_name, port_name)
→ pdg.Port
Looks up a port object using a node and port name.
nodePort(full_name)
→ pdg.Port
Loops up a port object using the concatenated node port name, with a dot
separator. For example, processor.command
.
nodes()
→ list
of pdg.Node
Returns the list of all nodes in the graph.
prepareDirty()
→ pdg.WorkItemDirty
Prepares a dirty of the grpahs’s work items, but does not apply the operation to the graph. Instead, the dirty operation is stored to a pdg.WorkItemDirty instance so that it can be applied to the graph at a later point.
workItemById(id)
→ pdg.WorkItem
Returns the work item with the specified unique id, or None
if no item
exists with that id.
workItemByName(name)
→ pdg.WorkItem
Returns the work item with the specified unique name, or None
if no item
exists with that name.
workItemsByIds(ids)
→ list
of pdg.WorkItem
Returns the list of work items with the specified unique ids.
Methods from pdg.AttributeOwner ¶
addAttrib(name, type:
pdg.attribType, overwrite=
pdg.attribOverwrite.Match, error_level=
pdg.attribErrorLevel.Error)
→ pdg.AttributeFile or pdg.AttributeFloat or pdg.AttributeInt or pdg.AttributePyObject or pdg.AttributeString
Adds an attribute with the specified name and type.
The optional overwrite
argument can be set to a value from the pdg.attribOverwrite enum to control what happens when the objectm already has an attribute with the same name
. By default, if the attribute already exists and has the same type, then the existing attribute is returned. If the attribute exists with a different type, then an exception is thrown. If overwrite
is set to pdg.attribOverwrite.Always the existing attribute will be removed and replace by one with the new type
.
The optional error_level
argument can be used to control how PDG handles failures. By default an exception is thrown with a message that describes the source of the failure. If the pdg.attribErrorLevel.Warn enum value is passed instead and this object is a work item, the error message will instead be added as a warning to the node that owns the work item. Finally, passing in pdg.attribErrorLevel.Quiet will suppress all error reporting. When the error level is set to a value other than Error
, the method will return None
if the attribute cannot be added.
attrib(name)
→ pdg.AttributeFile or pdg.AttributeFloat or pdg.AttributeInt or pdg.AttributePyObject or pdg.AttributeString
Returns the attribute with the specified name, or None
if no such attribute exists.
The attribute is one of the supported attribute types listed in pdg.attribType. You can also write the attribute as attrib_owner.attrib[name]
.
attribArray(name)
→ list
of int
, float
, str
or pdg.File
Returns the array stored on an attribute.
attribHash(include_internal=True, include_unowned=True, only_static=False)
→ int
Returns a hash value calculated based on all of attribute values. This can be useful to identify objects between cooks.
The include_internal
argument determines whether or not the hashing operation should include internal attributes defined by PDG itself, like item input/output files or the the command string.
If this is a work item, when the include_unowned
argument is False
the hashing operation will only consider attributes that were modified or added by the node that owns the work item. Otherwise, all attributes are considered.
If this is a work item, when the only_static
argument is True
the hashing operation will only consider attributes created when the work item was generated. Any attribute additions or modifications made while the work item was scheduled or cooked are not included in the hash.
attribMatch(pattern)
→ list
of str
Returns the list of attribute names from the that match the specified pdg.AttributePattern instance.
attribNames(type=pdg.attribType.Undefined)
→ list
of str
Returns the list of names for all attributes if type
is set to pdg.attribType.Undefined, otherwise returns the list of attribute names with the specified type.
attribValue(name, index=0)
→ int
, float
, str
or pdg.File
Returns the value of an attribute at the specified index. You can also write the attribute as attrib_owner[name][index]
.
attribValues(type=pdg.attribType.Undefined)
→ dict
of list
of int
, float
, and str
Returns a map of all attribute names to values if type
is set to pdg.attribType.Undefined, otherwise returns a map of names to values for all attributes of the specified type.
attribType(name)
→ pdg.attribType
Returns the type of attribute with the specified name, or pdg.attribType.Undefined
if no attribute with that name exists.
clearAttribs()
Clears and deletes all attributes.
dictAttribArray(name)
→ list
of pdg.Dictionary
Returns the dict attribute array.
dictAttribValue(name, index=0)
→ pdg.Dictionary
Returns the dict attribute value at the specified index.
eraseAttrib(name)
Erases an attribute with the specified name.
fileAttribArray(name)
→ list
of pdg.File
Returns the file attribute array.
fileAttribValue(name, index=0)
→ pdg.File
Returns the file attribute value at the specified index.
floatAttribArray(name)
→ list
of float
Returns the floating point attribute array.
floatAttribValue(name, index=0)
→ float
Returns the floating point attribute value at the specified index.
hasAttrib(name)
→ bool
Returns True
if this object has an attribute with the specified name.
intAttribArray(name)
→ list
of int
Returns the integer attribute array.
intAttribValue(name, index=0)
→ int
Returns the integer attribute value at the specified index.
loadAttributes(file_path, collision_strategy)
→ bool
Loads the attribute data from the specified JSON file into this object. The collision_strategy
should be one of the enum values from pdg.attribCollisionStrategy.
lockAttributes()
→ pdg.LockAttributesBlock
Locks this attributes using a context manager. For the duration of the context manager, it is safe to modify attributes without worry about other threads modifying them.
For example:
with attrib_owner.lockAttributes(): attrib_owner.setIntAttrib("example", 10)
Note
You should not call this method on work items from within a PDG node callback, such as onGenerate
or onPartition
. The node already ensures that the callback can safely access all of the work items.
numAttribs(type=pdg.attribType.Undefined)
→ int
Returns the total number of attributes in the map if type
is set to pdg.attribType.Undefined, otherwise returns the number of attributes of the specified type.
pyObjectAttribValue(name)
→ object
Returns the Python object stored on the specified attribute.
renameAttrib(src_name, dst_name, overwrite_existing=False)
→ bool
Renames the attribute with src_name
to dst_name
.
saveAttributes(file_path)
→ bool
Saves the attribute data stored on this object to the specified file path as JSON. If the file path ends in .gz
the file will be compressed using GZip, otherwise the file is saved as plain text JSON.
setAttribFlag(name, flag, value=True)
Sets or clears the pdg.attribFlag on the specified attribute.
setDictAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a dictionary attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFileAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a file attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setFloatAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets an float attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setIntAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets an integer attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setPyObjectAttrib(name, value, overwrite=
pdg.attribOverwrite.Match)
Sets a Python object attribute value. The attribute will increment the ref count on the object to ensure that it exists for the duration of the attribute itself.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
setStringAttrib(name, value, index=0, overwrite=
pdg.attribOverwrite.Match)
Sets a string attribute value at the specified index. If the attribute does not exist, then it is created.
The optional overwrite
argument determines what happens if an attribute already exists with the same name
, but a different type. See pdg.AttributeOwner.addAttrib for details.
stringAttribArray(name)
→ list
of str
Returns the string attribute array.
stringAttribValue(name, index=0)
→ str
Returns the string attribute value at the specified index.
timeDependentAttribs()
→ list
of str
Returns the list of attributes that are time dependent. This method is primarily used for work item that are in a batch with shared attributes on the batch parent.