Struct roqoqo::CircuitDag
source · pub struct CircuitDag {
pub(crate) graph: Graph<Operation, (), Directed, usize>,
pub(crate) commuting_operations: Vec<NodeIndex<usize>>,
pub(crate) first_parallel_block: HashSet<NodeIndex<usize>>,
pub(crate) last_parallel_block: HashSet<NodeIndex<usize>>,
pub(crate) first_all: Option<NodeIndex<usize>>,
pub(crate) last_all: Option<NodeIndex<usize>>,
pub(crate) first_operation_involving_qubit: HashMap<usize, NodeIndex<usize>>,
pub(crate) last_operation_involving_qubit: HashMap<usize, NodeIndex<usize>>,
pub(crate) first_operation_involving_classical: HashMap<(String, usize), NodeIndex<usize>>,
pub(crate) last_operation_involving_classical: HashMap<(String, usize), NodeIndex<usize>>,
_roqoqo_version: RoqoqoVersion,
}
Expand description
Represents the Direct Acyclic Graph (DAG) of a Circuit.
The order of execution of the operations contained in a quantum circuit matters. A CircuitDag instance of a roqoqo’s Circuit shows the dependency of all the operations in the circuit.
For CircuitDag, the following functions are defined:
with_capacity(node_number, edge_number)
: creates an empty CircuitDag with estimated capacityadd_to_back(operation)
: adds an Operation to the back of the CircuitDagadd_to_front(operation)
: adds an Operation to the front of the CircuitDagexecution_blocked(already_executed_indices, index)
: returns the blocking elements of the execution of an Operation, the scope is just the whole graphblocking_predecessors(already_executed_indices, index)
: returns the blocking elements of the execution of an Operation, the scope is just the Operation’s predecessorsnew_front_layer(already_executed_indices, front_layer_indices, index)
: given an Operation index, computes a new front layer when considering that Operation as executedparallel_blocks()
: returns an iterator over the possible parallel blocks in circuit that can be executed simultaneouslysuccessors(index)
: returns an iterator over all successors in the CircuitDag of a given nodecommuting_operators()
: returns a reference to the vector of commuting operations in CircuitDagfirst_parallel_block()
: returns a reference to the HashSet containing the nodes in the first parallel blocklast_parallel_block()
: returns a reference to the HashSet containing the nodes in the last parallel blockfirst_operation_involving_qubit()
: returns a reference to the HashMap where a key represents a qubit and its value represents the first node that involves that qubitlast_operation_involving_qubit()
: returns a reference to the HashMap where a key represents a qubit and its value represents the last node that involves that qubitfirst_operation_involving_classical()
: returns a reference to the HashMap 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 registerlast_operation_involving_classical()
: returns a reference to the HashMap 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 registerget(index)
: returns a reference to the Operation contained in the indexed CircuitDag’s node
Note: operations PragmaStartDecompositionBlock and PragmaStopDecompositionBlock are considered part of the graph.
Fields§
§graph: Graph<Operation, (), Directed, usize>
§commuting_operations: Vec<NodeIndex<usize>>
§first_parallel_block: HashSet<NodeIndex<usize>>
§last_parallel_block: HashSet<NodeIndex<usize>>
§first_all: Option<NodeIndex<usize>>
§last_all: Option<NodeIndex<usize>>
§first_operation_involving_qubit: HashMap<usize, NodeIndex<usize>>
§last_operation_involving_qubit: HashMap<usize, NodeIndex<usize>>
§first_operation_involving_classical: HashMap<(String, usize), NodeIndex<usize>>
§last_operation_involving_classical: HashMap<(String, usize), NodeIndex<usize>>
§_roqoqo_version: RoqoqoVersion
Implementations§
source§impl CircuitDag
impl CircuitDag
sourcepub fn with_capacity(node_number: usize, edge_number: usize) -> Self
pub fn with_capacity(node_number: usize, edge_number: usize) -> Self
Creates a new empty CircuitDag.
sourcepub fn add_to_back(&mut self, operation: Operation) -> Option<usize>
pub fn add_to_back(&mut self, operation: Operation) -> Option<usize>
sourcefn add_to_back_involved(&mut self, node: NodeIndex<usize>)
fn add_to_back_involved(&mut self, node: NodeIndex<usize>)
Adds an operation that involves some or all qubits to the end of the CircuitDag.
§Arguments
- ‘node’ - The NodeIndex
of the node to add to the end of the CircuitDag.
sourcefn update_from_qubit_back(&mut self, node: NodeIndex<usize>, qubit: usize)
fn update_from_qubit_back(&mut self, node: NodeIndex<usize>, qubit: usize)
Updates the relevant attributes and the graph of CircuitDag from a single qubit involved in an Operation added to the back of the CircuitDag.
§Arguments
- ‘node’ - The index of the node whose Operation involves the qubit.
- ‘qubit’ - The qubit involved in the Operation.
sourcefn update_from_all_operation_back(&mut self, node: NodeIndex<usize>)
fn update_from_all_operation_back(&mut self, node: NodeIndex<usize>)
Updates the relevant attributes and the graph of CircuitDag when an Operation that involves all qubits is added to the back.
§Arguments
- ‘node’ - The index of the node whose Operation involves all qubits.
sourcepub fn add_to_front(&mut self, operation: Operation) -> Option<usize>
pub fn add_to_front(&mut self, operation: Operation) -> Option<usize>
sourcefn add_to_front_involved(&mut self, node: NodeIndex<usize>)
fn add_to_front_involved(&mut self, node: NodeIndex<usize>)
Adds an operation that involves some or all qubits to the front of the CircuitDag.
§Arguments
- ‘node’ - The NodeIndex
of the node to add to the end of the CircuitDag.
sourcefn update_from_qubit_front(&mut self, node: NodeIndex<usize>, qubit: usize)
fn update_from_qubit_front(&mut self, node: NodeIndex<usize>, qubit: usize)
Updates the relevant attributes and the graph of CircuitDag from a single qubit involved in an Operation added to the front of the CircuitDag.
§Arguments
- ‘node’ - The index of the node whose Operation involves the qubit.
- ‘qubit’ - The qubit involved in the Operation.
sourcefn update_from_all_operation_front(&mut self, node: NodeIndex<usize>)
fn update_from_all_operation_front(&mut self, node: NodeIndex<usize>)
Updates the relevant attributes and the graph of CircuitDag when an Operation that involves all qubits is added to the front.
§Arguments
- ‘node’ - The index of the node whose Operation involves all qubits.
sourcefn is_definition_classical_populate(
&mut self,
node: NodeIndex<usize>,
operation: Operation
) -> bool
fn is_definition_classical_populate( &mut self, node: NodeIndex<usize>, operation: Operation ) -> bool
Given an Operation and its node, checks that it is a Definition and populates the classical layer accordingly.
§Arguments
- ‘node’ - The index of the node of the Operation.
- ‘operation’ - The Operation itself.
sourcefn update_classical_back(
&mut self,
node: NodeIndex<usize>,
operation: Operation
)
fn update_classical_back( &mut self, node: NodeIndex<usize>, operation: Operation )
Checks and updates the relevant classical registers attributes from a given Operation that was added to the back of the graph.
§Arguments
- ‘node’ - The index of the node of the Operation that was added to the back of the graph.
- ‘operation’ - The Operation that was added to the back of the graph.
sourcefn update_classical_front(
&mut self,
node: NodeIndex<usize>,
operation: Operation
)
fn update_classical_front( &mut self, node: NodeIndex<usize>, operation: Operation )
Checks and updates the relevant classical registers attributes from a given Operation that was added to the front of the graph.
§Arguments
- ‘node’ - The index of the node of the Operation that was added to the front of the graph.
- ‘operation’ - The Operation that was added to the front of the graph.
sourcepub fn execution_blocked(
&self,
already_executed: &[NodeIndex<usize>],
to_be_executed: &NodeIndex<usize>
) -> Vec<NodeIndex<usize>>
pub fn execution_blocked( &self, already_executed: &[NodeIndex<usize>], to_be_executed: &NodeIndex<usize> ) -> Vec<NodeIndex<usize>>
Checks if executing an Operation is blocked by any previous not-yet executed Operation. The scope of the check is the whole graph.
§Arguments:
already_executed
- Slice of NodeIndices of Nodes that have already been executed in the Circuit.to_be_executed
- NodeIndex of the Operation that should be executed next.
§Returns:
Vec<NodeIndex<usize>>
- Vector containing the sorted blocking elements.
sourcepub fn blocking_predecessors(
&self,
already_executed: &[NodeIndex<usize>],
to_be_executed: &NodeIndex<usize>
) -> Vec<NodeIndex<usize>>
pub fn blocking_predecessors( &self, already_executed: &[NodeIndex<usize>], to_be_executed: &NodeIndex<usize> ) -> Vec<NodeIndex<usize>>
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 (an 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.
§Arguments:
already_executed
- Slice of NodeIndices of Nodes that have already been executed in the Circuit.to_be_executed
- NodeIndex of the Operation that should be executed next.
sourcepub fn new_front_layer(
&self,
already_executed: &[NodeIndex<usize>],
current_front_layer: &[NodeIndex<usize>],
to_be_executed: &NodeIndex<usize>
) -> Result<Vec<NodeIndex<usize>>, RoqoqoError>
pub fn new_front_layer( &self, already_executed: &[NodeIndex<usize>], current_front_layer: &[NodeIndex<usize>], to_be_executed: &NodeIndex<usize> ) -> Result<Vec<NodeIndex<usize>>, RoqoqoError>
Returns a new front layer after executing an operation from the current front layer. A front layer is a set of Operations that are ready to be executed, because all required predecessors in the graph have already been executed.
Returns an error if operation to be executed is not in the current front layer.
§Arguments:
already_executed
- Slice of NodeIndices of Nodes that have already been executed in the Circuit.current_front_layer
- Slice of NodeIndices in the current front layer ready to be executed if physically possible.to_be_executed
- NodeIndex of the operation that should be executed next.
sourcepub fn parallel_blocks(&self) -> ParallelBlocks<'_> ⓘ
pub fn parallel_blocks(&self) -> ParallelBlocks<'_> ⓘ
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
sourcepub fn successors(&self, node: NodeIndex<usize>) -> Neighbors<'_, (), usize>
pub fn successors(&self, node: NodeIndex<usize>) -> Neighbors<'_, (), usize>
Returns an iterator over all successors in the CircuitDag of a given node.
sourcepub fn commuting_operations(&self) -> &Vec<usize>
pub fn commuting_operations(&self) -> &Vec<usize>
Returns a reference to the vector of commuting operations in CircuitDag.
sourcepub fn first_parallel_block(&self) -> &HashSet<usize>
pub fn first_parallel_block(&self) -> &HashSet<usize>
Returns a reference to the HashSet containing the nodes in the first parallel block.
sourcepub fn last_parallel_block(&self) -> &HashSet<usize>
pub fn last_parallel_block(&self) -> &HashSet<usize>
Returns a reference to the HashSet containing the nodes in the last parallel block.
sourcepub fn first_operation_involving_qubit(&self) -> &HashMap<usize, usize>
pub fn first_operation_involving_qubit(&self) -> &HashMap<usize, usize>
Returns a reference to the HashMap where a key represents a qubit and its value represents the first node that involves that qubit.
sourcepub fn last_operation_involving_qubit(&self) -> &HashMap<usize, usize>
pub fn last_operation_involving_qubit(&self) -> &HashMap<usize, usize>
Returns a reference to the HashMap where a key represents a qubit and its value represents the last node that involves that qubit.
sourcepub fn first_operation_involving_classical(
&self
) -> &HashMap<(String, usize), usize>
pub fn first_operation_involving_classical( &self ) -> &HashMap<(String, usize), usize>
Returns a reference to the HashMap 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.
Trait Implementations§
source§impl Clone for CircuitDag
impl Clone for CircuitDag
source§fn clone(&self) -> CircuitDag
fn clone(&self) -> CircuitDag
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CircuitDag
impl Debug for CircuitDag
source§impl<'de> Deserialize<'de> for CircuitDag
impl<'de> Deserialize<'de> for CircuitDag
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl From<Circuit> for CircuitDag
impl From<Circuit> for CircuitDag
Creates a new CircuitDag from a given Circuit.
source§impl From<CircuitDag> for Circuit
impl From<CircuitDag> for Circuit
Creates a new Circuit from a given CircuitDag.
source§fn from(dag: CircuitDag) -> Circuit
fn from(dag: CircuitDag) -> Circuit
source§impl From<CircuitDag> for CircuitDagSerializable
impl From<CircuitDag> for CircuitDagSerializable
source§fn from(value: CircuitDag) -> Self
fn from(value: CircuitDag) -> Self
source§impl PartialEq for CircuitDag
impl PartialEq for CircuitDag
source§impl Serialize for CircuitDag
impl Serialize for CircuitDag
source§impl SupportedVersion for CircuitDag
impl SupportedVersion for CircuitDag
source§impl TryFrom<CircuitDagSerializable> for CircuitDag
impl TryFrom<CircuitDagSerializable> for CircuitDag
§type Error = RoqoqoError
type Error = RoqoqoError
Auto Trait Implementations§
impl Freeze for CircuitDag
impl RefUnwindSafe for CircuitDag
impl Send for CircuitDag
impl Sync for CircuitDag
impl Unpin for CircuitDag
impl UnwindSafe for CircuitDag
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.