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 capacity
  • add_to_back(operation): adds an Operation to the back of the CircuitDag
  • add_to_front(operation): adds an Operation to the front of the CircuitDag
  • execution_blocked(already_executed_indices, index): returns the blocking elements of the execution of an Operation, the scope is just the whole graph
  • blocking_predecessors(already_executed_indices, index): returns the blocking elements of the execution of an Operation, the scope is just the Operation’s predecessors
  • new_front_layer(already_executed_indices, front_layer_indices, index): given an Operation index, computes a new front layer when considering that Operation as executed
  • parallel_blocks(): returns an iterator over the possible parallel blocks in circuit that can be executed simultaneously
  • successors(index): returns an iterator over all successors in the CircuitDag of a given node
  • commuting_operators(): returns a reference to the vector of commuting operations in CircuitDag
  • first_parallel_block(): returns a reference to the HashSet containing the nodes in the first parallel block
  • last_parallel_block(): returns a reference to the HashSet containing the nodes in the last parallel block
  • first_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 qubit
  • last_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 qubit
  • first_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 register
  • last_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 register
  • get(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

source

pub fn with_capacity(node_number: usize, edge_number: usize) -> Self

Creates a new empty CircuitDag.

source

pub fn add_to_back(&mut self, operation: Operation) -> Option<usize>

Adds an operation to the back of the CircuitDag, if necessary.

§Arguments
  • ‘operation’ - The Operation to add to the back of the CircuitDag.
§Returns
  • ‘Option<NodeIndex>’ - The NodeIndex relative to the Operation, if added to CircuitGraph.
source

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.
source

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.
source

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.
source

pub fn add_to_front(&mut self, operation: Operation) -> Option<usize>

Adds an operation to the front of the CircuitDag is necessary.

§Arguments
  • ‘operation’ - The Operation to add to the front of the CircuitDag.
§Returns
  • ‘Option<NodeIndex>’ - The NodeIndex relative to the Operation, if added to CircuitGraph.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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.
source

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

source

pub fn successors(&self, node: NodeIndex<usize>) -> Neighbors<'_, (), usize>

Returns an iterator over all successors in the CircuitDag of a given node.

source

pub fn commuting_operations(&self) -> &Vec<usize>

Returns a reference to the vector of commuting operations in CircuitDag.

source

pub fn first_parallel_block(&self) -> &HashSet<usize>

Returns a reference to the HashSet containing the nodes in the first parallel block.

source

pub fn last_parallel_block(&self) -> &HashSet<usize>

Returns a reference to the HashSet containing the nodes in the last parallel block.

source

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.

source

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.

source

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.

source

pub fn last_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 last node that involves that register.

source

pub fn get(&self, node: NodeIndex<usize>) -> Option<&Operation>

Given a NodeIndex, returns a reference to the Operation contained in the node of the CircuitDag.

Trait Implementations§

source§

impl Clone for CircuitDag

source§

fn clone(&self) -> CircuitDag

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for CircuitDag

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for CircuitDag

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Circuit> for CircuitDag

Creates a new CircuitDag from a given Circuit.

source§

fn from(circuit: Circuit) -> Self

Converts to this type from the input type.
source§

impl From<CircuitDag> for Circuit

Creates a new Circuit from a given CircuitDag.

source§

fn from(dag: CircuitDag) -> Circuit

Converts to this type from the input type.
source§

impl From<CircuitDag> for CircuitDagSerializable

source§

fn from(value: CircuitDag) -> Self

Converts to this type from the input type.
source§

impl PartialEq for CircuitDag

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for CircuitDag

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl SupportedVersion for CircuitDag

source§

fn minimum_supported_roqoqo_version(&self) -> (u32, u32, u32)

Returns the minimum roqoqo version that supports the operation. Read more
source§

impl TryFrom<CircuitDagSerializable> for CircuitDag

§

type Error = RoqoqoError

The type returned in the event of a conversion error.
source§

fn try_from(value: CircuitDagSerializable) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,