Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

The main graph structure representing a DAG

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Create a new empty graph

Source

pub fn with_strict_edges() -> Self

Create a new graph with strict edge mapping enabled When enabled, edges must be explicitly added with add_edge() When disabled (default), edges are automatically created based on node order

Source

pub fn set_strict_edge_mapping(&mut self, strict: bool)

Set strict edge mapping mode

Source

pub fn add(&mut self, node: Node) -> Result<()>

Add a node to the graph

Source

pub fn add_node(&mut self, node: Node) -> Result<()>

👎Deprecated since 0.2.0: Use add instead

Alias for add() for backward compatibility

Source

pub fn add_edge(&mut self, edge: Edge) -> Result<()>

Add an edge to the graph

Source

pub fn get_node(&self, node_id: &str) -> Result<&Node>

Get a node by ID

Source

pub fn get_node_mut(&mut self, node_id: &str) -> Result<&mut Node>

Get a mutable reference to a node by ID

Source

pub fn validate(&self) -> Result<()>

Validate the graph (check for cycles)

Source

pub fn topological_order(&self) -> Result<Vec<NodeId>>

Get a topological ordering of the nodes

Source

pub fn nodes(&self) -> Vec<&Node>

Get all nodes in the graph

Source

pub fn edges(&self) -> Vec<&Edge>

Get all edges in the graph

Source

pub fn node_count(&self) -> usize

Get the number of nodes

Source

pub fn edge_count(&self) -> usize

Get the number of edges

Source

pub fn incoming_edges(&self, node_id: &str) -> Result<Vec<&Edge>>

Get incoming edges for a node

Source

pub fn outgoing_edges(&self, node_id: &str) -> Result<Vec<&Edge>>

Get outgoing edges for a node

Source

pub fn auto_connect(&mut self) -> Result<usize>

Automatically connect nodes based on matching port names This enables implicit edge mapping without explicit add_edge() calls

§Matching Strategy
  • Connects output ports to input ports with the same name
  • Only creates edges if the port names match exactly
  • Respects topological ordering to avoid cycles
§Returns

The number of edges created

Source

pub fn with_auto_connect(self) -> Result<Self>

Build a graph with strict mode disabled - uses implicit edge mapping This is a convenience method that calls auto_connect() after all nodes are added

Source

pub fn create_branch(&mut self, name: impl Into<String>) -> Result<&mut Graph>

Create a new branch (subgraph) with the given name

Source

pub fn get_branch(&self, name: &str) -> Result<&Graph>

Get a reference to a branch by name

Source

pub fn get_branch_mut(&mut self, name: &str) -> Result<&mut Graph>

Get a mutable reference to a branch by name

Source

pub fn branch_names(&self) -> Vec<String>

Get all branch names

Source

pub fn has_branch(&self, name: &str) -> bool

Check if a branch exists

Source

pub fn merge( &mut self, node_id: impl Into<NodeId>, config: MergeConfig, ) -> Result<()>

Create a merge node that combines outputs from multiple branches

The merge node will collect outputs from the specified branches and combine them using the provided merge function (or collect into a list by default).

Source

pub fn create_variants(&mut self, config: VariantConfig) -> Result<Vec<String>>

Create variant branches for config sweeps

This creates multiple isolated branches, each with a different parameter value. Variants can be used for hyperparameter sweeps, A/B testing, or any scenario where you want to run the same computation with different inputs.

Returns the names of the created variant branches.

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate 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 Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl !RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl !UnwindSafe for Graph

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

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>,

Source§

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>,

Source§

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.