qermit.taskgraph¶
- class qermit.taskgraph.task_graph.TaskGraph(_label='TaskGraph')[source]¶
The TaskGraph class stores a networkx graph where vertices are pure functions or tasks, and edges hold data. In the TaskGraph class these tasks and edges have no type restrictions, though for the run method to be succesful, the types of ports edges are attached to must match.
- Parameters:
_label (
str
) – Name for identification of TaskGraph object.
- __call__(input_wires)[source]¶
Call self as a function.
- Return type:
Tuple
[List
[Union
[CircuitShots
,Circuit
,BackendResult
,ResultHandle
,AnsatzCircuit
,ObservableExperiment
,int
,float
,bool
,str
,QubitPauliOperator
,Dict
[Qubit
,Bit
],Dict
]]]
- __weakref__¶
list of weak references to the object (if defined)
- add_n_wires(num_wires)[source]¶
Adds num_wires number of edges between the input vertex and output vertex, with no type restrictions.
- Parameters:
num_wires (
int
) – Number of edges to add between input and output vertices.
- append(task)[source]¶
Inserts new task to end of TaskGraph._task_graph. All in edges to Output vertex are wired as in edges to task in same port ordering (types must match). New edges added from task to Output vertex (any type permitted), ports ordered in arguments order.
- check_append_wires(task)[source]¶
Confirms that the number of in wires of the proposed task to append to the internal task_graph attribute matches the number of out wires to the graph.
- check_prepend_wires(task)[source]¶
Confirms that the number of out wires of the proposed task to prepend to the internal task_graph attribute matches the number of in wires to the graph.
- decompose_TaskGraph_nodes()[source]¶
For each node in self._task_graph, if node is a TaskGraph object, substitutes that node with the _task_graph structure held inside the node.
- from_TaskGraph(task_graph)[source]¶
Returns a new TaskGraph object from another TaskGraph object.
- Parameters:
task_graph (
TaskGraph
) – TaskGraph object to copy tasks from.- Returns:
Copied TaskGraph
- get_cache()[source]¶
- Return type:
OrderedDict
[str
,Tuple
[MitTask
,List
[Union
[CircuitShots
,Circuit
,BackendResult
,ResultHandle
,AnsatzCircuit
,ObservableExperiment
,int
,float
,bool
,str
,QubitPauliOperator
,Dict
[Qubit
,Bit
],Dict
]]]]- Returns:
Dictionary holding all output data from all MitTask. This is only full after run is called with the cache argument set to True. Keys are stored in graph topological order.
- get_task_graph()[source]¶
Return a visual representation of the DAG as a graphviz object.
- Return type:
Digraph
- Returns:
Representation of the DAG
- property n_in_wires: int¶
The number of in wires to a TaskGraph object is defined as the number of out edges from the Input Vertex, as when called, a TaskGraph object calls the run method which stores input arguments as data on Input vertex output edges.
- property n_out_wires: int¶
The number of out wires to a TaskGraph object is defined as the number of in edges to the Input Vertex, as when called, a TaskGraph object calls the run method which after running all tasks, returns the data on input edges to the Output Vertex as a tuple.
- parallel(task)[source]¶
Adds new MitTask/TaskGraph to TaskGraph object in parallel. All task in edges wired as out edges from Input vertex. All task out_Edges wired as in edges to Output Vertex.
- prepend(task)[source]¶
Inserts new task to the start of TaskGraph._task_graph. All out edges from the Input vertex are wired as out edges from the task in the same port ordering (types must match). New edges also added from the Input vertex to the task (any type permitted), ports ordered in arguments order.
- run(input_wires, cache=False, characterisation={})[source]¶
Each task in TaskGraph is a pure function that produces output data from input data to some specification. Data is stored on edges of the internal _task_graph object. The run method first assigns each wire in the list to an output edge of the input vertex. If more wires are passed than there are edges, wire information is not assigned to some edge. If less wires are passed then there are edges, some edges will have no data and later computation will likely fail. Nodes (holding either MitTask or TaskGraph callable objects) on the graph undergo a topological sort to order them, and are then executed sequentially. To be executed, data from in edges to a task are passed arguments to the tasks _method, and data returned from method are assigned to out edges from a task. This process is repeated until all tasks are run, at which point all in edges to the output vertex wil have data on, with each data set returned in a tuple.
- Parameters:
input_wires (
List
[Union
[CircuitShots
,Circuit
,BackendResult
,ResultHandle
,AnsatzCircuit
,ObservableExperiment
,int
,float
,bool
,str
,QubitPauliOperator
,Dict
[Qubit
,Bit
],Dict
]]) – Each Wire holds information assigned as data to an output edge from the input vertex of the _task_graph.cache (
bool
) – If True each Tasks output data is stored in an OrderedDict with the Task._label attribute as its key.
- Return type:
Tuple
[List
[Union
[CircuitShots
,Circuit
,BackendResult
,ResultHandle
,AnsatzCircuit
,ObservableExperiment
,int
,float
,bool
,str
,QubitPauliOperator
,Dict
[Qubit
,Bit
],Dict
]]]- Returns:
Data from input edges to output vertex, assigned as wires.