qoqo.CircuitDag
- class qoqo.CircuitDag(node_number=100, edge_number=300)
Represents the Direct Acyclic Graph (DAG) of a Circuit.
- __init__()
Methods
__init__
()add_to_back
(op)Add an Operation to the back of the CircuitDag, if necessary.
add_to_front
(op)Add an Operation to the front of the CircuitDag, if necessary.
blocking_predecessors
(already_executed, ...)Checks which of the direct predecessors of an Operation in the CircuitDag blocks the execution.
Returns the list of nodes of commuting operations in CircuitDag.
execution_blocked
(already_executed, ...)Checks if executing an operation is blocked by any not-yet executed operation.
Returns a dictionary where a key is composed by the name and the size of the classical register and its value represents the first node that involves that register.
Returns a dictionary where a key represents a qubit and its value represents the first node that involves that qubit.
Returns a set containing the nodes in the first parallel block.
from_bincode
(input)Convert the bincode representation of the CircuitDag to a CircuitDag using the [bincode] crate.
Create a CircuitDag from a given Circuit;
get
(index)Given a NodeIndex, returns the Operation contained in the node of the CircuitDag.
Returns a dictionary where a key is composed by the name and the size of the classical register and its value represents the last node that involves that register.
Returns a dictionary where a key represents a qubit and its value represents the last node that involves that qubit.
Returns a set containing the nodes in the last parallel block.
new_front_layer
(already_executed, ...)Returns a new front-layer after executing an operation from the current front layer.
Returns an iterator over the possible parallel blocks in circuit that can be executed simultaneously
successors
(node)Returns the list of the successors of a given node in the CircuitDag.
Return the bincode representation of the CircuitDag using the [bincode] crate.
Transforms the CircuitDag into a Circuit.
- add_to_back(op)
Add an Operation to the back of the CircuitDag, if necessary.
- Parameters:
op (Operation) -- The Operation to add to the back of the CircuitDag.
- Raises:
TypeError -- The Python Object cannot be converted to Operation.
- add_to_front(op)
Add an Operation to the front of the CircuitDag, if necessary.
- Parameters:
op (Operation) -- The Operation to add to the front of the CircuitDag.
- Raises:
TypeError -- The Python Object cannot be converted to Operation.
- blocking_predecessors(already_executed, to_be_executed)
Checks which of the direct predecessors of an Operation in the CircuitDag blocks the execution.
Warning: This method can only be used to determine if an operation can be executed when already_executed is consistent. When the list already_executed is inconsistent (a n operation is reported as executed that could not have been executed yet) this method returning an empty vector does not imply that the to_be_executed operation can be executed.
- Parameters:
already_executed (List[int]) -- List of NodeIndices of Nodes that have already been executed in the Circuit.
to_be_executed (int) -- NodeIndex of the Operation that should be executed next.
- Returns:
List containing the sorted blocking elements.
- Return type:
List[int]
- commuting_operations()
Returns the list of nodes of commuting operations in CircuitDag.
- Returns:
The list of nodes of commuting operations.
- Return type:
List[int]
- execution_blocked(already_executed, to_be_executed)
Checks if executing an operation is blocked by any not-yet executed operation.
- Parameters:
already_executed (List[int]) -- List of NodeIndices of Nodes that have already been executed in the Circuit.
to_be_executed (int) -- NodeIndex of the operation that should be executed next.
- Returns:
List containing the sorted blocking elements.
- Return type:
List[int]
- first_operation_involving_classical()
Returns a dictionary where a key is composed by the name and the size of the classical register and its value represents the first node that involves that register.
- Returns:
The dictionary of {(str, int), int} elements.
- Return type:
Dict[(str, int), int]
- first_operation_involving_qubit()
Returns a dictionary where a key represents a qubit and its value represents the first node that involves that qubit.
- Returns:
The dictionary of {qubit: node} elements.
- Return type:
Dict[int, int]
- first_parallel_block()
Returns a set containing the nodes in the first parallel block.
- Returns:
The set of nodes in the first parallel block.
- Return type:
Set[int]
- static from_bincode(input)
Convert the bincode representation of the CircuitDag to a CircuitDag using the [bincode] crate.
- Parameters:
input (ByteArray) -- The serialized CircuitDag (in [bincode] form).
- Returns:
The deserialized CircuitDag.
- Return type:
- Raises:
TypeError -- Input cannot be converted to byte array.
ValueError -- Input cannot be deserialized to CircuitDag.
- from_circuit()
Create a CircuitDag from a given Circuit;
- Parameters:
circuit (Circuit) -- The Circuit to build the new CircuitDag from.
- Returns:
The new CircuitDag.
- Return type:
self
- get(index)
Given a NodeIndex, returns the Operation contained in the node of the CircuitDag.
- Parameters:
index (int) -- The index of the node to get from the CircuitDag.
- Returns:
The Operation at the given index (if it exists).
- Return type:
Operation
- Raises:
IndexError -- Index out of range.
- last_operation_involving_classical()
Returns a dictionary where a key is composed by the name and the size of the classical register and its value represents the last node that involves that register.
- Returns:
The dictionary of {(str, int), int} elements.
- Return type:
Dict[(str, int), int]
- last_operation_involving_qubit()
Returns a dictionary where a key represents a qubit and its value represents the last node that involves that qubit.
- Returns:
The dictionary of {qubit: node} elements.
- Return type:
Dict[int, int]
- last_parallel_block()
Returns a set containing the nodes in the last parallel block.
- Returns:
The set of nodes in the last parallel block.
- Return type:
Set[int]
- new_front_layer(already_executed, current_front_layer, to_be_executed)
Returns a new front-layer after executing an operation from the current front layer.
Returns an error if operation to be executed is not in the current front layer.
- Parameters:
already_executed (List[int]) -- List of NodeIndices of Nodes that have already been executed in the Circuit.
current_front_layer (List[int]) -- List of NodeIndices in the current front layer ready to be executed if physically possible.
to_be_executed (int) -- NodeIndex of the operation that should be executed next.
- parallel_blocks()
Returns an iterator over the possible parallel blocks in circuit that can be executed simultaneously
Returns an Iterator over Vectors of references to the NodeIndices in the parallel block as well as references to the Operation in the blocks
- successors(node)
Returns the list of the successors of a given node in the CircuitDag.
- to_bincode()
Return the bincode representation of the CircuitDag using the [bincode] crate.
- Returns:
The serialized CircuitDag (in [bincode] form).
- Return type:
ByteArray
- Raises:
ValueError -- Cannot serialize CircuitDag to bytes.
- to_circuit()
Transforms the CircuitDag into a Circuit.