This module defines the FlowManager class.
Manages the flow of data products between ADMIT tasks.
The flow manager maintains the tree of ADMIT tasks (ATs) constituting a data flow. Tasks communicate through basic data products (BDPs) that flow between tasks, which combine and transform them into new BDPs according to their function. This class implements the bookkeeping to track task connections and inter-dependencies. A central concept is the task connection 4-tuple, (si, sp, di, dp), connecting a source task (ID si) output BDP (port sp) to a destination task (ID di) input BDP (port dp). The primary concern of the flow manager is to organize and maintain this connection information to permit efficient execution and modification of data flows.
Parameters: | connmap : triple-nested dictionary of 4-tuples, optional
bdpmap : dictionary of list of 2-tuples, optional
depsmap : dictionary of sets, optional
tasklevs : dictionary of int, optional
tasks : dictionary of task references, optional
|
---|
Notes
All internal state is kept up to date by add() and remove() so that it is valid at all times. Hence _connmap, _depsmap, etc. should never be modified by any other methods, either inside or outside of FlowManager (the leading underscore emphasizes this intent).
Attributes
_connmap | (triple-nested dictionary of 4-tuples) Organizes connection 4-tuples in a 3-level dictionary hierarchy; _connmap[si][di][dp] is a connection 4-tuple (si, sp, di, dp) connecting source task ID si, BDP output port sp, to destination task di, input dp. |
_bdpmap | (dictionary of list of 2-tuples) Relates BDP outputs from source tasks with the BDP inputs to connected destination tasks; _bdpmap[di] is a list of 2-tuples (si, sp), one for each BDP input port, describing the source of the corresponding BDP. |
_depsmap | (dictionary of sets) Maintains the task dependency levels needed by the run() method; _depsmap[level] is the set of task IDs residing at the dependency level. Lower level tasks must execute prior to higher level tasks to satisfy dependency requirements; tasks at the same level may be executed in any order (even concurrently). |
_tasklevs | (dictionary of int) Maintains task dependency information in a complementary (inverse) manner to _depsmap; _tasklevels[id] is the dependency level for task id. |
_tasks | (dictionary of task references) Holds references to all ADMIT tasks in the flow, keyed by task id; _tasks[id] is an ADMIT task reference. |
Methods
add(a[, stuples, dtuples]) | Appends or inserts an AT into the task flow. |
clone(id) | Clones the flow emanating from a given root task (included). |
downstream(id[, leaf]) | Determines the ATs downstream of a task (includes itself). |
dryrun() | Performs a dry run. |
has_task(id) | Checks whether a task exists in the flow. |
remove(id) | Removes an AT and its downstream tasks. |
replace(id, a[, stuples]) | Replaces one task with another, removing the original. |
run([dryrun]) | Executes the flow, but only tasks that are out of date. |
show() | Displays formatted internal FlowManager state. |
stale(id[, direct]) | Sets the stale flag of an AT and its downstream ATs. |
verify() | Verifies the internal state of the FlowManager. |
Appends or inserts an AT into the task flow.
Appending a task creates a new leaf—a task whose BDP outputs (if any) are not connected to any tasks; in this case, dtuples can be omitted. Insertion implies that one or more of the tasks’s outputs feeds back into the flow, in which case dtuples will be non-empty.
Parameters: | a : AT
stuples : list of 2-tuples, optional
dtuples : list of 4-tuples, optional
|
---|---|
Returns: | int
|
Notes
Usually all but the root task(s) will have a non-empty stuples list.
Clones the flow emanating from a given root task (included).
Creates an independent, parallel sub-flow duplicating the action of the original.
Parameters: | id : int
|
---|---|
Returns: | int
|
Determines the ATs downstream of a task (includes itself).
The downstream tasks constitute the sub-flow emanating from the specified root task (also considered part of the sub-flow).
Parameters: | id : int
leaf : set of int, optional
|
---|---|
Returns: | list
|
Notes
Recursion through task id is detected. This is used by add() to prevent the creation of cyclic flows.
Performs a dry run.
Dry runs provide a summary of which tasks are in the flow, which are stale (out-of-date), and the order in which they will be executed in a live run.
Returns: | None |
---|
Checks whether a task exists in the flow.
This method does not differentiate between current, stale or disabled tasks, merely whether a task with the specified ID is present in the flow.
Parameters: | id : int
|
---|---|
Returns: | bool
|
Removes an AT and its downstream tasks.
Deletes an entire sub-flow starting from the specified root task.
Parameters: | id : int
|
---|---|
Returns: | None |
Replaces one task with another, removing the original.
The replacement task must have the same output signature (i.e, produce the same types/number of output BDPs)—otherwise the existing task could not be removed—but stuples may be specified if the inputs differ.
Parameters: | id : int
a : AT
stuples : list of 2-tuples, optional
|
---|---|
Returns: | None |
Executes the flow, but only tasks that are out of date.
Runs all enabled tasks in the correct order, accounting for their inter-dependencies. This will reduce to a no-op for tasks whose outputs are up-to-date (not dependent on stale tasks).
Parameters: | dryrun : bool, optional
|
---|---|
Returns: | None |
Displays formatted internal FlowManager state.
Pretty-prints the current contents of the instance to the screen (standard output).
Returns: | None |
---|
Sets the stale flag of an AT and its downstream ATs.
Stale tasks will be re-run upon execution of the flow, updating their output BDPs in the process; tasks not so marked are skipped to minimize running time.
Parameters: | id : int
direct : bool, optional
|
---|---|
Returns: | None |
Verifies the internal state of the FlowManager.
Verification searches for internal inconsistencies in the flow bookkeeping, which to improve runtime efficiency is partially redundant.
Returns: | bool
|
---|