Inheritance |
|
This object contains a reference to the graph and methods for running, pausing, canceling, etc. the work in the graph.
Warning
Do not use mutating methods, such as adding/removing nodes or setting parameter values, on a graph produced by a TOP network. The TOP network expects to manage the graph itself.
Methods ¶
Static methods ¶
byName(name)
→ pdg.GraphContext
Static method
Looks up a graph context object by name.
findFile(path)
→ str
Static method
Find a file on the PDG search path and returns the absolute path to that file.
globFiles(ext, subdir)
→ list
of str
Static method
Finds all files on the PDG search path with the specified extension, in the specified subdirectory.
globTypeFiles()
→ list
of str
Static method
Returns the list of all .py files on the search path.
names()
→ list
of str
Static method
Returns the names of all active graph contexts.
searchPath()
→ list
of str
Static method
Returns the list of paths on the PDG search path.
Instance methods ¶
__init__(name="context")
Constructs a new graph context. If name is not specified, the default name “context” is used instead. The name is automatically made unique.
In TOPs, the graph context associated with a TOP network has the same name as the network object.
addDependency(type_name, node_name, dep_key)
Constructs an instance of the specified external dependency type and assigns it to the node.
addFileDependency(node_name, file_name)
Constructs a file dependency on the specified file name and assigns it to the node.
addNode(type_name, node_name="")
→ pdg.Node
Constructs a node of the specified type and adds it to the graph. If the
node_name
argument is not specified, the node’s name will be derived from
the type name.
addScheduler(type_name, scheduler_name="")
→ pdg.SchedulerBase
Constructs a scheduler of the specified type and adds it to the graph. If
the scheduler_name
argument is not specified, the scheduler’s name will be
derived from the type name.
addParameter(node_name, port_name, port_label, port_tag, data_type, port_size)
Adds a custom parameter to a node. The tags
argument can be either a
single str
value or a list
of str
values and data_type
should be a
pdg.dataType. All other arguments should be strings.
cancelCook()
Cancels the current cook.
cleanTempDirectory(scheduler_name)
Cleans the temp file directory for the specified scheduler.
cookItems(block, item_ids, node_name)
Cooks the specified work item ids from the node with the name node_name
. If block
is True
the method will wait and return after the cook completes. Otherwise the method returns immediately with the cook operation running in the background.
cook(cook_options)
Cooks the graph context using the specified pdg.CookOptions.
cook(block, mode=pdg.cookType.Full, name="", ids=pdg.Filter())
Cooks the graph using individually specified cook parameters. See pdg.CookOptions for a description of the parameters.
connect(src_node_name, src_port_name, dst_node_name, dst_port_name)
Connects a output port on the source node to an input port on the destination node.
connect(src_name, dst_name)
Connects a output port on the source node to an input port on the destination
node. Ports are specified using the nodename.portname
syntax.
delete(node_name)
Deletes a node from the graph.
deserializeWorkItemFromJSON(json_text)
→ pdg.WorkItem
Loads a work item from the standard PDG JSON format.
disconnect(src_node_name, src_port_name, dst_node_name, dst_port_name)
Disconnects a output port on the source node from an input port on the destination node.
disconnect(src_name, dst_name)
Disconnects a output port on the source node from an input port on the
destination node. Ports are specified using the nodename.portname
syntax.
memoryUsage()
→ pdg.MemoryInfo
Queries memory usage of the graph and the nodes/work items inside it.
pauseCook()
Pauses the cook. Processes that have begun cooking will continue to cook, but no new jobs will be sent to schedulers. Work items and nodes can be dirtied during this time, and on the next cook the graph will resume with the changes made.
Note
This is currently only supported using the Local Scheduler.
removeDependency(node_name, dep_name)
Removes an external dependency from a node.
renameNode(old_name, new_name)
Renames an node from old_name
to new_name
.
saveJSON(file_path, pretty_print=True, skip_defaults=true)
Saves a JSON representation of the nodes, parameters and connections in the
graph to the specified file_path
.
If pretty_print
is True
, the resulting JSON file is formatted in a
human-readable way, with indentations and newlines. Otherwise, the file has
minimal whitespace and formatting characters.
If skip_defaults
is True
, parameters that are at their default value
will be skipped. Otherwise, if skip_defaults
is False
, all node
parameters will be written to the file even if they're set to the default
value for that node.
schedulerForName(scheduler_name)
→ pdg.SchedulerBase
Looks up a scheduler by name.
serializeWorkItemToJSON(work_item, pretty_print=False)
→ str
Serializes the specified work item, its data and its inputs to a .json
file. If pretty_print
is True
, the .json file is written out in a human-
readable format with indentation.
setDefaultScheduler(scheduler_name)
Sets the graph context’s default scheduler
setExpression(node_name, port_name, expression, index)
Sets a Python expression on a node’s parameter.
setExpressions(node_name, dict)
Batch sets multiple port_name:expression pairs on the specified node.
setParameter(node_name, port_name, value, index)
Sets a constant value on a node’s parameter to the specified value. If the parameter is numeric and the value is a string, the parameter’s expression is set instead.
setParameters(node_name, dict)
Batch sets multiple parameter:value pairs on the specified node. If the parameter is numeric and the value is a string, the paremter’s expression is set instead.
setScheduler(node_name, scheduler_name)
Sets a node’s scheduler
setValue(node_name, port_name, value, index)
Sets a constant value on a node’s parameter.
setValues(node_name, dict)
Batch sets multiple port_name:value pairs on the specified node.
canceling
: bool
Property
Set to True
when the current cook is being canceled.
cookOptions
: pdg.CookOptions
Property
The last set of cook options used to cook this graph.
cookSet
: list
of pdg.Node
Property
The nodes involved in the current cook.
cooking
: bool
Property
Set to True
when the graph context is cooking.
defaultScheduler
: pdg.SchedulerBase
Property
The default scheduler for the graph context.
graph
: pdg.Graph
Property
The node graph owned by the graph context.
name
: str
Property
The name of the context.
schedulers
: list
of pdg.SchedulerBase
Property
The list of schedulers available in the context.
waitAllEvents()
Waits event queue to emit all queued events.
Methods from pdg.EventEmitter ¶
addEventHandler(handler, filter=pdg.EventType.All, pass_handler=False)
→ pdg.PyEventHandler
Adds an event handler to the emitter, with a value of the type of event to receive. The handler
should be a callable that accepts one argument of type pdg.Event.
If pass_handler
is True, the handler itself is passed as the first argument to
the function, otherwise only the event object is passed to the function.
hasEventHandler(handler)
→ bool
Returns True
if the event emitter already has an event handler that uses the handler
function or callback object.
removeEventHandler(handler)
Removes an event handler from the emitter.
removeAllEventHandlers()
Removes all event handlers from the emitter.
eventHandlers
→ list
of pdg.EventHandler
Property
Returns the list of all active event handles for the emitter.
supportedEventTypes
→ list
of `pdg.EventType
Property
The list of event types that this event emitter may produce when PDG is cooking