pub trait HugrView: HugrInternals {
type Nodes<'a>: Iterator<Item = Node>
where Self: 'a;
type NodePorts<'a>: Iterator<Item = Port>
where Self: 'a;
type Children<'a>: Iterator<Item = Node>
where Self: 'a;
type Neighbours<'a>: Iterator<Item = Node>
where Self: 'a;
type PortLinks<'a>: Iterator<Item = (Node, Port)>
where Self: 'a;
type NodeConnections<'a>: Iterator<Item = [Port; 2]>
where Self: 'a;
Show 50 methods
// Required methods
fn contains_node(&self, node: Node) -> bool;
fn node_count(&self) -> usize;
fn edge_count(&self) -> usize;
fn nodes(&self) -> Self::Nodes<'_>;
fn node_ports(&self, node: Node, dir: Direction) -> Self::NodePorts<'_>;
fn all_node_ports(&self, node: Node) -> Self::NodePorts<'_>;
fn linked_ports(
&self,
node: Node,
port: impl Into<Port>,
) -> Self::PortLinks<'_>;
fn node_connections(
&self,
node: Node,
other: Node,
) -> Self::NodeConnections<'_>;
fn num_ports(&self, node: Node, dir: Direction) -> usize;
fn children(&self, node: Node) -> Self::Children<'_>;
fn neighbours(&self, node: Node, dir: Direction) -> Self::Neighbours<'_>;
fn all_neighbours(&self, node: Node) -> Self::Neighbours<'_>;
// Provided methods
fn root(&self) -> Node { ... }
fn root_type(&self) -> &OpType { ... }
fn valid_node(&self, node: Node) -> bool { ... }
fn valid_non_root(&self, node: Node) -> bool { ... }
fn get_parent(&self, node: Node) -> Option<Node> { ... }
fn get_optype(&self, node: Node) -> &OpType { ... }
fn get_metadata(
&self,
node: Node,
key: impl AsRef<str>,
) -> Option<&NodeMetadata> { ... }
fn get_node_metadata(&self, node: Node) -> Option<&NodeMetadataMap> { ... }
fn node_outputs(&self, node: Node) -> OutgoingPorts<Self::NodePorts<'_>> { ... }
fn node_inputs(&self, node: Node) -> IncomingPorts<Self::NodePorts<'_>> { ... }
fn all_linked_ports(
&self,
node: Node,
dir: Direction,
) -> Either<impl Iterator<Item = (Node, OutgoingPort)>, impl Iterator<Item = (Node, IncomingPort)>> ⓘ { ... }
fn all_linked_outputs(
&self,
node: Node,
) -> impl Iterator<Item = (Node, OutgoingPort)> { ... }
fn all_linked_inputs(
&self,
node: Node,
) -> impl Iterator<Item = (Node, IncomingPort)> { ... }
fn single_linked_port(
&self,
node: Node,
port: impl Into<Port>,
) -> Option<(Node, Port)> { ... }
fn single_linked_output(
&self,
node: Node,
port: impl Into<IncomingPort>,
) -> Option<(Node, OutgoingPort)> { ... }
fn single_linked_input(
&self,
node: Node,
port: impl Into<OutgoingPort>,
) -> Option<(Node, IncomingPort)> { ... }
fn linked_outputs(
&self,
node: Node,
port: impl Into<IncomingPort>,
) -> OutgoingNodePorts<Self::PortLinks<'_>> { ... }
fn linked_inputs(
&self,
node: Node,
port: impl Into<OutgoingPort>,
) -> IncomingNodePorts<Self::PortLinks<'_>> { ... }
fn is_linked(&self, node: Node, port: impl Into<Port>) -> bool { ... }
fn num_inputs(&self, node: Node) -> usize { ... }
fn num_outputs(&self, node: Node) -> usize { ... }
fn input_neighbours(&self, node: Node) -> Self::Neighbours<'_> { ... }
fn output_neighbours(&self, node: Node) -> Self::Neighbours<'_> { ... }
fn get_io(&self, node: Node) -> Option<[Node; 2]> { ... }
fn inner_function_type(&self) -> Option<FunctionType> { ... }
fn poly_func_type(&self) -> Option<PolyFuncType> { ... }
fn as_petgraph(&self) -> PetgraphWrapper<'_, Self>
where Self: Sized { ... }
fn mermaid_string(&self) -> String { ... }
fn mermaid_string_with_config(&self, config: RenderConfig) -> String { ... }
fn dot_string(&self) -> String
where Self: Sized { ... }
fn static_source(&self, node: Node) -> Option<Node> { ... }
fn static_targets(
&self,
node: Node,
) -> Option<impl Iterator<Item = (Node, IncomingPort)>> { ... }
fn signature(&self, node: Node) -> Option<FunctionType> { ... }
fn value_types(
&self,
node: Node,
dir: Direction,
) -> impl Iterator<Item = (Port, Type)> { ... }
fn in_value_types(
&self,
node: Node,
) -> impl Iterator<Item = (IncomingPort, Type)> { ... }
fn out_value_types(
&self,
node: Node,
) -> impl Iterator<Item = (OutgoingPort, Type)> { ... }
fn validate(&self, reg: &ExtensionRegistry) -> Result<(), ValidationError> { ... }
fn validate_no_extensions(
&self,
reg: &ExtensionRegistry,
) -> Result<(), ValidationError> { ... }
}Expand description
A trait for inspecting HUGRs. For end users we intend this to be superseded by region-specific APIs.
Required Associated Types§
sourcetype Nodes<'a>: Iterator<Item = Node>
where
Self: 'a
type Nodes<'a>: Iterator<Item = Node> where Self: 'a
An Iterator over the nodes in a Hugr(View)
sourcetype NodePorts<'a>: Iterator<Item = Port>
where
Self: 'a
type NodePorts<'a>: Iterator<Item = Port> where Self: 'a
An Iterator over (some or all) ports of a node
sourcetype Children<'a>: Iterator<Item = Node>
where
Self: 'a
type Children<'a>: Iterator<Item = Node> where Self: 'a
An Iterator over the children of a node
sourcetype Neighbours<'a>: Iterator<Item = Node>
where
Self: 'a
type Neighbours<'a>: Iterator<Item = Node> where Self: 'a
An Iterator over (some or all) the nodes neighbouring a node
sourcetype PortLinks<'a>: Iterator<Item = (Node, Port)>
where
Self: 'a
type PortLinks<'a>: Iterator<Item = (Node, Port)> where Self: 'a
Iterator over the children of a node
sourcetype NodeConnections<'a>: Iterator<Item = [Port; 2]>
where
Self: 'a
type NodeConnections<'a>: Iterator<Item = [Port; 2]> where Self: 'a
Iterator over the links between two nodes.
Required Methods§
sourcefn contains_node(&self, node: Node) -> bool
fn contains_node(&self, node: Node) -> bool
Returns whether the node exists.
sourcefn node_count(&self) -> usize
fn node_count(&self) -> usize
Returns the number of nodes in the hugr.
sourcefn edge_count(&self) -> usize
fn edge_count(&self) -> usize
Returns the number of edges in the hugr.
sourcefn node_ports(&self, node: Node, dir: Direction) -> Self::NodePorts<'_>
fn node_ports(&self, node: Node, dir: Direction) -> Self::NodePorts<'_>
Iterator over ports of node in a given direction.
sourcefn all_node_ports(&self, node: Node) -> Self::NodePorts<'_>
fn all_node_ports(&self, node: Node) -> Self::NodePorts<'_>
Iterator over both the input and output ports of node.
sourcefn linked_ports(&self, node: Node, port: impl Into<Port>) -> Self::PortLinks<'_>
fn linked_ports(&self, node: Node, port: impl Into<Port>) -> Self::PortLinks<'_>
Iterator over the nodes and ports connected to a port.
sourcefn node_connections(&self, node: Node, other: Node) -> Self::NodeConnections<'_>
fn node_connections(&self, node: Node, other: Node) -> Self::NodeConnections<'_>
Iterator the links between two nodes.
sourcefn num_ports(&self, node: Node, dir: Direction) -> usize
fn num_ports(&self, node: Node, dir: Direction) -> usize
Number of ports in node for a given direction.
sourcefn children(&self, node: Node) -> Self::Children<'_>
fn children(&self, node: Node) -> Self::Children<'_>
Return iterator over the direct children of node.
sourcefn neighbours(&self, node: Node, dir: Direction) -> Self::Neighbours<'_>
fn neighbours(&self, node: Node, dir: Direction) -> Self::Neighbours<'_>
Iterates over neighbour nodes in the given direction. May contain duplicates if the graph has multiple links between nodes.
sourcefn all_neighbours(&self, node: Node) -> Self::Neighbours<'_>
fn all_neighbours(&self, node: Node) -> Self::Neighbours<'_>
Iterates over the input and output neighbours of the node in sequence.
Provided Methods§
sourcefn valid_node(&self, node: Node) -> bool
fn valid_node(&self, node: Node) -> bool
Validates that a node is valid in the graph.
sourcefn valid_non_root(&self, node: Node) -> bool
fn valid_non_root(&self, node: Node) -> bool
Validates that a node is a valid root descendant in the graph.
To include the root node use HugrView::valid_node instead.
sourcefn get_parent(&self, node: Node) -> Option<Node>
fn get_parent(&self, node: Node) -> Option<Node>
Returns the parent of a node.
sourcefn get_optype(&self, node: Node) -> &OpType
fn get_optype(&self, node: Node) -> &OpType
Returns the operation type of a node.
sourcefn get_metadata(
&self,
node: Node,
key: impl AsRef<str>,
) -> Option<&NodeMetadata>
fn get_metadata( &self, node: Node, key: impl AsRef<str>, ) -> Option<&NodeMetadata>
Returns the metadata associated with a node.
sourcefn get_node_metadata(&self, node: Node) -> Option<&NodeMetadataMap>
fn get_node_metadata(&self, node: Node) -> Option<&NodeMetadataMap>
Retrieve the complete metadata map for a node.
sourcefn node_outputs(&self, node: Node) -> OutgoingPorts<Self::NodePorts<'_>>
fn node_outputs(&self, node: Node) -> OutgoingPorts<Self::NodePorts<'_>>
Iterator over output ports of node.
Like node_ports(node, Direction::Outgoing)
but preserves knowledge that the ports are OutgoingPorts.
sourcefn node_inputs(&self, node: Node) -> IncomingPorts<Self::NodePorts<'_>>
fn node_inputs(&self, node: Node) -> IncomingPorts<Self::NodePorts<'_>>
Iterator over inputs ports of node.
Like node_ports(node, Direction::Incoming)
but preserves knowledge that the ports are IncomingPorts.
sourcefn all_linked_ports(
&self,
node: Node,
dir: Direction,
) -> Either<impl Iterator<Item = (Node, OutgoingPort)>, impl Iterator<Item = (Node, IncomingPort)>> ⓘ
fn all_linked_ports( &self, node: Node, dir: Direction, ) -> Either<impl Iterator<Item = (Node, OutgoingPort)>, impl Iterator<Item = (Node, IncomingPort)>> ⓘ
Iterator over all the nodes and ports connected to a node in a given direction.
sourcefn all_linked_outputs(
&self,
node: Node,
) -> impl Iterator<Item = (Node, OutgoingPort)>
fn all_linked_outputs( &self, node: Node, ) -> impl Iterator<Item = (Node, OutgoingPort)>
Iterator over all the nodes and ports connected to a node’s inputs.
sourcefn all_linked_inputs(
&self,
node: Node,
) -> impl Iterator<Item = (Node, IncomingPort)>
fn all_linked_inputs( &self, node: Node, ) -> impl Iterator<Item = (Node, IncomingPort)>
Iterator over all the nodes and ports connected to a node’s outputs.
sourcefn single_linked_port(
&self,
node: Node,
port: impl Into<Port>,
) -> Option<(Node, Port)>
fn single_linked_port( &self, node: Node, port: impl Into<Port>, ) -> Option<(Node, Port)>
If there is exactly one port connected to this port, return it and its node.
sourcefn single_linked_output(
&self,
node: Node,
port: impl Into<IncomingPort>,
) -> Option<(Node, OutgoingPort)>
fn single_linked_output( &self, node: Node, port: impl Into<IncomingPort>, ) -> Option<(Node, OutgoingPort)>
If there is exactly one OutgoingPort connected to this IncomingPort, return it and its node.
sourcefn single_linked_input(
&self,
node: Node,
port: impl Into<OutgoingPort>,
) -> Option<(Node, IncomingPort)>
fn single_linked_input( &self, node: Node, port: impl Into<OutgoingPort>, ) -> Option<(Node, IncomingPort)>
If there is exactly one IncomingPort connected to this OutgoingPort, return it and its node.
sourcefn linked_outputs(
&self,
node: Node,
port: impl Into<IncomingPort>,
) -> OutgoingNodePorts<Self::PortLinks<'_>>
fn linked_outputs( &self, node: Node, port: impl Into<IncomingPort>, ) -> OutgoingNodePorts<Self::PortLinks<'_>>
Iterator over the nodes and output ports connected to a given input port.
Like linked_ports but preserves knowledge
that the linked ports are OutgoingPorts.
sourcefn linked_inputs(
&self,
node: Node,
port: impl Into<OutgoingPort>,
) -> IncomingNodePorts<Self::PortLinks<'_>>
fn linked_inputs( &self, node: Node, port: impl Into<OutgoingPort>, ) -> IncomingNodePorts<Self::PortLinks<'_>>
Iterator over the nodes and input ports connected to a given output port
Like linked_ports but preserves knowledge
that the linked ports are IncomingPorts.
sourcefn is_linked(&self, node: Node, port: impl Into<Port>) -> bool
fn is_linked(&self, node: Node, port: impl Into<Port>) -> bool
Returns whether a port is connected.
sourcefn num_inputs(&self, node: Node) -> usize
fn num_inputs(&self, node: Node) -> usize
Number of inputs to a node.
Shorthand for num_ports(node, Direction::Incoming).
sourcefn num_outputs(&self, node: Node) -> usize
fn num_outputs(&self, node: Node) -> usize
Number of outputs from a node.
Shorthand for num_ports(node, Direction::Outgoing).
sourcefn input_neighbours(&self, node: Node) -> Self::Neighbours<'_>
fn input_neighbours(&self, node: Node) -> Self::Neighbours<'_>
Iterates over the input neighbours of the node.
Shorthand for neighbours(node, Direction::Incoming).
sourcefn output_neighbours(&self, node: Node) -> Self::Neighbours<'_>
fn output_neighbours(&self, node: Node) -> Self::Neighbours<'_>
Iterates over the output neighbours of the node.
Shorthand for neighbours(node, Direction::Outgoing).
sourcefn get_io(&self, node: Node) -> Option<[Node; 2]>
fn get_io(&self, node: Node) -> Option<[Node; 2]>
Get the input and output child nodes of a dataflow parent. If the node isn’t a dataflow parent, then return None
sourcefn inner_function_type(&self) -> Option<FunctionType>
fn inner_function_type(&self) -> Option<FunctionType>
Returns the function type defined by this dataflow HUGR.
If the root of the Hugr is a
DataflowParent operation, report the
signature corresponding to the input and output node of its sibling
graph. Otherwise, returns None.
In contrast to poly_func_type, this
method always return a concrete FunctionType.
sourcefn poly_func_type(&self) -> Option<PolyFuncType>
fn poly_func_type(&self) -> Option<PolyFuncType>
Returns the function type defined by this HUGR.
For HUGRs with a DataflowParent root
operation, report the signature of the inner dataflow sibling graph.
For HUGRS with a FuncDecl or
FuncDefn root operation, report the signature
of the function.
Otherwise, returns None.
sourcefn as_petgraph(&self) -> PetgraphWrapper<'_, Self>where
Self: Sized,
fn as_petgraph(&self) -> PetgraphWrapper<'_, Self>where
Self: Sized,
Return a wrapper over the view that can be used in petgraph algorithms.
sourcefn mermaid_string(&self) -> String
fn mermaid_string(&self) -> String
Return the mermaid representation of the underlying hierarchical graph.
The hierarchy is represented using subgraphs. Edges are labelled with their source and target ports.
For a more detailed representation, use the HugrView::dot_string
format instead.
sourcefn mermaid_string_with_config(&self, config: RenderConfig) -> String
fn mermaid_string_with_config(&self, config: RenderConfig) -> String
Return the mermaid representation of the underlying hierarchical graph.
The hierarchy is represented using subgraphs. Edges are labelled with their source and target ports.
For a more detailed representation, use the HugrView::dot_string
format instead.
sourcefn dot_string(&self) -> Stringwhere
Self: Sized,
fn dot_string(&self) -> Stringwhere
Self: Sized,
Return the graphviz representation of the underlying graph and hierarchy side by side.
For a simpler representation, use the HugrView::mermaid_string format instead.
sourcefn static_source(&self, node: Node) -> Option<Node>
fn static_source(&self, node: Node) -> Option<Node>
If a node has a static input, return the source node.
sourcefn static_targets(
&self,
node: Node,
) -> Option<impl Iterator<Item = (Node, IncomingPort)>>
fn static_targets( &self, node: Node, ) -> Option<impl Iterator<Item = (Node, IncomingPort)>>
If a node has a static output, return the targets.
sourcefn signature(&self, node: Node) -> Option<FunctionType>
fn signature(&self, node: Node) -> Option<FunctionType>
Get the “signature” (incoming and outgoing types) of a node, non-Value kind ports will be missing.
sourcefn value_types(
&self,
node: Node,
dir: Direction,
) -> impl Iterator<Item = (Port, Type)>
fn value_types( &self, node: Node, dir: Direction, ) -> impl Iterator<Item = (Port, Type)>
Iterator over all outgoing ports that have Value type, along with corresponding types.
sourcefn in_value_types(
&self,
node: Node,
) -> impl Iterator<Item = (IncomingPort, Type)>
fn in_value_types( &self, node: Node, ) -> impl Iterator<Item = (IncomingPort, Type)>
Iterator over all incoming ports that have Value type, along with corresponding types.
sourcefn out_value_types(
&self,
node: Node,
) -> impl Iterator<Item = (OutgoingPort, Type)>
fn out_value_types( &self, node: Node, ) -> impl Iterator<Item = (OutgoingPort, Type)>
Iterator over all incoming ports that have Value type, along with corresponding types.
sourcefn validate(&self, reg: &ExtensionRegistry) -> Result<(), ValidationError>
fn validate(&self, reg: &ExtensionRegistry) -> Result<(), ValidationError>
Check the validity of the underlying HUGR.
sourcefn validate_no_extensions(
&self,
reg: &ExtensionRegistry,
) -> Result<(), ValidationError>
fn validate_no_extensions( &self, reg: &ExtensionRegistry, ) -> Result<(), ValidationError>
Check the validity of the underlying HUGR, but don’t check consistency of extension requirements between connected nodes or between parents and children.