Trait hugr_core::hugr::views::HugrView

source ·
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§

source

type Nodes<'a>: Iterator<Item = Node> where Self: 'a

An Iterator over the nodes in a Hugr(View)

source

type NodePorts<'a>: Iterator<Item = Port> where Self: 'a

An Iterator over (some or all) ports of a node

source

type Children<'a>: Iterator<Item = Node> where Self: 'a

An Iterator over the children of a node

source

type Neighbours<'a>: Iterator<Item = Node> where Self: 'a

An Iterator over (some or all) the nodes neighbouring a node

Iterator over the children of a node

source

type NodeConnections<'a>: Iterator<Item = [Port; 2]> where Self: 'a

Iterator over the links between two nodes.

Required Methods§

source

fn contains_node(&self, node: Node) -> bool

Returns whether the node exists.

source

fn node_count(&self) -> usize

Returns the number of nodes in the hugr.

source

fn edge_count(&self) -> usize

Returns the number of edges in the hugr.

source

fn nodes(&self) -> Self::Nodes<'_>

Iterates over the nodes in the port graph.

source

fn node_ports(&self, node: Node, dir: Direction) -> Self::NodePorts<'_>

Iterator over ports of node in a given direction.

source

fn all_node_ports(&self, node: Node) -> Self::NodePorts<'_>

Iterator over both the input and output ports of node.

source

fn linked_ports(&self, node: Node, port: impl Into<Port>) -> Self::PortLinks<'_>

Iterator over the nodes and ports connected to a port.

source

fn node_connections(&self, node: Node, other: Node) -> Self::NodeConnections<'_>

Iterator the links between two nodes.

source

fn num_ports(&self, node: Node, dir: Direction) -> usize

Number of ports in node for a given direction.

source

fn children(&self, node: Node) -> Self::Children<'_>

Return iterator over the direct children of node.

source

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.

source

fn all_neighbours(&self, node: Node) -> Self::Neighbours<'_>

Iterates over the input and output neighbours of the node in sequence.

Provided Methods§

source

fn root(&self) -> Node

Return the root node of this view.

source

fn root_type(&self) -> &OpType

Return the type of the HUGR root node.

source

fn valid_node(&self, node: Node) -> bool

Validates that a node is valid in the graph.

source

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.

source

fn get_parent(&self, node: Node) -> Option<Node>

Returns the parent of a node.

source

fn get_optype(&self, node: Node) -> &OpType

Returns the operation type of a node.

source

fn get_metadata( &self, node: Node, key: impl AsRef<str>, ) -> Option<&NodeMetadata>

Returns the metadata associated with a node.

source

fn get_node_metadata(&self, node: Node) -> Option<&NodeMetadataMap>

Retrieve the complete metadata map for a node.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

fn is_linked(&self, node: Node, port: impl Into<Port>) -> bool

Returns whether a port is connected.

source

fn num_inputs(&self, node: Node) -> usize

Number of inputs to a node. Shorthand for num_ports(node, Direction::Incoming).

source

fn num_outputs(&self, node: Node) -> usize

Number of outputs from a node. Shorthand for num_ports(node, Direction::Outgoing).

source

fn input_neighbours(&self, node: Node) -> Self::Neighbours<'_>

Iterates over the input neighbours of the node. Shorthand for neighbours(node, Direction::Incoming).

source

fn output_neighbours(&self, node: Node) -> Self::Neighbours<'_>

Iterates over the output neighbours of the node. Shorthand for neighbours(node, Direction::Outgoing).

source

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

source

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.

source

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.

source

fn as_petgraph(&self) -> PetgraphWrapper<'_, Self>
where Self: Sized,

Return a wrapper over the view that can be used in petgraph algorithms.

source

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.

source

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.

source

fn dot_string(&self) -> String
where 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.

source

fn static_source(&self, node: Node) -> Option<Node>

If a node has a static input, return the source node.

source

fn static_targets( &self, node: Node, ) -> Option<impl Iterator<Item = (Node, IncomingPort)>>

If a node has a static output, return the targets.

source

fn signature(&self, node: Node) -> Option<FunctionType>

Get the “signature” (incoming and outgoing types) of a node, non-Value kind ports will be missing.

source

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.

source

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.

source

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.

source

fn validate(&self, reg: &ExtensionRegistry) -> Result<(), ValidationError>

Check the validity of the underlying HUGR.

source

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.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'g, Root: NodeHandle> HugrView for DescendantsGraph<'g, Root>

§

type Nodes<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &RegionContext<'g>) -> bool, fn(_: PortIndex, _: &RegionContext<'g>) -> bool, RegionContext<'g>> as PortView>::Nodes<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type NodePorts<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &RegionContext<'g>) -> bool, fn(_: PortIndex, _: &RegionContext<'g>) -> bool, RegionContext<'g>> as PortView>::NodePortOffsets<'a>, MapSpecialCaseFnInto<Port>> where Self: 'a

§

type Children<'a> = MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type Neighbours<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &RegionContext<'g>) -> bool, fn(_: PortIndex, _: &RegionContext<'g>) -> bool, RegionContext<'g>> as LinkView>::Neighbours<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type NodeConnections<'a> = MapCtx<WithCtx<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &RegionContext<'g>) -> bool, fn(_: PortIndex, _: &RegionContext<'g>) -> bool, RegionContext<'g>> as LinkView>::NodeConnections<'a>, &'a DescendantsGraph<'g, Root>>, [Port; 2]> where Self: 'a

source§

impl<'g, Root: NodeHandle> HugrView for SiblingGraph<'g, Root>

§

type Neighbours<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, fn(_: PortIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, (&'g Hierarchy, NodeIndex)> as LinkView>::Neighbours<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type NodeConnections<'a> = MapCtx<WithCtx<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, fn(_: PortIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, (&'g Hierarchy, NodeIndex)> as LinkView>::NodeConnections<'a>, &'a SiblingGraph<'g, Root>>, [Port; 2]> where Self: 'a

§

type Nodes<'a> = Chain<Once<Node>, MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>>> where Self: 'a

§

type NodePorts<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, fn(_: PortIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, (&'g Hierarchy, NodeIndex)> as PortView>::NodePortOffsets<'a>, MapSpecialCaseFnInto<Port>> where Self: 'a

§

type Children<'a> = MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

source§

impl<'g, Root: NodeHandle> HugrView for SiblingMut<'g, Root>

§

type Neighbours<'a> = <Vec<Node> as IntoIterator>::IntoIter where Self: 'a

§

type NodeConnections<'a> = <Vec<[Port; 2]> as IntoIterator>::IntoIter where Self: 'a

§

type Nodes<'a> = Chain<Once<Node>, MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>>> where Self: 'a

§

type NodePorts<'a> = MapSpecialCase<<FilteredGraph<&'g MultiPortGraph, fn(_: NodeIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, fn(_: PortIndex, _: &(&'g Hierarchy, NodeIndex)) -> bool, (&'g Hierarchy, NodeIndex)> as PortView>::NodePortOffsets<'a>, MapSpecialCaseFnInto<Port>> where Self: 'a

§

type Children<'a> = MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

source§

impl<T: AsRef<Hugr>> HugrView for T

§

type Nodes<'a> = MapSpecialCase<Nodes<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type NodePorts<'a> = MapSpecialCase<NodePortOffsets, MapSpecialCaseFnInto<Port>> where Self: 'a

§

type Children<'a> = MapSpecialCase<Children<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type Neighbours<'a> = MapSpecialCase<Neighbours<'a>, MapSpecialCaseFnInto<Node>> where Self: 'a

§

type NodeConnections<'a> = MapCtx<WithCtx<NodeConnections<'a>, &'a Hugr>, [Port; 2]> where Self: 'a