Trait Dataflow

Source
pub trait Dataflow: Container {
Show 28 methods // Required method fn num_inputs(&self) -> usize; // Provided methods fn io(&self) -> [Node; 2] { ... } fn input(&self) -> BuildHandle<DataflowOpID> { ... } fn output(&self) -> DataflowOpID { ... } fn input_wires(&self) -> Outputs { ... } fn add_dataflow_op( &mut self, nodetype: impl Into<OpType>, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError> { ... } fn add_hugr_with_wires( &mut self, hugr: Hugr, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError> { ... } fn add_hugr_view_with_wires( &mut self, hugr: &impl HugrView, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError> { ... } fn set_outputs( &mut self, output_wires: impl IntoIterator<Item = Wire>, ) -> Result<(), BuildError> { ... } fn input_wires_arr<const N: usize>(&self) -> [Wire; N] { ... } fn dfg_builder( &mut self, signature: Signature, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<DFGBuilder<&mut Hugr>, BuildError> { ... } fn dfg_builder_endo( &mut self, inputs: impl IntoIterator<Item = (Type, Wire)>, ) -> Result<DFGBuilder<&mut Hugr>, BuildError> { ... } fn cfg_builder( &mut self, inputs: impl IntoIterator<Item = (Type, Wire)>, output_types: TypeRow, ) -> Result<CFGBuilder<&mut Hugr>, BuildError> { ... } fn load_const(&mut self, cid: &ConstID) -> Wire { ... } fn add_load_const(&mut self, constant: impl Into<Const>) -> Wire { ... } fn add_load_value(&mut self, constant: impl Into<Value>) -> Wire { ... } fn load_func<const DEFINED: bool>( &mut self, fid: &FuncID<DEFINED>, type_args: &[TypeArg], ) -> Result<Wire, BuildError> { ... } fn tail_loop_builder( &mut self, just_inputs: impl IntoIterator<Item = (Type, Wire)>, inputs_outputs: impl IntoIterator<Item = (Type, Wire)>, just_out_types: TypeRow, ) -> Result<TailLoopBuilder<&mut Hugr>, BuildError> { ... } fn conditional_builder( &mut self, (sum_rows, sum_wire): (impl IntoIterator<Item = TypeRow>, Wire), other_inputs: impl IntoIterator<Item = (Type, Wire)>, output_types: TypeRow, ) -> Result<ConditionalBuilder<&mut Hugr>, BuildError> { ... } fn set_order(&mut self, before: &impl NodeHandle, after: &impl NodeHandle) { ... } fn get_wire_type(&self, wire: Wire) -> Result<Type, BuildError> { ... } fn make_tuple( &mut self, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError> { ... } fn make_sum( &mut self, tag: usize, variants: impl IntoIterator<Item = TypeRow>, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError> { ... } fn make_continue( &mut self, tail_loop: TailLoop, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError> { ... } fn make_break( &mut self, loop_op: TailLoop, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError> { ... } fn call<const DEFINED: bool>( &mut self, function: &FuncID<DEFINED>, type_args: &[TypeArg], input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError> { ... } fn as_circuit( &mut self, wires: impl IntoIterator<Item = Wire>, ) -> CircuitBuilder<'_, Self> { ... } fn add_barrier( &mut self, wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError> { ... }
}
Expand description

Trait for building dataflow regions of a HUGR.

Required Methods§

Source

fn num_inputs(&self) -> usize

Return the number of inputs to the dataflow sibling graph.

Provided Methods§

Source

fn io(&self) -> [Node; 2]

Return indices of input and output nodes.

Source

fn input(&self) -> BuildHandle<DataflowOpID>

Handle to input node.

Source

fn output(&self) -> DataflowOpID

Handle to output node.

Source

fn input_wires(&self) -> Outputs

Return iterator over all input Value wires.

Source

fn add_dataflow_op( &mut self, nodetype: impl Into<OpType>, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError>

Add a dataflow OpType to the sibling graph, wiring up the input_wires to the incoming ports of the resulting node.

Adds the extensions required by the op to the HUGR, if they are not already present.

§Errors

Returns a BuildError::OperationWiring error if the input_wires cannot be connected.

Source

fn add_hugr_with_wires( &mut self, hugr: Hugr, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError>

Insert a hugr-defined op to the sibling graph, wiring up the input_wires to the incoming ports of the resulting root node.

§Errors

This function will return an error if there is an error when adding the node.

Source

fn add_hugr_view_with_wires( &mut self, hugr: &impl HugrView, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError>

Copy a hugr-defined op into the sibling graph, wiring up the input_wires to the incoming ports of the resulting root node.

§Errors

This function will return an error if there is an error when adding the node.

Source

fn set_outputs( &mut self, output_wires: impl IntoIterator<Item = Wire>, ) -> Result<(), BuildError>

Wire up the output_wires to the input ports of the Output node.

§Errors

This function will return an error if there is an error when wiring up.

Source

fn input_wires_arr<const N: usize>(&self) -> [Wire; N]

Return an array of the input wires.

§Panics

Panics if the number of input Wires does not match the size of the array.

Source

fn dfg_builder( &mut self, signature: Signature, input_wires: impl IntoIterator<Item = Wire>, ) -> Result<DFGBuilder<&mut Hugr>, BuildError>

Return a builder for a crate::ops::DFG node, i.e. a nested dataflow subgraph, given a signature describing its input and output types and extension delta, and the input wires (which must match the input types)

§Errors

This function will return an error if there is an error when building the DFG node.

Source

fn dfg_builder_endo( &mut self, inputs: impl IntoIterator<Item = (Type, Wire)>, ) -> Result<DFGBuilder<&mut Hugr>, BuildError>

Return a builder for a crate::ops::DFG node, i.e. a nested dataflow subgraph, that is endomorphic (the output types are the same as the input types). The inputs must be an iterable over pairs of the type of the input and the corresponding wire.

Source

fn cfg_builder( &mut self, inputs: impl IntoIterator<Item = (Type, Wire)>, output_types: TypeRow, ) -> Result<CFGBuilder<&mut Hugr>, BuildError>

Return a builder for a crate::ops::CFG node, i.e. a nested controlflow subgraph. The inputs must be an iterable over pairs of the type of the input and the corresponding wire. The output_types are the types of the outputs.

§Errors

This function will return an error if there is an error when building the CFG node.

Source

fn load_const(&mut self, cid: &ConstID) -> Wire

Load a static constant and return the local dataflow wire for that constant. Adds a OpType::LoadConstant node.

Source

fn add_load_const(&mut self, constant: impl Into<Const>) -> Wire

Load a static constant and return the local dataflow wire for that constant. Adds a ops::Const and a ops::LoadConstant node.

Source

fn add_load_value(&mut self, constant: impl Into<Value>) -> Wire

Load a ops::Value and return the local dataflow wire for that constant. Adds a ops::Const and a ops::LoadConstant node.

Source

fn load_func<const DEFINED: bool>( &mut self, fid: &FuncID<DEFINED>, type_args: &[TypeArg], ) -> Result<Wire, BuildError>

Load a static function and return the local dataflow wire for that function. Adds a OpType::LoadFunction node.

The DEF const generic is used to indicate whether the function is defined or just declared.

Source

fn tail_loop_builder( &mut self, just_inputs: impl IntoIterator<Item = (Type, Wire)>, inputs_outputs: impl IntoIterator<Item = (Type, Wire)>, just_out_types: TypeRow, ) -> Result<TailLoopBuilder<&mut Hugr>, BuildError>

Return a builder for a crate::ops::TailLoop node. The inputs must be an iterable over pairs of the type of the input and the corresponding wire. The output_types are the types of the outputs.

§Errors

This function will return an error if there is an error when building the ops::TailLoop node.

Source

fn conditional_builder( &mut self, (sum_rows, sum_wire): (impl IntoIterator<Item = TypeRow>, Wire), other_inputs: impl IntoIterator<Item = (Type, Wire)>, output_types: TypeRow, ) -> Result<ConditionalBuilder<&mut Hugr>, BuildError>

Return a builder for a crate::ops::Conditional node. sum_input is a tuple of the type of the Sum variants and the corresponding wire.

The other_inputs must be an iterable over pairs of the type of the input and the corresponding wire. The output_types are the types of the outputs.

§Errors

This function will return an error if there is an error when building the Conditional node.

Source

fn set_order(&mut self, before: &impl NodeHandle, after: &impl NodeHandle)

Add an order edge from before to after. Assumes any additional edges to both nodes will be Order kind.

Source

fn get_wire_type(&self, wire: Wire) -> Result<Type, BuildError>

Get the type of a Value Wire. If not valid port or of Value kind, returns None.

Source

fn make_tuple( &mut self, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError>

Add a MakeTuple node and wire in the values Wires, returning the Wire corresponding to the tuple.

§Errors

This function will return an error if there is an error adding the MakeTuple node.

Source

fn make_sum( &mut self, tag: usize, variants: impl IntoIterator<Item = TypeRow>, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError>

Add a Tag node and wire in the value Wire, to make a value with Sum type, with tag and possible types described by variants. Returns the Wire corresponding to the Sum value.

§Errors

This function will return an error if there is an error adding the Tag node.

Source

fn make_continue( &mut self, tail_loop: TailLoop, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError>

Use the wires in values to return a wire corresponding to the “Continue” variant of a ops::TailLoop with loop_signature.

Packs the values in to a tuple and tags appropriately to generate a value of Sum type.

§Errors

This function will return an error if there is an error in adding the nodes.

Source

fn make_break( &mut self, loop_op: TailLoop, values: impl IntoIterator<Item = Wire>, ) -> Result<Wire, BuildError>

Use the wires in values to return a wire corresponding to the “Break” variant of a ops::TailLoop with loop_signature.

Packs the values in to a tuple and tags appropriately to generate a value of Sum type.

§Errors

This function will return an error if there is an error in adding the nodes.

Source

fn call<const DEFINED: bool>( &mut self, function: &FuncID<DEFINED>, type_args: &[TypeArg], input_wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError>

Add a ops::Call node, calling function, with inputs specified by input_wires. Returns a handle to the corresponding Call node.

§Errors

This function will return an error if there is an error adding the Call node, or if function does not refer to a ops::FuncDecl or ops::FuncDefn node.

Source

fn as_circuit( &mut self, wires: impl IntoIterator<Item = Wire>, ) -> CircuitBuilder<'_, Self>

For the vector of wires, produce a CircuitBuilder where ops can be added using indices in to the vector.

Source

fn add_barrier( &mut self, wires: impl IntoIterator<Item = Wire>, ) -> Result<BuildHandle<DataflowOpID>, BuildError>

Add a Barrier to a set of wires and return them in the same order.

§Errors

This function will return an error if there is an error adding the Barrier node or retrieving the type of the incoming wires.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§